Commit 21c22686bb8a19c1dbef893df008bd29362679bf
1 parent
580db1c8
Exists in
master
and in
1 other branch
update catchup algorithm
When calculating weights, ignore prompts with invalid choices. Update if statement that determines if all possible valid prompts have been created. Update test factory to include case where there exists a prompt with invalid choices.
Showing
2 changed files
with
11 additions
and
2 deletions
Show diff stats
app/models/question.rb
... | ... | @@ -114,7 +114,11 @@ class Question < ActiveRecord::Base |
114 | 114 | throttle_min = 0.05 |
115 | 115 | sum = 0.0 |
116 | 116 | |
117 | - prompts.find_each(:select => 'votes_count, left_choice_id, right_choice_id') do |p| | |
117 | + # get weights of all existing prompts that have two active choices | |
118 | + active_choice_ids = choices.active.map {|c| c.id} | |
119 | + prompts.find_each(:select => 'votes_count, left_choice_id, right_choice_id', | |
120 | + :conditions => {:left_choice_id => active_choice_ids, | |
121 | + :right_choice_id => active_choice_ids}) do |p| | |
118 | 122 | value = [(1.0/ (p.votes.size + 1).to_f).to_f, throttle_min].min |
119 | 123 | weights["#{p.left_choice_id}, #{p.right_choice_id}"] = value |
120 | 124 | sum += value |
... | ... | @@ -122,7 +126,7 @@ class Question < ActiveRecord::Base |
122 | 126 | |
123 | 127 | # This will not run once all prompts have been generated, |
124 | 128 | # but it prevents us from having to pregenerate all possible prompts |
125 | - if weights.size < choices.size ** 2 - choices.size | |
129 | + if weights.size < choices.active.size ** 2 - choices.active.size | |
126 | 130 | choices.active.each do |l| |
127 | 131 | choices.active.each do |r| |
128 | 132 | if l.id == r.id | ... | ... |
spec/factories.rb
... | ... | @@ -36,6 +36,11 @@ Factory.define(:aoi_question, :parent => :question) do |f| |
36 | 36 | :left_choice => question.choices.first, |
37 | 37 | :right_choice => question.choices.second) |
38 | 38 | |
39 | + result << Factory.build(:prompt, | |
40 | + :question => question.result, | |
41 | + :left_choice => question.choices.third, | |
42 | + :right_choice => question.choices.fourth) | |
43 | + | |
39 | 44 | end |
40 | 45 | result |
41 | 46 | end | ... | ... |