Skip to content
Permalink
Browse files

FIX: Store user_accuracy_bonus to clarify explanations (#8165)

* FIX: Store user_accuracy_bonus to clarify explanations

* Fixed specs from rounding change

* migration cleanup

* user_accuracy_bonus column not nullable
  • Loading branch information...
markvanlan authored and eviltrout committed Oct 8, 2019
1 parent 4c9ed7b commit 057f698e37d2ede776cc787ea55ca69e89ad05f7
@@ -159,6 +159,7 @@ def add_score(
type_bonus = PostActionType.where(id: reviewable_score_type).pluck(:score_bonus)[0] || 0
take_action_bonus = take_action ? 5.0 : 0.0
sub_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 posts
if force_review && sub_total < Reviewable.min_score_for_priority
@@ -170,6 +171,7 @@ def add_score(
status: 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 @@ def explain_score
us.flags_disagreed,
us.flags_ignored,
rs.score,
rs.user_accuracy_bonus,
rs.take_action_bonus,
COALESCE(pat.score_bonus, 0.0) AS type_bonus
FROM reviewable_scores AS rs
@@ -84,7 +84,8 @@ def self.calc_user_accuracy_bonus(agreed, disagreed)
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)
(absolute_distance * axis_distance_multiplier * positivity_multiplier * (Math.log(total, 4) * 5.0))
.round(2)
end

def reviewable_conversation
@@ -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

end
@@ -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
end
@@ -135,7 +135,7 @@

user_stat.flags_agreed = 9
user_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 = 25
user_stat.flags_disagreed = 4
@@ -170,7 +170,7 @@
user_stat.flags_agreed = 12
user_stat.flags_disagreed = 2
user_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)
end

it 'return 0 if the accuracy_bonus would make the score negative' do

0 comments on commit 057f698

Please sign in to comment.
You can’t perform that action at this time.