Modified story intelligence formula.

This commit is contained in:
RyanBateman 2012-10-03 22:02:26 -04:00
parent 0a26329155
commit 925f798231
4 changed files with 75 additions and 38 deletions

View file

@ -37,7 +37,7 @@ public class DatabaseConstants {
public static final String FEED_FOLDER_MAP_TABLE = "feed_folder_map";
public static final String FEED_FOLDER_FEED_ID = "feed_feed_id";
public static final String FEED_FOLDER_FOLDER_NAME = "feed_folder_name";
public static final String SOCIALFEED_STORY_MAP_TABLE = "socialfeed_story_map";
public static final String SOCIALFEED_STORY_USER_ID = "socialfeed_story_user_id";
public static final String SOCIALFEED_STORY_STORYID = "socialfeed_story_storyid";
@ -59,7 +59,7 @@ public class DatabaseConstants {
public static final String USER_USERID = BaseColumns._ID;
public static final String USER_USERNAME = "username";
public static final String USER_PHOTO_URL = "photo_url";
public static final String STORY_TABLE = "stories";
public static final String STORY_ID = BaseColumns._ID;
public static final String STORY_AUTHORS = "authors";
@ -96,14 +96,14 @@ public class DatabaseConstants {
public static final String COMMENT_USERID = "comment_userid";
public static final String REPLY_TABLE = "comment_replies";
public static final String REPLY_ID = BaseColumns._ID;
public static final String REPLY_COMMENTID = "comment_id";
public static final String REPLY_TEXT = "reply_text";
public static final String REPLY_USERID = "reply_userid";
public static final String REPLY_DATE = "reply_date";
public static final String REPLY_SHORTDATE = "reply_shortdate";
// Aggregated columns
public static final String SUM_POS = "sum_postive";
public static final String SUM_NEUT = "sum_neutral";
@ -112,7 +112,7 @@ public class DatabaseConstants {
public static final String[] UPDATE_COLUMNS = {
UPDATE_ID, UPDATE_TYPE, UPDATE_ARGUMENTS
};
public static final String[] FEED_COLUMNS = {
FEED_TABLE + "." + FEED_ACTIVE, FEED_TABLE + "." + FEED_ID, FEED_TABLE + "." + FEED_FAVICON_URL, FEED_TABLE + "." + FEED_TITLE, FEED_TABLE + "." + FEED_LINK, FEED_TABLE + "." + FEED_ADDRESS, FEED_TABLE + "." + FEED_SUBSCRIBERS, FEED_TABLE + "." + FEED_UPDATED_SECONDS, FEED_TABLE + "." + FEED_FAVICON_FADE, FEED_TABLE + "." + FEED_FAVICON_COLOUR, FEED_TABLE + "." + FEED_FAVICON_BORDER,
FEED_TABLE + "." + FEED_FAVICON, FEED_TABLE + "." + FEED_POSITIVE_COUNT, FEED_TABLE + "." + FEED_NEUTRAL_COUNT, FEED_TABLE + "." + FEED_NEGATIVE_COUNT
@ -125,7 +125,7 @@ public class DatabaseConstants {
public static final String[] COMMENT_COLUMNS = {
COMMENT_ID, COMMENT_STORYID, COMMENT_TEXT, COMMENT_BYFRIEND, COMMENT_USERID, COMMENT_DATE, COMMENT_LIKING_USERS, COMMENT_SHAREDDATE, COMMENT_SOURCE_USERID
};
public static final String[] REPLY_COLUMNS = {
REPLY_COMMENTID, REPLY_DATE, REPLY_ID, REPLY_SHORTDATE, REPLY_TEXT, REPLY_USERID
};
@ -134,23 +134,33 @@ public class DatabaseConstants {
FOLDER_TABLE + "." + FOLDER_ID, FOLDER_TABLE + "." + FOLDER_NAME, " SUM(" + FEED_POSITIVE_COUNT + ") AS " + SUM_POS, " SUM(" + FEED_NEUTRAL_COUNT + ") AS " + SUM_NEUT, " SUM(" + FEED_NEGATIVE_COUNT + ") AS " + SUM_NEG
};
public static final String[] STORY_COLUMNS = {
STORY_AUTHORS, STORY_COMMENT_COUNT, STORY_CONTENT, STORY_DATE, STORY_SHARED_DATE, STORY_SHORTDATE, STORY_LONGDATE, STORY_TABLE + "." + STORY_FEED_ID, STORY_TABLE + "." + STORY_ID, STORY_INTELLIGENCE_AUTHORS, STORY_INTELLIGENCE_FEED, STORY_INTELLIGENCE_TAGS, STORY_INTELLIGENCE_TITLE,
STORY_PERMALINK, STORY_READ, STORY_SHARE_COUNT, STORY_TAGS, STORY_TITLE, STORY_SOCIAL_USER_ID, STORY_SOURCE_USER_ID, STORY_SHARED_USER_IDS, STORY_FRIEND_USER_IDS, STORY_PUBLIC_USER_IDS
};
public static final String FOLDER_INTELLIGENCE_ALL = " HAVING SUM(" + DatabaseConstants.FEED_NEGATIVE_COUNT + " + " + DatabaseConstants.FEED_NEUTRAL_COUNT + " + " + DatabaseConstants.FEED_POSITIVE_COUNT + ") >= 0 ";
public static final String FOLDER_INTELLIGENCE_SOME = " HAVING SUM(" + DatabaseConstants.FEED_NEUTRAL_COUNT + " + " + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 ";
public static final String FOLDER_INTELLIGENCE_BEST = " HAVING SUM(" + DatabaseConstants.FEED_POSITIVE_COUNT + ") > 0 ";
public static final String SOCIAL_INTELLIGENCE_ALL = "";
public static final String SOCIAL_INTELLIGENCE_SOME = " (" + DatabaseConstants.SOCIAL_FEED_NEUTRAL_COUNT + " + " + DatabaseConstants.SOCIAL_FEED_POSITIVE_COUNT + ") > 0 ";
public static final String SOCIAL_INTELLIGENCE_BEST = " (" + DatabaseConstants.SOCIAL_FEED_POSITIVE_COUNT + ") > 0 ";
private static final String SUM_STORY_TOTAL = "storyTotal";
private static String STORY_SUM_TOTAL = " CASE " +
"WHEN MAX(" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + "," + DatabaseConstants.STORY_INTELLIGENCE_FEED + "," + DatabaseConstants.STORY_INTELLIGENCE_TAGS + "," + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") > 0 " +
"THEN MAX(" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + "," + DatabaseConstants.STORY_INTELLIGENCE_FEED + "," + DatabaseConstants.STORY_INTELLIGENCE_TAGS + "," + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") " +
"WHEN MIN(" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + "," + DatabaseConstants.STORY_INTELLIGENCE_FEED + "," + DatabaseConstants.STORY_INTELLIGENCE_TAGS + "," + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") < 0 " +
"THEN MIN(" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + "," + DatabaseConstants.STORY_INTELLIGENCE_FEED + "," + DatabaseConstants.STORY_INTELLIGENCE_TAGS + "," + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") " +
"ELSE " + DatabaseConstants.STORY_INTELLIGENCE_FEED + " " +
"END AS " + DatabaseConstants.SUM_STORY_TOTAL;
public static final String STORY_INTELLIGENCE_BEST = DatabaseConstants.SUM_STORY_TOTAL + " > 0 ";
public static final String STORY_INTELLIGENCE_SOME = DatabaseConstants.SUM_STORY_TOTAL + " >= 0 ";
public static final String STORY_INTELLIGENCE_ALL = DatabaseConstants.SUM_STORY_TOTAL + " >= 0 ";
public static final String[] STORY_COLUMNS = {
STORY_AUTHORS, STORY_COMMENT_COUNT, STORY_CONTENT, STORY_DATE, STORY_SHARED_DATE, STORY_SHORTDATE, STORY_LONGDATE, STORY_TABLE + "." + STORY_FEED_ID, STORY_TABLE + "." + STORY_ID, STORY_INTELLIGENCE_AUTHORS, STORY_INTELLIGENCE_FEED, STORY_INTELLIGENCE_TAGS, STORY_INTELLIGENCE_TITLE,
STORY_PERMALINK, STORY_READ, STORY_SHARE_COUNT, STORY_TAGS, STORY_TITLE, STORY_SOCIAL_USER_ID, STORY_SOURCE_USER_ID, STORY_SHARED_USER_IDS, STORY_FRIEND_USER_IDS, STORY_PUBLIC_USER_IDS, STORY_SUM_TOTAL
};
public static final String STORY_INTELLIGENCE_BEST = " (" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + " + " + DatabaseConstants.STORY_INTELLIGENCE_FEED + " + " + DatabaseConstants.STORY_INTELLIGENCE_TAGS + " + " + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") > 0 ";
public static final String STORY_INTELLIGENCE_SOME = " (" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + " + " + DatabaseConstants.STORY_INTELLIGENCE_FEED + " + " + DatabaseConstants.STORY_INTELLIGENCE_TAGS + " + " + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") >= 0 ";
public static final String STORY_INTELLIGENCE_ALL = " (" + DatabaseConstants.STORY_INTELLIGENCE_AUTHORS + " + " + DatabaseConstants.STORY_INTELLIGENCE_FEED + " + " + DatabaseConstants.STORY_INTELLIGENCE_TAGS + " + " + DatabaseConstants.STORY_INTELLIGENCE_TITLE + ") >= 0 ";
}

View file

@ -1,11 +1,15 @@
package com.newsblur.domain;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import android.content.ContentValues;
import android.database.Cursor;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.annotations.SerializedName;
import com.newsblur.database.DatabaseConstants;
@ -15,22 +19,22 @@ public class Story implements Serializable {
private static final long serialVersionUID = 7629596752129163308L;
public String id;
@SerializedName("story_permalink")
public String permalink;
@SerializedName("share_count")
public String shareCount;
@SerializedName("share_user_ids")
public String[] sharedUserIds;
@SerializedName("shared_by_friends")
public String[] friendUserIds = new String[]{};
@SerializedName("shared_by_public")
public String[] publicUserIds = new String[]{};
@SerializedName("comment_count")
public int commentCount;
@ -45,13 +49,13 @@ public class Story implements Serializable {
@SerializedName("source_user_id")
public String sourceUserId;
@SerializedName("story_title")
public String title;
@SerializedName("story_date")
public Date date;
@SerializedName("shared_date")
public Date sharedDate;
@ -66,7 +70,7 @@ public class Story implements Serializable {
@SerializedName("public_comments")
public Comment[] publicComments;
@SerializedName("friend_comments")
public Comment[] friendsComments;
@ -75,10 +79,10 @@ public class Story implements Serializable {
@SerializedName("short_parsed_date")
public String shortDate;
@SerializedName("long_parsed_date")
public String longDate;
public ContentValues getValues() {
final ContentValues values = new ContentValues();
values.put(DatabaseConstants.STORY_ID, id);
@ -106,7 +110,7 @@ public class Story implements Serializable {
values.put(DatabaseConstants.STORY_FEED_ID, feedId);
return values;
}
public static Story fromCursor(final Cursor cursor) {
Story story = new Story();
story.authors = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_AUTHORS));
@ -134,24 +138,41 @@ public class Story implements Serializable {
story.id = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_ID));
return story;
}
public class Intelligence implements Serializable {
private static final long serialVersionUID = -1314486209455376730L;
@SerializedName("feed")
public int intelligenceFeed = 0;
@SerializedName("author")
public int intelligenceAuthors = 0;
@SerializedName("tags")
public int intelligenceTags = 0;
@SerializedName("title")
public int intelligenceTitle = 0;
}
public int getIntelligenceTotal() {
return (intelligence.intelligenceAuthors + intelligence.intelligenceFeed + intelligence.intelligenceTags + intelligence.intelligenceTitle);
return getIntelligenceTotal(intelligence.intelligenceTitle, intelligence.intelligenceAuthors, intelligence.intelligenceTags, intelligence.intelligenceFeed);
}
public static int getIntelligenceTotal(int title, int authors, int tags, int feed) {
int score = 0;
List<Integer> list = Arrays.asList(title, authors, tags);
int max = Collections.max(list);
int min = Collections.min(list);
if (max > 0) {
score = max;
} else if (min < 0) {
score = min;
} else {
score = feed;
}
return score;
}
}

View file

@ -10,6 +10,7 @@ import android.widget.TextView;
import com.newsblur.R;
import com.newsblur.database.DatabaseConstants;
import com.newsblur.domain.Story;
public class FeedItemViewBinder implements ViewBinder {
@ -45,13 +46,14 @@ public class FeedItemViewBinder implements ViewBinder {
return true;
} else if (TextUtils.equals(columnName, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS)) {
int authors = cursor.getInt(columnIndex);
int tags = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TAGS));
int feed = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_FEED));
int title = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TITLE));
if (authors + tags + feed + title > 0) {
int score = Story.getIntelligenceTotal(title, authors, tags, feed);
if (score > 0) {
view.setBackgroundResource(hasBeenRead == 0 ? R.drawable.positive_count_circle : R.drawable.positive_count_circle_read);
} else if (authors + tags + feed + title == 0) {
} else if (score == 0) {
view.setBackgroundResource(hasBeenRead == 0 ? R.drawable.neutral_count_circle : R.drawable.neutral_count_circle_read);
} else {
view.setBackgroundResource(R.drawable.negative_count_circle);

View file

@ -12,6 +12,7 @@ import android.widget.TextView;
import com.newsblur.R;
import com.newsblur.activity.NewsBlurApplication;
import com.newsblur.database.DatabaseConstants;
import com.newsblur.domain.Story;
import com.newsblur.util.ImageLoader;
public class SocialItemViewBinder implements ViewBinder {
@ -35,9 +36,12 @@ public class SocialItemViewBinder implements ViewBinder {
int tags = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TAGS));
int feed = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_FEED));
int title = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TITLE));
if (authors + tags + feed + title > 0) {
int score = Story.getIntelligenceTotal(title, authors, tags, feed);
if (score > 0) {
view.setBackgroundResource(hasBeenRead == 0 ? R.drawable.positive_count_circle : R.drawable.positive_count_circle_read);
} else if (authors + tags + feed + title == 0) {
} else if (score == 0) {
view.setBackgroundResource(hasBeenRead == 0 ? R.drawable.neutral_count_circle : R.drawable.neutral_count_circle_read);
} else {
view.setBackgroundResource(R.drawable.negative_count_circle);