Search in sources :

Example 1 with Post

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;
    }
}
Also used : Post(io.plaidapp.data.api.producthunt.model.Post)

Example 2 with Post

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);
}
Also used : Post(io.plaidapp.data.api.producthunt.model.Post) PlaidItemSorting(io.plaidapp.data.PlaidItemSorting) StoryWeigher(io.plaidapp.data.api.designernews.StoryWeigher) PostWeigher(io.plaidapp.data.api.producthunt.PostWeigher) Shot(io.plaidapp.data.api.dribbble.model.Shot) Story(io.plaidapp.data.api.designernews.model.Story) ShotWeigher(io.plaidapp.data.api.dribbble.ShotWeigher)

Aggregations

Post (io.plaidapp.data.api.producthunt.model.Post)2 PlaidItemSorting (io.plaidapp.data.PlaidItemSorting)1 StoryWeigher (io.plaidapp.data.api.designernews.StoryWeigher)1 Story (io.plaidapp.data.api.designernews.model.Story)1 ShotWeigher (io.plaidapp.data.api.dribbble.ShotWeigher)1 Shot (io.plaidapp.data.api.dribbble.model.Shot)1 PostWeigher (io.plaidapp.data.api.producthunt.PostWeigher)1