Class: ReviewableScore
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ReviewableScore
- Defined in:
- app/models/reviewable_score.rb
Class Method Summary collapse
- .add_new_types(type_names) ⇒ Object
- .calc_user_accuracy_bonus(agreed, disagreed) ⇒ Object
- .calculate_score(user, type_bonus, take_action_bonus) ⇒ Object
-
.reload_types ⇒ Object
When extending post action flags, we need to call this method in order to get the latests flags.
- .score_transitions ⇒ Object
- .type_title(type) ⇒ Object
-
.types ⇒ Object
To keep things simple the types correspond to ‘PostActionType` for backwards compatibility, but we can add extra reasons for scores.
-
.user_accuracy_bonus(user) ⇒ Object
A user’s accuracy bonus is: if 5 or less flags => 0.0 if > 5 flags => (agreed flags / total flags) * 5.0.
-
.user_flag_score(user) ⇒ Object
A user’s flag score is: 1.0 + trust_level + user_accuracy_bonus (trust_level is 5 for staff).
Instance Method Summary collapse
Class Method Details
.add_new_types(type_names) ⇒ Object
30 31 32 33 34 |
# File 'app/models/reviewable_score.rb', line 30 def self.add_new_types(type_names) next_id = types.values.max + 1 type_names.each_with_index { |name, idx| @types[name] = next_id + idx } end |
.calc_user_accuracy_bonus(agreed, disagreed) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/reviewable_score.rb', line 70 def self.calc_user_accuracy_bonus(agreed, disagreed) agreed ||= 0 disagreed ||= 0 total = (agreed + disagreed).to_f return 0.0 if total <= 5 accuracy_axis = 0.7 percent_correct = agreed / total positive_accuracy = percent_correct >= accuracy_axis bottom = positive_accuracy ? accuracy_axis : 0.0 top = positive_accuracy ? 1.0 : accuracy_axis absolute_distance = positive_accuracy ? percent_correct - bottom : top - percent_correct axis_distance_multiplier = 1.0 / (top - bottom) positivity_multiplier = positive_accuracy ? 1.0 : -1.0 ( absolute_distance * axis_distance_multiplier * positivity_multiplier * (Math.log(total, 4) * 5.0) ).round(2) end |
.calculate_score(user, type_bonus, take_action_bonus) ⇒ Object
48 49 50 51 |
# File 'app/models/reviewable_score.rb', line 48 def self.calculate_score(user, type_bonus, take_action_bonus) score = user_flag_score(user) + type_bonus + take_action_bonus score > 0 ? score : 0 end |
.reload_types ⇒ Object
When extending post action flags, we need to call this method in order to get the latests flags.
25 26 27 28 |
# File 'app/models/reviewable_score.rb', line 25 def self.reload_types @types = nil types end |
.score_transitions ⇒ Object
36 37 38 |
# File 'app/models/reviewable_score.rb', line 36 def self.score_transitions { approved: statuses[:agreed], rejected: statuses[:disagreed], ignored: statuses[:ignored] } end |
.type_title(type) ⇒ Object
17 18 19 20 21 |
# File 'app/models/reviewable_score.rb', line 17 def self.type_title(type) I18n.t("post_action_types.#{type}.title", default: nil) || I18n.t("reviewable_score_types.#{type}.title", default: nil) || PostActionType.names[types[type]] end |
.types ⇒ Object
To keep things simple the types correspond to ‘PostActionType` for backwards compatibility, but we can add extra reasons for scores.
13 14 15 |
# File 'app/models/reviewable_score.rb', line 13 def self.types @types ||= PostActionType.flag_types.merge(PostActionType.score_types) end |
.user_accuracy_bonus(user) ⇒ Object
A user’s accuracy bonus is:
if 5 or less flags => 0.0
if > 5 flags => (agreed flags / total flags) * 5.0
63 64 65 66 67 68 |
# File 'app/models/reviewable_score.rb', line 63 def self.user_accuracy_bonus(user) user_stat = user&.user_stat return 0.0 if user_stat.blank? || user.bot? calc_user_accuracy_bonus(user_stat.flags_agreed, user_stat.flags_disagreed) end |
.user_flag_score(user) ⇒ Object
A user’s flag score is:
1.0 + trust_level + user_accuracy_bonus
(trust_level is 5 for staff)
56 57 58 |
# File 'app/models/reviewable_score.rb', line 56 def self.user_flag_score(user) 1.0 + (user.staff? ? 5.0 : user.trust_level.to_f) + user_accuracy_bonus(user) end |
Instance Method Details
#reviewable_conversation ⇒ Object
95 96 97 98 |
# File 'app/models/reviewable_score.rb', line 95 def reviewable_conversation return if .blank? Reviewable::Conversation.new() end |
#score_type ⇒ Object
40 41 42 |
# File 'app/models/reviewable_score.rb', line 40 def score_type Reviewable::Collection::Item.new(reviewable_score_type) end |
#took_action? ⇒ Boolean
44 45 46 |
# File 'app/models/reviewable_score.rb', line 44 def took_action? take_action_bonus > 0 end |