Trust level 3 measurements redone
This commit is contained in:
parent
0289e60a25
commit
b69bc5a5f5
|
@ -10,12 +10,14 @@ Discourse.LeaderRequirements = Discourse.Model.extend({
|
||||||
met: function() {
|
met: function() {
|
||||||
return {
|
return {
|
||||||
days_visited: this.get('days_visited') >= this.get('min_days_visited'),
|
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_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')
|
flagged_posts: this.get('num_flagged_posts') < this.get('max_flagged_posts')
|
||||||
};
|
};
|
||||||
}.property('days_visited', 'min_days_visited',
|
}.property('days_visited', 'min_days_visited',
|
||||||
'num_topics_with_replies', 'min_topics_with_replies',
|
|
||||||
'num_topics_replied_to', 'min_topics_replied_to',
|
'num_topics_replied_to', 'min_topics_replied_to',
|
||||||
|
'topics_viewed', 'min_topics_viewed',
|
||||||
|
'posts_read', 'min_posts_read',
|
||||||
'num_flagged_posts', 'max_flagged_posts')
|
'num_flagged_posts', 'max_flagged_posts')
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,12 +31,6 @@
|
||||||
</td>
|
</td>
|
||||||
<td>{{min_days_visited_percent}}%</td>
|
<td>{{min_days_visited_percent}}%</td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<th>{{i18n admin.user.tl3_requirements.topics_replied_to}}</th>
|
<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>
|
<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>
|
<td>{{min_topics_replied_to}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{i18n admin.user.tl3_requirements.quality_content}}</th>
|
<th>{{i18n admin.user.tl3_requirements.topics_viewed}}</th>
|
||||||
<td></td>
|
<td><i {{bindAttr class=":fa met.topics_viewed:fa-check:fa-times"}}></i></td>
|
||||||
<td style="color: #ccc;">
|
<td>{{topics_viewed}}</td>
|
||||||
TODO
|
<td>{{min_topics_viewed}}</td>
|
||||||
</td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{i18n admin.user.tl3_requirements.reading}}</th>
|
<th>{{i18n admin.user.tl3_requirements.posts_read}}</th>
|
||||||
<td></td>
|
<td><i {{bindAttr class=":fa met.posts_read:fa-check:fa-times"}}></i></td>
|
||||||
<td style="color: #ccc;">
|
<td>{{posts_read}}</td>
|
||||||
TODO
|
<td>{{min_posts_read}}</td>
|
||||||
</td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<th>{{i18n admin.user.tl3_requirements.site_promotion}}</th>
|
|
||||||
<td></td>
|
|
||||||
<td style="color: #ccc;">
|
|
||||||
TODO
|
|
||||||
</td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{i18n admin.user.tl3_requirements.flagged_posts}}</th>
|
<th>{{i18n admin.user.tl3_requirements.flagged_posts}}</th>
|
||||||
|
@ -75,6 +57,15 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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}}
|
{{/with}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -6,18 +6,22 @@ class LeaderRequirements
|
||||||
|
|
||||||
attr_accessor :time_period,
|
attr_accessor :time_period,
|
||||||
:days_visited, :min_days_visited,
|
:days_visited, :min_days_visited,
|
||||||
:num_topics_with_replies, :min_topics_with_replies,
|
|
||||||
:num_topics_replied_to, :min_topics_replied_to,
|
:num_topics_replied_to, :min_topics_replied_to,
|
||||||
|
:topics_viewed, :min_topics_viewed,
|
||||||
|
:posts_read, :min_posts_read,
|
||||||
:num_flagged_posts, :max_flagged_posts
|
:num_flagged_posts, :max_flagged_posts
|
||||||
|
|
||||||
def initialize(user)
|
def initialize(user)
|
||||||
@user = user
|
@user = user
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO
|
def requirements_met?
|
||||||
# def requirements_met?
|
days_visited >= min_days_visited &&
|
||||||
# false
|
num_topics_replied_to >= min_topics_replied_to &&
|
||||||
# end
|
topics_viewed >= min_topics_viewed &&
|
||||||
|
posts_read >= min_posts_read &&
|
||||||
|
num_flagged_posts <= max_flagged_posts
|
||||||
|
end
|
||||||
|
|
||||||
def time_period
|
def time_period
|
||||||
100 # days
|
100 # days
|
||||||
|
@ -31,14 +35,6 @@ class LeaderRequirements
|
||||||
time_period * 0.5
|
time_period * 0.5
|
||||||
end
|
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
|
def num_topics_replied_to
|
||||||
@user.posts.select('distinct topic_id').where('created_at > ? AND post_number > 1', time_period.days.ago).count
|
@user.posts.select('distinct topic_id').where('created_at > ? AND post_number > 1', time_period.days.ago).count
|
||||||
end
|
end
|
||||||
|
@ -47,11 +43,31 @@ class LeaderRequirements
|
||||||
10
|
10
|
||||||
end
|
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
|
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
|
end
|
||||||
|
|
||||||
def max_flagged_posts
|
def max_flagged_posts
|
||||||
5 # TODO what should it be?
|
5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,6 +54,7 @@ class Post < ActiveRecord::Base
|
||||||
scope :public_posts, -> { joins(:topic).where('topics.archetype <> ?', Archetype.private_message) }
|
scope :public_posts, -> { joins(:topic).where('topics.archetype <> ?', Archetype.private_message) }
|
||||||
scope :private_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 :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
|
delegate :username, to: :user
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
class LeaderRequirementsSerializer < ApplicationSerializer
|
class LeaderRequirementsSerializer < ApplicationSerializer
|
||||||
attributes :time_period,
|
attributes :time_period,
|
||||||
|
:requirements_met,
|
||||||
:days_visited, :min_days_visited,
|
:days_visited, :min_days_visited,
|
||||||
:num_topics_with_replies, :min_topics_with_replies,
|
|
||||||
:num_topics_replied_to, :min_topics_replied_to,
|
:num_topics_replied_to, :min_topics_replied_to,
|
||||||
|
:topics_viewed, :min_topics_viewed,
|
||||||
|
:posts_read, :min_posts_read,
|
||||||
:num_flagged_posts, :max_flagged_posts
|
:num_flagged_posts, :max_flagged_posts
|
||||||
|
|
||||||
|
def requirements_met
|
||||||
|
object.requirements_met?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1796,11 +1796,9 @@ en:
|
||||||
requirement_heading: "Requirement"
|
requirement_heading: "Requirement"
|
||||||
visits: "Visits"
|
visits: "Visits"
|
||||||
days: "days"
|
days: "days"
|
||||||
topics_with_replies: "Topics with Replies"
|
|
||||||
topics_replied_to: "Topics Replied To"
|
topics_replied_to: "Topics Replied To"
|
||||||
quality_content: "Quality Content"
|
topics_viewed: "Topics Viewed"
|
||||||
reading: "Reading"
|
posts_read: "Posts Read"
|
||||||
site_promotion: "Site Promotion"
|
|
||||||
flagged_posts: "Flagged Posts"
|
flagged_posts: "Flagged Posts"
|
||||||
|
|
||||||
site_content:
|
site_content:
|
||||||
|
|
Loading…
Reference in New Issue