-
-
Save ArtOfCode-/993b93d0c5f975002807092678fcffed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to validate a weighting preference | |
user_weights = current_user.user_site_settings.map { |uss| [uss.site, uss.group_weight] }.to_h | |
flags_per_site = current_user.user_site_settings.map { |uss| [uss.site, FlagLog.auto.successful.where(site: uss.site).count] } | |
fps_per_day = flags_per_site.map do |fps| | |
site_flags = FlagLog.auto.successful.where(site: fps[0]) | |
[fps[0], fps[1].to_f / (site_flags.first.created_at.to_i - site_flags.last.created_at.to_i) / 86400)] | |
end | |
fpspd_per_user = if current_user.has_role?(:core) | |
user_count = User.with_role(:core).where(flags_enabled: true).count | |
fps_per_day.map do |fsd| | |
# 2/3 of the flags per day on each site go to core users | |
[fsd[0], (fsd[1] / (2/3.0)) / user_count] | |
end | |
else | |
user_count = User.without_role(:core).where(flags_enabled: true).count | |
fps_per_day.map do |fsd| | |
# 1/3 to everyone else | |
[fsd[0], (fsd[1] / (1/3.0)) / user_count] | |
end | |
end | |
weighted_fsdu = fpspd_per_user.map { |fsdu| [fsdu[0], user_weights[fsdu[0]] * fsdu[1]] } | |
unewighted_flags = fpspd_per_user.map { |fsdu| fsdu[1] }.reduce(:+) | |
weighted_flags = weighted_fsdu.map { |fsdu| fsdu[1] }.reduce(:+) | |
diff = weighted_flags - unweighted_flags | |
if diff.abs <= some_tolerance | |
# valid and fair to everyone | |
else | |
# invalid, user would get too many (or too few) flags | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment