Skip to content

Instantly share code, notes, and snippets.

@rumblex
Created October 29, 2008 15:17
Show Gist options
  • Save rumblex/20717 to your computer and use it in GitHub Desktop.
Save rumblex/20717 to your computer and use it in GitHub Desktop.
>> users = User.all
<< snip >>
>> def trim_percentage(users, cutoff)
>> above, below, novote = 0, 0, 0
>> users.each do |user|
?> avg = user.ratings.average(:value).to_f
>> if avg < 1
>> novote += 1
>> elsif avg < cutoff
>> below += 1
>> else
?> above += 1
>> end
>> end
>> [novote, below, above, ((below.to_f / (above + below).to_f)*100).to_i]
>> end
=> nil
>> trim_percentage(users, 1.5)
=> [938, 256, 814, 23]
>> trim_percentage(users, 1.4)
=> [938, 224, 846, 20]
>> trim_percentage(users, 1.3)
=> [938, 199, 871, 18]
>> trim_percentage(users, 1.2)
=> [938, 168, 902, 15]
>> trim_percentage(users, 1.1)
=> [938, 144, 926, 13]
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment