-
Notifications
You must be signed in to change notification settings - Fork 26
Leaderboard
- Run rails server
- Connect to http://localhost:3000/leaderboards
For test, excute the following rake task to insert test score data to redis.
bundle exec rake leaderboard:add_test_data
To delete all leaderboard data from redis
bundle exec rake leaderboard:clear
Models for leaderboard are Leaderboard, Leaderboad::Score, and Leaderboard::Member. It uses redis as backend datastore. The base namespace of leaderboard is cs:leaderboard
.
Leaderboard#leaders
method will return leaders that matche options. Options are community, category, year, month, and page. The default value of each option is "all".
Leaderboard.leaders
Leaderboard.leaders community: "java"
Leaderboard.leaders community: "java", category: "ruby"
Leaderboard.leaders community: "java", category: "ruby", year: "2012", month: "10"
Leaderboard.leaders category: "ruby", page: 2
Score model is in charge of constructing leaderboard. When saving score, it updates all concerned leaderboards. Let's say score is in community 'java', and category 'ios', and date is "2012-06". Then it will update the following leaderboards.
'cs:leaderboard:java:all:all:all:prizes'
'cs:leaderboard:java:all:2012:all:prizes'
'cs:leaderboard:java:all:2012:6:prizes'
'cs:leaderboard:java:ios:all:all:prizes'
'cs:leaderboard:java:ios:2012:all:prizes'
'cs:leaderboard:java:ios:2012:6:prizes'
Score data itself is stored in redis to avoid duplication. When the same score(with same username and challenge_id) is requested to save, it will just return false without doing anything.
Member model is for the view. It has name and picture fields which are stored in redis.
total_prizes
, rank
, and total_wins
fields are updated dynamically when getting leaders.(see leaderboard.rb)
When the app receives 'update' event of challenge from database.com(streaming.rb file), it can construct score instances from the challenge_prizes__r
attribute. Then, call score.save
.
For Instance,
scores = challenge.scores # Challenge#scores is not yet implemented
scores.each {|s| s.save}
To make the above possible, records of challenge_prizes__r
needs member_name
of member_id
field to identify who the score is belonged to.
For member, when app receives 'create' event of member, it can save leaderboard member. For Instance,
lb_member = Leaderboard::Member.new(name: member.name, picture: member.profile_pic)
lb_member.save
The design is almost same as current leaderboard site.
Changes are
- Select box of Community is newly added. If you select one community, it will show leaders of selected community.
- previous and next arrow is added next to the title like 'This Month'. So you can navigate to previous month, or previous year.