Commit 59bb951ff6847c3e89f24c4658a6a78ce20ca8ff
1 parent
7e22d490
Exists in
master
and in
1 other branch
add an explicit loss count
Showing
2 changed files
with
10 additions
and
1 deletions
Show diff stats
app/models/choice.rb
| ... | ... | @@ -16,6 +16,11 @@ class Choice < ActiveRecord::Base |
| 16 | 16 | item.data |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | + def lose! | |
| 20 | + self.loss_count += 1 | |
| 21 | + save! | |
| 22 | + end | |
| 23 | + | |
| 19 | 24 | def wins_plus_losses |
| 20 | 25 | #(prompts_on_the_left.collect(&:votes_count).sum + prompts_on_the_right.collect(&:votes_count).sum) |
| 21 | 26 | Prompt.sum('votes_count', :conditions => "left_choice_id = #{id} OR right_choice_id = #{id}") | ... | ... |
app/models/visitor.rb
| ... | ... | @@ -13,12 +13,16 @@ class Visitor < ActiveRecord::Base |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | def vote_for!(prompt, ordinality) |
| 16 | - choice = prompt.choices[ordinality] #we need to guarantee that the choices are in the right order (by position) | |
| 16 | + choices = prompt.choices | |
| 17 | + choice = choices[ordinality] #we need to guarantee that the choices are in the right order (by position) | |
| 17 | 18 | prompt_vote = votes.create!(:voteable => prompt) |
| 18 | 19 | choice_vote = votes.create!(:voteable => choice) |
| 19 | 20 | choice.save! |
| 20 | 21 | choice.score = choice.compute_score |
| 21 | 22 | choice.save! |
| 23 | + | |
| 24 | + other_choices = choices - [choice] | |
| 25 | + other_choices.each {|c| c.lose! } | |
| 22 | 26 | end |
| 23 | 27 | |
| 24 | 28 | def skip!(prompt) | ... | ... |