Trust level 3 measurements redone

This commit is contained in:
Neil Lalonde 2014-06-26 13:48:07 -04:00
parent 0289e60a25
commit b69bc5a5f5
6 changed files with 62 additions and 48 deletions

View File

@ -10,12 +10,14 @@ Discourse.LeaderRequirements = Discourse.Model.extend({
met: function() {
return {
days_visited: this.get('days_visited') >= this.get('min_days_visited'),
topics_with_replies: this.get('num_topics_with_replies') >= this.get('min_topics_with_replies'),
topics_replied_to: this.get('num_topics_replied_to') >= this.get('min_topics_replied_to'),
topics_viewed: this.get('topics_viewed') >= this.get('min_topics_viewed'),
posts_read: this.get('posts_read') >= this.get('min_posts_read'),
flagged_posts: this.get('num_flagged_posts') < this.get('max_flagged_posts')
};
}.property('days_visited', 'min_days_visited',
'num_topics_with_replies', 'min_topics_with_replies',
'num_topics_replied_to', 'min_topics_replied_to',
'topics_viewed', 'min_topics_viewed',
'posts_read', 'min_posts_read',
'num_flagged_posts', 'max_flagged_posts')
});

View File

@ -31,12 +31,6 @@
</td>
<td>{{min_days_visited_percent}}%</td>
</tr>
<tr>
<th>{{i18n admin.user.tl3_requirements.topics_with_replies}}</th>
<td><i {{bindAttr class=":fa met.topics_with_replies:fa-check:fa-times"}}></i></td>
<td>{{num_topics_with_replies}}</td>
<td>{{min_topics_with_replies}}</td>
</tr>
<tr>
<th>{{i18n admin.user.tl3_requirements.topics_replied_to}}</th>
<td><i {{bindAttr class=":fa met.topics_replied_to:fa-check:fa-times"}}></i></td>
@ -44,28 +38,16 @@
<td>{{min_topics_replied_to}}</td>
</tr>
<tr>
<th>{{i18n admin.user.tl3_requirements.quality_content}}</th>
<td></td>
<td style="color: #ccc;">
TODO
</td>
<td></td>
<th>{{i18n admin.user.tl3_requirements.topics_viewed}}</th>
<td><i {{bindAttr class=":fa met.topics_viewed:fa-check:fa-times"}}></i></td>
<td>{{topics_viewed}}</td>
<td>{{min_topics_viewed}}</td>
</tr>
<tr>
<th>{{i18n admin.user.tl3_requirements.reading}}</th>
<td></td>
<td style="color: #ccc;">
TODO
</td>
<td></td>
</tr>
<tr>
<th>{{i18n admin.user.tl3_requirements.site_promotion}}</th>
<td></td>
<td style="color: #ccc;">
TODO
</td>
<td></td>
<th>{{i18n admin.user.tl3_requirements.posts_read}}</th>
<td><i {{bindAttr class=":fa met.posts_read:fa-check:fa-times"}}></i></td>
<td>{{posts_read}}</td>
<td>{{min_posts_read}}</td>
</tr>
<tr>
<th>{{i18n admin.user.tl3_requirements.flagged_posts}}</th>
@ -75,6 +57,15 @@
</tr>
</tbody>
</table>
<br/>
<p>
{{#if requirements_met}}
<i class="fa fa-check"></i> Qualifies for trust level 3
{{else}}
<i class="fa fa-times"></i> Doesn't qualify for trust level 3
{{/if}}
</p>
{{/with}}
</div>

View File

@ -6,18 +6,22 @@ class LeaderRequirements
attr_accessor :time_period,
:days_visited, :min_days_visited,
:num_topics_with_replies, :min_topics_with_replies,
:num_topics_replied_to, :min_topics_replied_to,
:topics_viewed, :min_topics_viewed,
:posts_read, :min_posts_read,
:num_flagged_posts, :max_flagged_posts
def initialize(user)
@user = user
end
# TODO
# def requirements_met?
# false
# end
def requirements_met?
days_visited >= min_days_visited &&
num_topics_replied_to >= min_topics_replied_to &&
topics_viewed >= min_topics_viewed &&
posts_read >= min_posts_read &&
num_flagged_posts <= max_flagged_posts
end
def time_period
100 # days
@ -31,14 +35,6 @@ class LeaderRequirements
time_period * 0.5
end
def num_topics_with_replies
@user.topics.where('posts_count > 1 AND participant_count > 1 AND created_at > ?', time_period.days.ago).count
end
def min_topics_with_replies
5
end
def num_topics_replied_to
@user.posts.select('distinct topic_id').where('created_at > ? AND post_number > 1', time_period.days.ago).count
end
@ -47,11 +43,31 @@ class LeaderRequirements
10
end
def topics_viewed
View.where('viewed_at > ?', time_period.days.ago).where(user_id: @user.id, parent_type: 'Topic').select('distinct(parent_id)').count
end
def min_topics_viewed
(Topic.listable_topics.visible.created_since(time_period.days.ago).count * 0.25).round
end
def posts_read
@user.user_visits.where('visited_at > ?', time_period.days.ago).pluck(:posts_read).sum
end
def min_posts_read
(Post.public_posts.visible.created_since(time_period.days.ago).count * 0.25).round
end
def num_flagged_posts
@user.posts.where('created_at > ? AND (off_topic_count > 0 OR spam_count > 0 OR illegal_count > 0 OR inappropriate_count > 0 OR notify_moderators_count > 0)', time_period.days.ago).count
# Count the number of posts that were flagged, and moderators explicitly agreed with the flags
# by clicking the "Agree (hide post + send PM)" or "Defer" (on an automatically hidden post) buttons.
# In both cases, the defer flag is set to true.
post_ids = @user.posts.with_deleted.where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', time_period.days.ago).pluck(:id)
PostAction.with_deleted.where(post_id: post_ids).where(defer: true).pluck(:post_id).uniq.count
end
def max_flagged_posts
5 # TODO what should it be?
5
end
end

View File

@ -54,6 +54,7 @@ class Post < ActiveRecord::Base
scope :public_posts, -> { joins(:topic).where('topics.archetype <> ?', Archetype.private_message) }
scope :private_posts, -> { joins(:topic).where('topics.archetype = ?', Archetype.private_message) }
scope :with_topic_subtype, ->(subtype) { joins(:topic).where('topics.subtype = ?', subtype) }
scope :visible, -> { joins(:topic).where('topics.visible = true').where(hidden: false) }
delegate :username, to: :user

View File

@ -1,7 +1,13 @@
class LeaderRequirementsSerializer < ApplicationSerializer
attributes :time_period,
:requirements_met,
:days_visited, :min_days_visited,
:num_topics_with_replies, :min_topics_with_replies,
:num_topics_replied_to, :min_topics_replied_to,
:topics_viewed, :min_topics_viewed,
:posts_read, :min_posts_read,
:num_flagged_posts, :max_flagged_posts
def requirements_met
object.requirements_met?
end
end

View File

@ -1796,11 +1796,9 @@ en:
requirement_heading: "Requirement"
visits: "Visits"
days: "days"
topics_with_replies: "Topics with Replies"
topics_replied_to: "Topics Replied To"
quality_content: "Quality Content"
reading: "Reading"
site_promotion: "Site Promotion"
topics_viewed: "Topics Viewed"
posts_read: "Posts Read"
flagged_posts: "Flagged Posts"
site_content: