Updated Leaderboard and easy-to-use functions
Pull Request
Closes #50
- Filter out blacklisted posts from database requests
- Removed unused functions
- Added
getWeekfunction - Commented more thoroughly the report functions
- Added
getNumWeeksandgetNumVoteshelper 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 columnsweeksandupvotes, when really what was being shown waspostsandupvotes. Now thanks to two helper methodsgetNumWeeksandgetNumVoteswe are able to accurately rank users. ThegetNumVotessimply sums up the number of votes from all of a user's posts. ThegetNumWeekshowever 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
@walnut1, Upvote for supporting you.
Congratulations @walnut1! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
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
STOPThank 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
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
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