include rating and uploader median score in automod events

This commit is contained in:
Albert Yi
2019-02-07 15:17:39 -08:00
parent e69f201e2c
commit a66d0353d8

View File

@@ -24,7 +24,10 @@ module Automod
"copyright_count", "copyright_count",
"translated", "translated",
"comment_count", "comment_count",
"note_count" "note_count",
"rating",
"median_score",
"is_comic"
] ]
Post.where("created_at between ? and ?", start, stop).find_each do |post| Post.where("created_at between ? and ?", start, stop).find_each do |post|
data = build_hash(post) data = build_hash(post)
@@ -44,12 +47,20 @@ module Automod
data[:copyright_count], data[:copyright_count],
data[:translated], data[:translated],
data[:comment_count], data[:comment_count],
data[:note_count] data[:note_count],
data[:rating],
data[:median_score]
] ]
end end
end end
end end
def self.backfill
Post.where("id >= ?", 3_400_840).find_each do |post|
dynamo_db_client
end
end
def build_hash(post) def build_hash(post)
data = { data = {
post_id: post.id, post_id: post.id,
@@ -67,7 +78,9 @@ module Automod
copyright_count: copyright_count(post), copyright_count: copyright_count(post),
translated: is_translated?(post), translated: is_translated?(post),
comment_count: post.comments.count, comment_count: post.comments.count,
note_count: post.notes.count note_count: post.notes.count,
rating: post.rating,
median_score: median_score(post)
} }
end end
@@ -122,5 +135,9 @@ module Automod
def is_translated?(post) def is_translated?(post)
post.has_tag?("translated") post.has_tag?("translated")
end end
def median_score(post)
Post.where("uploader_id = ?", post.uploader_id).where("created_at >= ?", 1.year.ago).pluck("percentile_cont(0.5) within group (order by score)").first
end
end end
end end