Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> 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]
- >>
Add Comment
Please, Sign In to add comment