Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TieRankingLeaderboard doesn't rank if the score is 0 #53

Closed
ivanovv opened this issue Mar 19, 2015 · 3 comments · Fixed by #54
Closed

TieRankingLeaderboard doesn't rank if the score is 0 #53

ivanovv opened this issue Mar 19, 2015 · 3 comments · Fixed by #54

Comments

@ivanovv
Copy link

ivanovv commented Mar 19, 2015

First of all - thanks for a great gem!

Now, looks like there is a certain difference in behaviour between Leaderboard and TieRankingLeaderboard.

lb = Leaderboard.new('dd')
=> #<Leaderboard:0x007fe7c6f3d850 @leaderboard_name="dd", @reverse=false, @page_size=25, @member_key=:member, @rank_key=:rank, @score_key=:score, @member_data_key=:member_data, @member_data_namespace="member_data", @global_member_data=false, @redis_connection=#<Redis client v3.2.1 for redis://localhost:6379/0>>
>> lb.rank_members [1, 0.0, 2, 0.0]
=> [true, true]
>> lb.leaders 1
=> [{:member=>"2", :rank=>1, :score=>0.0}, {:member=>"1", :rank=>2, :score=>0.0}]

This is an expected behaviour - all members have rank, only I need members with equal score to have equal rank. So:

require 'tie_ranking_leaderboard'
>>  lb2 = TieRankingLeaderboard.new('zz')
=> #<TieRankingLeaderboard:0x007fe7c2b7c030 @leaderboard_name="zz", @reverse=false, @page_size=25, @member_key=:member, @rank_key=:rank, @score_key=:score, @member_data_key=:member_data, @member_data_namespace="member_data", @global_member_data=false, @redis_connection=#<Redis client v3.2.1 for redis://localhost:6379/0>, @ties_namespace="ties">
>> lb2.rank_members [1, 0, 2, 0]
=> [true, true, true, true]
>> lb2.leaders 1
=> [{:member=>"2", :score=>0.0, :rank=>nil}, {:member=>"1", :score=>0.0, :rank=>nil}]

I would expect both members to have the same rank (1).

>> lb2.rank_members [1, 1, 2, 1]
=> [false, false, false, false]
>> lb2.leaders 1
=> [{:member=>"2", :score=>1.0, :rank=>2}, {:member=>"1", :score=>1.0, :rank=>2}]

When the scores !=0 all members have a rank, but it is not 1, it is 2.

Any ideas?

czarneckid pushed a commit that referenced this issue Mar 19, 2015
We sometimes need to remove a rank in the ties leaderboard.
Fixes #53.
@czarneckid
Copy link
Member

@ivanovv An interesting bug indeed! Thanks for the basics of the test case as well. Are you able to test that new commit to see if that fixes things for you?

@ivanovv
Copy link
Author

ivanovv commented Mar 19, 2015

Yeah, fixed for me 👍

lb = TieRankingLeaderboard.new('zz')
lb.rank_members [1, 0.0, 2, 17543.0, 34, 0.0]
lb.leaders 1
[{:member=>"2", :score=>17543.0, :rank=>1}, {:member=>"34", :score=>0.0, :rank=>2}, {:member=>"1", :score=>0.0, :rank=>2}]

Thanks!

@czarneckid
Copy link
Member

OK. I'll cut a new release tomorrow. I've got some other updates that I'm going to roll in as well.

czarneckid pushed a commit that referenced this issue Mar 19, 2015
We sometimes need to remove a rank in the ties leaderboard.
Fixes #53.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants