Skip to content

Commit

Permalink
Also count total golfers and display that with the ranking
Browse files Browse the repository at this point in the history
So it can show you that you're "#1 / 170" or "igrigorik#350 / 941", etc.
  • Loading branch information
filbranden committed Aug 11, 2020
1 parent 6cabc81 commit 522de31
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/repositories/repository_challenge.rb
Expand Up @@ -370,6 +370,7 @@ def self.player_best_scores(player_id)
"$group": {
"_id": "$_id.challenge_id",
"items": { "$push": "$$ROOT" },
"count_golfers": { "$sum": 1 },
}
},
{ "$unwind": { "path": "$items", "includeArrayIndex": "items.position" }},
Expand All @@ -385,7 +386,8 @@ def self.player_best_scores(player_id)
"best_score": "$items.best_score",
"best_player_score": "$items.best_player_score",
"attempts": "$items.attempts",
"position": { "$add": ["$items.position", 1]}
"position": { "$add": ["$items.position", 1]},
"count_golfers": 1,
}
},
)
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.erb
Expand Up @@ -7,7 +7,7 @@
<ul>
<li>Best score: <b><%= player_challenge['best_score'] %></b></li>
<li>Best player score: <b><%= player_challenge['best_player_score'] %></b></li>
<li>Position: <b>#<%= player_challenge['position'] %></b></li>
<li>Position: <b>#<%= player_challenge['position'] %> / <%= player_challenge['count_golfers'] %></b></li>
<li>Number of attempts: <b><%= player_challenge['attempts'] %></b></li>
</ul>
</div>
Expand Down
2 changes: 2 additions & 0 deletions spec/repositories/repository_challenge_spec.rb
Expand Up @@ -461,6 +461,7 @@
expect(challenge['best_player_score']).to eq(14)
expect(challenge['attempts']).to eq(1)
expect(challenge['position']).to eq(1)
expect(challenge['count_golfers']).to eq(1)

# And challenge1 is next.
challenge = result[1]
Expand All @@ -472,6 +473,7 @@
expect(challenge['best_player_score']).to eq(12)
expect(challenge['attempts']).to eq(2)
expect(challenge['position']).to eq(2)
expect(challenge['count_golfers']).to eq(2)
end
end

Expand Down

0 comments on commit 522de31

Please sign in to comment.