Permalink
Browse files

fix counters

  • Loading branch information...
1 parent 2e15998 commit 22be53eb1f2bbc8eff0e9942fae4a58b9208ce80 @aserafin aserafin committed Jan 3, 2014
Showing with 4 additions and 4 deletions.
  1. +4 −4 app/models/player.rb
View
@@ -17,18 +17,18 @@ def setup_default_rating
end
def count_matches(tournament)
- matches.confirmed.where(tournament_id: tournament.id).count
+ matches.confirmed.where(tournament_id: tournament.id).count('distinct match_id')
end
def count_wins(tournament)
- matches.confirmed.where('tournament_id = ? and winners @> ARRAY[?]', tournament.id, self.id).count
+ matches.confirmed.where('tournament_id = ? and winners @> ARRAY[?]', tournament.id, self.id).count('distinct match_id')
end
def count_losts(tournament)
- matches.confirmed.where('tournament_id = ? and (array_length(winners, 1) > 0 and not (winners @> ARRAY[?]))', tournament.id, self.id).count
+ matches.confirmed.where('tournament_id = ? and (coalesce(array_length(winners, 1), 0) > 0 and not (winners @> ARRAY[?]))', tournament.id, self.id).count('distinct match_id')
end
def count_draws(tournament)
- matches.confirmed.where('tournament_id = ? and array_length(winners, 1) = 0', tournament.id).count
+ matches.confirmed.where('tournament_id = ? and coalesce(array_length(winners, 1), 0) = 0', tournament.id).count('distinct match_id')
end
end

0 comments on commit 22be53e

Please sign in to comment.