Commit 4abe0130087897f7f1adb4a3a4a8967f2de05388
1 parent
2a7581ab
Exists in
master
and in
1 other branch
make whitespace changes to question model
Showing
1 changed file
with
26 additions
and
27 deletions
Show diff stats
app/models/question.rb
@@ -109,37 +109,36 @@ class Question < ActiveRecord::Base | @@ -109,37 +109,36 @@ class Question < ActiveRecord::Base | ||
109 | end | 109 | end |
110 | 110 | ||
111 | 111 | ||
112 | - # TODO Add index for question id on prompts table | ||
113 | - def catchup_prompts_weights | ||
114 | - weights = Hash.new(0) | ||
115 | - throttle_min = 0.05 | ||
116 | - sum = 0.0 | ||
117 | - | ||
118 | - prompts.find_each(:select => 'votes_count, left_choice_id, right_choice_id') do |p| | ||
119 | - value = [(1.0/ (p.votes.size + 1).to_f).to_f, throttle_min].min | ||
120 | - weights["#{p.left_choice_id}, #{p.right_choice_id}"] = value | ||
121 | - sum += value | ||
122 | - end | 112 | + def catchup_prompts_weights |
113 | + weights = Hash.new(0) | ||
114 | + throttle_min = 0.05 | ||
115 | + sum = 0.0 | ||
116 | + | ||
117 | + prompts.find_each(:select => 'votes_count, left_choice_id, right_choice_id') do |p| | ||
118 | + value = [(1.0/ (p.votes.size + 1).to_f).to_f, throttle_min].min | ||
119 | + weights["#{p.left_choice_id}, #{p.right_choice_id}"] = value | ||
120 | + sum += value | ||
121 | + end | ||
123 | 122 | ||
124 | - # This will not run once all prompts have been generated, | ||
125 | - # but it prevents us from having to pregenerate all possible prompts | ||
126 | - if weights.size < choices.size ** 2 - choices.size | 123 | + # This will not run once all prompts have been generated, |
124 | + # but it prevents us from having to pregenerate all possible prompts | ||
125 | + if weights.size < choices.size ** 2 - choices.size | ||
127 | choices.each do |l| | 126 | choices.each do |l| |
128 | - choices.each do |r| | ||
129 | - if l.id == r.id | ||
130 | - next | ||
131 | - end | ||
132 | - if !weights.has_key?("#{l.id}, #{r.id}") | ||
133 | - weights["#{l.id}, #{r.id}"] = throttle_min | ||
134 | - sum+=throttle_min | ||
135 | - end | ||
136 | - end | 127 | + choices.each do |r| |
128 | + if l.id == r.id | ||
129 | + next | ||
130 | + end | ||
131 | + if !weights.has_key?("#{l.id}, #{r.id}") | ||
132 | + weights["#{l.id}, #{r.id}"] = throttle_min | ||
133 | + sum+=throttle_min | ||
134 | + end | ||
135 | + end | ||
137 | end | 136 | end |
138 | - end | 137 | + end |
139 | 138 | ||
140 | - normalize!(weights, sum) | ||
141 | - weights | ||
142 | - end | 139 | + normalize!(weights, sum) |
140 | + weights | ||
141 | + end | ||
143 | 142 | ||
144 | def get_optional_information(params) | 143 | def get_optional_information(params) |
145 | 144 |