Guest User

Untitled

a guest
Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. >> users = User.all
  2. << snip >>
  3. >> def trim_percentage(users, cutoff)
  4. >> above, below, novote = 0, 0, 0
  5. >> users.each do |user|
  6. ?> avg = user.ratings.average(:value).to_f
  7. >> if avg < 1
  8. >> novote += 1
  9. >> elsif avg < cutoff
  10. >> below += 1
  11. >> else
  12. ?> above += 1
  13. >> end
  14. >> end
  15. >> [novote, below, above, ((below.to_f / (above + below).to_f)*100).to_i]
  16. >> end
  17. => nil
  18. >> trim_percentage(users, 1.5)
  19. => [938, 256, 814, 23]
  20. >> trim_percentage(users, 1.4)
  21. => [938, 224, 846, 20]
  22. >> trim_percentage(users, 1.3)
  23. => [938, 199, 871, 18]
  24. >> trim_percentage(users, 1.2)
  25. => [938, 168, 902, 15]
  26. >> trim_percentage(users, 1.1)
  27. => [938, 144, 926, 13]
  28. >>
Add Comment
Please, Sign In to add comment