Commit 90bb583f30f346bf8033ae8fc06b2875b5965ea5
1 parent
f043f5b4
Exists in
master
and in
1 other branch
more whitespace fixes
Showing
1 changed file
with
19 additions
and
20 deletions
Show diff stats
app/models/question.rb
| @@ -227,27 +227,26 @@ class Question < ActiveRecord::Base | @@ -227,27 +227,26 @@ class Question < ActiveRecord::Base | ||
| 227 | return result | 227 | return result |
| 228 | end | 228 | end |
| 229 | 229 | ||
| 230 | - #passing precomputed sum saves us a traversal through the array | ||
| 231 | - def normalize!(weighted, sum=nil) | ||
| 232 | - if weighted.instance_of?(Hash) | ||
| 233 | - if sum.nil? | ||
| 234 | - sum = weighted.inject(0) do |sum, item_and_weight| | 230 | + #passing precomputed sum saves us a traversal through the array |
| 231 | + def normalize!(weighted, sum=nil) | ||
| 232 | + if weighted.instance_of?(Hash) | ||
| 233 | + if sum.nil? | ||
| 234 | + sum = weighted.inject(0) do |sum, item_and_weight| | ||
| 235 | sum += item_and_weight[1] | 235 | sum += item_and_weight[1] |
| 236 | - end | ||
| 237 | - sum = sum.to_f | ||
| 238 | - end | ||
| 239 | - weighted.each do |item, weight| | ||
| 240 | - weighted[item] = weight/sum | ||
| 241 | - weighted[item] = 0.0 unless weighted[item].finite? | ||
| 242 | - end | ||
| 243 | - elsif weighted.instance_of?(Array) | ||
| 244 | - sum = weighted.inject(0) {|sum, item| sum += item} if sum.nil? | ||
| 245 | - weighted.each_with_index do |item, i| | ||
| 246 | - weighted[i] = item/sum | ||
| 247 | - weighted[i] = 0.0 unless weighted[i].finite? | ||
| 248 | - end | ||
| 249 | - | ||
| 250 | - end | 236 | + end |
| 237 | + sum = sum.to_f | ||
| 238 | + end | ||
| 239 | + weighted.each do |item, weight| | ||
| 240 | + weighted[item] = weight/sum | ||
| 241 | + weighted[item] = 0.0 unless weighted[item].finite? | ||
| 242 | + end | ||
| 243 | + elsif weighted.instance_of?(Array) | ||
| 244 | + sum = weighted.inject(0) {|sum, item| sum += item} if sum.nil? | ||
| 245 | + weighted.each_with_index do |item, i| | ||
| 246 | + weighted[i] = item/sum | ||
| 247 | + weighted[i] = 0.0 unless weighted[i].finite? | ||
| 248 | + end | ||
| 249 | + end | ||
| 251 | end | 250 | end |
| 252 | 251 | ||
| 253 | def bradley_terry_probs | 252 | def bradley_terry_probs |