Updated Leaderboard and easy-to-use functions

in #utopian-io6 years ago (edited)

Pull Request

Closes #50
  • Filter out blacklisted posts from database requests
  • Removed unused functions
  • Added getWeek function
  • Commented more thoroughly the report functions
  • Added getNumWeeks and getNumVotes helper methods used for the leaderboards

Bug Fixes

Blacklist

The blacklist was updated for filtering from the database. This means that now even if a blacklisted user ends up in the database, that user's posts will be filtered out. Things like the payout(), contestants, and leaderboard functions will not include these users. The filter occurs during getUsers and getPosts right after the items are returned from the database. Blacklisted users and posts will be removed from the database manually.

New Features

Accurate Leaderboards

  • What was the issue(s)?
    The previous leaderboard had the columns weeks and upvotes, when really what was being shown was posts and upvotes. Now thanks to two helper methods getNumWeeks and getNumVotes we are able to accurately rank users. The getNumVotes simply sums up the number of votes from all of a user's posts. The getNumWeeks however will return the number of weeks a user has participated in the community. There have been users that submit multiple posts every week (which is a good thing) and their counts were incorrect.
getNumWeeks

This function works by first mapping each post to the week number that it is. All duplicates are removed, and then we just call .length. I thought a bit about how to do this and it's worth thinking about whether this will ever need to be optimized. I'm first mapping each post using a getWeek function. getWeek just performs some simple math to figure out which week out of the year this post was from. It looks something like dayOfYear / 7. Then we are filtering each one to get a unique set of items. This is done using indexOf which is going to run in linear time - when it could just as easily be done using a dictionary in a reduce. I am curious to know if the number of posts ever get so great that I will have to change the implementation to speed things up.

const getNumWeeks = (posts: Post[]): number => posts
    // Map each post to its week #
    .map(post => getWeek(new Date(post.created)))
    // Remove duplicates
    .filter((num, index, arr) => index === arr.indexOf(num))
    // Return number of weeks
    .length

Now Playing

Check out the #nowplaying community and bot in action here



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

@walnut1, Upvote for supporting you.

Congratulations @walnut1! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of comments

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @walnut1 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.028
BTC 59596.75
ETH 2659.83
USDT 1.00
SBD 2.45