A platform for community discussion. Free, open, simple.
FIX: Store user_accuracy_bonus to clarify explanations (#8165)
Mark VanLandingham057f698e37d2
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rbindex 539ae3c2f9d..750f99544a3 100644--- a/app/models/reviewable.rb+++ b/app/models/reviewable.rb@@ -159,6 +159,7 @@ class Reviewable < ActiveRecord::Basetype_bonus = PostActionType.where(id: reviewable_score_type).pluck(:score_bonus)[0] || 0take_action_bonus = take_action ? 5.0 : 0.0sub_total = (ReviewableScore.user_flag_score(user) + type_bonus + take_action_bonus)+ user_accuracy_bonus = ReviewableScore.user_accuracy_bonus(user)# We can force a reviewable to hit the threshold, for example with queued postsif force_review && sub_total < Reviewable.min_score_for_priority@@ -170,6 +171,7 @@ class Reviewable < ActiveRecord::Basestatus: ReviewableScore.statuses[:pending],reviewable_score_type: reviewable_score_type,score: sub_total,+ user_accuracy_bonus: user_accuracy_bonus,meta_topic_id: meta_topic_id,take_action_bonus: take_action_bonus,created_at: created_at || Time.zone.now@@ -491,6 +493,7 @@ class Reviewable < ActiveRecord::Baseus.flags_disagreed,us.flags_ignored,rs.score,+ rs.user_accuracy_bonus,rs.take_action_bonus,COALESCE(pat.score_bonus, 0.0) AS type_bonusFROM reviewable_scores AS rsdiff --git a/app/models/reviewable_score.rb b/app/models/reviewable_score.rbindex e51af3c0a2d..1fe28972977 100644--- a/app/models/reviewable_score.rb+++ b/app/models/reviewable_score.rb@@ -84,7 +84,8 @@ class ReviewableScore < ActiveRecord::Baseaxis_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)+ (absolute_distance * axis_distance_multiplier * positivity_multiplier * (Math.log(total, 4) * 5.0))+ .round(2)enddef reviewable_conversationdiff --git a/app/serializers/reviewable_score_explanation_serializer.rb b/app/serializers/reviewable_score_explanation_serializer.rbindex 73dccc01bf7..f0082022883 100644--- a/app/serializers/reviewable_score_explanation_serializer.rb+++ b/app/serializers/reviewable_score_explanation_serializer.rb@@ -12,9 +12,4 @@ class ReviewableScoreExplanationSerializer < ApplicationSerializer:user_accuracy_bonus,:score)-- def user_accuracy_bonus- ReviewableScore.calc_user_accuracy_bonus(object.flags_agreed, object.flags_disagreed)- end-enddiff --git a/db/migrate/20191007140446_add_user_accuracy_bonus_to_reviewable_scores.rb b/db/migrate/20191007140446_add_user_accuracy_bonus_to_reviewable_scores.rbnew file mode 100644index 00000000000..e9e2b7a6f0b--- /dev/null+++ b/db/migrate/20191007140446_add_user_accuracy_bonus_to_reviewable_scores.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true++class AddUserAccuracyBonusToReviewableScores < ActiveRecord::Migration[6.0]+ def up+ # Add user_accuracy_bonus to reviewable_scores+ add_column :reviewable_scores, :user_accuracy_bonus, :float, default: 0, null: false++ # Set user_accuracy_bonus = score - user.trust_level - 1+ execute <<~SQL+ UPDATE reviewable_scores+ SET user_accuracy_bonus = score - users.trust_level - 1+ FROM users+ WHERE reviewable_scores.user_id = users.id+ SQL+ end++ def down+ # Remove user_accuracy_bonus from reviewable_scores+ remove_column :reviewable_scores, :user_accuracy_bonus+ end+enddiff --git a/spec/models/reviewable_score_spec.rb b/spec/models/reviewable_score_spec.rbindex 03c96163323..47fe188f617 100644--- a/spec/models/reviewable_score_spec.rb+++ b/spec/models/reviewable_score_spec.rb@@ -135,7 +135,7 @@ RSpec.describe ReviewableScore, type: :model douser_stat.flags_agreed = 9user_stat.flags_disagreed = 2- expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(3.40)+ expect(ReviewableScore.user_accuracy_bonus(user).floor(2)).to eq(3.41)user_stat.flags_agreed = 25user_stat.flags_disagreed = 4@@ -170,7 +170,7 @@ RSpec.describe ReviewableScore, type: :model douser_stat.flags_agreed = 12user_stat.flags_disagreed = 2user_stat.flags_ignored = 2- expect(ReviewableScore.user_flag_score(user).floor(2)).to eq(7.98)+ expect(ReviewableScore.user_flag_score(user).floor(2)).to eq(7.99)endit 'return 0 if the accuracy_bonus would make the score negative' do