Add bookmarks and favorites to dashboard stats

This commit is contained in:
Neil Lalonde 2013-04-18 14:27:22 -04:00
parent 75cfcbfa4f
commit 5cd6c85e8b
6 changed files with 47 additions and 12 deletions

View file

@ -129,6 +129,8 @@
{{ render 'admin_report_counts' posts }}
{{ render 'admin_report_counts' likes }}
{{ render 'admin_report_counts' flags }}
{{ render 'admin_report_counts' bookmarks }}
{{ render 'admin_report_counts' favorites }}
{{ render 'admin_report_counts' emails }}
{{/unless}}
</table>

View file

@ -10,6 +10,8 @@ class AdminDashboardData
'flags',
'users_by_trust_level',
'likes',
'bookmarks',
'favorites',
'emails',
'user_to_user_private_messages',
'system_private_messages',

View file

@ -50,8 +50,8 @@ class PostAction < ActiveRecord::Base
user_actions
end
def self.count_likes_per_day(sinceDaysAgo = 30)
where(post_action_type_id: PostActionType.types[:like]).where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
def self.count_per_day_for_type(sinceDaysAgo = 30, post_action_type)
where(post_action_type_id: post_action_type).where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
end
def self.clear_flags!(post, moderator_id, action_type_id = nil)

View file

@ -74,6 +74,22 @@ class Report
report.prev30Days = subject_class.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
end
def self.report_users_by_trust_level(report)
report.data = []
User.counts_by_trust_level.each do |level, count|
report.data << {x: level.to_i, y: count}
end
end
def self.report_favorites(report)
basic_report_about report, Topic, :starred_counts_per_day
query = TopicUser.where(starred: true)
report.total = query.count
report.prev30Days = query.where('starred_at > ? and starred_at < ?', 60.days.ago, 30.days.ago).count
end
# Post action counts:
def self.report_flags(report)
report.data = []
(0..30).to_a.reverse.each do |i|
@ -89,23 +105,26 @@ class Report
report.prev30Days = flagsQuery.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
end
def self.report_users_by_trust_level(report)
report.data = []
User.counts_by_trust_level.each do |level, count|
report.data << {x: level.to_i, y: count}
end
def self.report_likes(report)
post_action_report report, PostActionType.types[:like]
end
def self.report_likes(report)
def self.report_bookmarks(report)
post_action_report report, PostActionType.types[:bookmark]
end
def self.post_action_report(report, post_action_type)
report.data = []
PostAction.count_likes_per_day(30).each do |date, count|
PostAction.count_per_day_for_type(30, post_action_type).each do |date, count|
report.data << {x: date, y: count}
end
likesQuery = PostAction.where(post_action_type_id: PostActionType.types[:like])
report.total = likesQuery.count
report.prev30Days = likesQuery.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
query = PostAction.where(post_action_type_id: post_action_type)
report.total = query.count
report.prev30Days = query.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
end
# Private messages counts:
def self.private_messages_report(report, topic_subtype)
basic_report_about report, Post, :private_messages_count_per_day, topic_subtype
report.total = Post.private_posts.with_topic_subtype(topic_subtype).count

View file

@ -583,6 +583,10 @@ class Topic < ActiveRecord::Base
end
end
def self.starred_counts_per_day(sinceDaysAgo=30)
TopicUser.where('starred_at > ?', sinceDaysAgo.days.ago).group('date(starred_at)').order('date(starred_at)').count
end
# Enable/disable the mute on the topic
def toggle_mute(user, muted)
TopicUser.change(user, self.id, notification_level: muted?(user) ? TopicUser.notification_levels[:regular] : TopicUser.notification_levels[:muted] )

View file

@ -298,6 +298,14 @@ en:
title: "Flags"
xaxis: "Day"
yaxis: "Number of flags"
bookmarks:
title: "Bookmarks"
xaxis: "Day"
yaxis: "Number of new bookmarks"
favorites:
title: "Favorites"
xaxis: "Day"
yaxis: "Number of new favorites"
users_by_trust_level:
title: "Users per Trust Level"
xaxis: "Trust Level"