use of io.plaidapp.data.api.producthunt.model.Post in project plaid by nickbutcher.
the class PostWeigher method weigh.
@Override
public void weigh(List<Post> posts) {
float maxVotes = 0f;
float maxComments = 0f;
for (Post post : posts) {
maxVotes = Math.max(maxVotes, post.votes_count);
maxComments = Math.max(maxComments, post.comments_count);
}
for (Post post : posts) {
float weight = 1f - ((((float) post.comments_count) / maxComments) + ((float) post.votes_count / maxVotes)) / 2f;
post.weight = post.page + weight;
}
}
use of io.plaidapp.data.api.producthunt.model.Post in project plaid by nickbutcher.
the class FeedAdapter method weighItems.
/**
* Calculate a 'weight' [0, 1] for each data type for sorting. Each data type/source has a
* different metric for weighing it e.g. Dribbble uses likes etc. but some sources should keep
* the order returned by the API. Weights are 'scoped' to the page they belong to and lower
* weights are sorted earlier in the grid (i.e. in ascending weight).
*/
private void weighItems(List<? extends PlaidItem> items) {
if (items == null || items.isEmpty())
return;
PlaidItemSorting.PlaidItemGroupWeigher weigher = null;
switch(items.get(0).dataSource) {
// have an expectation about the order they appear in
case SourceManager.SOURCE_DRIBBBLE_USER_SHOTS:
case SourceManager.SOURCE_DRIBBBLE_USER_LIKES:
case SourceManager.SOURCE_PRODUCT_HUNT:
case PlayerShotsDataManager.SOURCE_PLAYER_SHOTS:
case PlayerShotsDataManager.SOURCE_TEAM_SHOTS:
if (naturalOrderWeigher == null) {
naturalOrderWeigher = new PlaidItemSorting.NaturalOrderWeigher();
}
weigher = naturalOrderWeigher;
break;
default:
// regular pattern of items in the grid
if (items.get(0) instanceof Shot) {
if (shotWeigher == null)
shotWeigher = new ShotWeigher();
weigher = shotWeigher;
} else if (items.get(0) instanceof Story) {
if (storyWeigher == null)
storyWeigher = new StoryWeigher();
weigher = storyWeigher;
} else if (items.get(0) instanceof Post) {
if (postWeigher == null)
postWeigher = new PostWeigher();
weigher = postWeigher;
}
}
weigher.weigh(items);
}
Aggregations