Dashboard: split out private messages from topic and post counts; re-enable report_spec because I think I fixed it...

This commit is contained in:
Neil Lalonde
2013-04-03 13:25:52 -04:00
parent 738789f336
commit bb18b6cb9b
12 changed files with 149 additions and 66 deletions

View File

@@ -113,6 +113,7 @@
{{ render 'admin_report_counts' likes }}
{{ render 'admin_report_counts' flags }}
{{ render 'admin_report_counts' emails }}
{{ render 'admin_report_counts' private_messages }}
{{/unless}}
</table>
</div>

View File

@@ -2,7 +2,7 @@ require_dependency 'mem_info'
class AdminDashboardData
REPORTS = ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails']
REPORTS = ['visits', 'signups', 'topics', 'posts', 'flags', 'users_by_trust_level', 'likes', 'emails', 'private_messages']
def self.fetch_all
AdminDashboardData.new

View File

@@ -8,7 +8,7 @@ class EmailLog < ActiveRecord::Base
User.update_all("last_emailed_at = CURRENT_TIMESTAMP", id: user_id) if user_id.present?
end
def self.count_per_day(since = 30.days.ago)
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
def self.count_per_day(sinceDaysAgo = 30)
where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
end
end

View File

@@ -390,7 +390,11 @@ class Post < ActiveRecord::Base
Jobs.enqueue(:process_post, args)
end
def self.count_per_day(since=30.days.ago)
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
def self.public_posts_count_per_day(sinceDaysAgo=30)
joins(:topic).where('topics.archetype <> ?', [Archetype.private_message]).where('posts.created_at > ?', sinceDaysAgo.days.ago).group('date(posts.created_at)').order('date(posts.created_at)').count
end
def self.private_messages_count_per_day(sinceDaysAgo=30)
joins(:topic).where('topics.archetype = ?', Archetype.private_message).where('posts.created_at > ?', sinceDaysAgo.days.ago).group('date(posts.created_at)').order('date(posts.created_at)').count
end
end

View File

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

View File

@@ -40,11 +40,15 @@ class Report
end
def self.report_topics(report)
report_about report, Topic
report_about report, Topic, :listable_count_per_day
end
def self.report_posts(report)
report_about report, Post
report_about report, Post, :public_posts_count_per_day
end
def self.report_private_messages(report)
report_about report, Post, :private_messages_count_per_day
end
def self.report_emails(report)
@@ -58,7 +62,7 @@ class Report
def self.basic_report_about(report, subject_class, report_method)
report.data = []
subject_class.send(report_method, 30.days.ago).each do |date, count|
subject_class.send(report_method, 30).each do |date, count|
report.data << {x: date, y: count}
end
end
@@ -89,7 +93,7 @@ class Report
def self.report_likes(report)
report.data = []
PostAction.count_likes_per_day(30.days.ago).each do |date, count|
PostAction.count_likes_per_day(30).each do |date, count|
report.data << {x: date, y: count}
end
likesQuery = PostAction.where(post_action_type_id: PostActionType.types[:like])

View File

@@ -192,8 +192,8 @@ class Topic < ActiveRecord::Base
where("created_at > ?", time_ago)
end
def self.count_per_day(since=30.days.ago)
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
def self.listable_count_per_day(sinceDaysAgo=30)
listable_topics.where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
end
def private_message?

View File

@@ -479,8 +479,8 @@ class User < ActiveRecord::Base
Summarize.new(bio_cooked).summary
end
def self.count_by_signup_date(since=30.days.ago)
where('created_at > ?', since).group('date(created_at)').order('date(created_at)').count
def self.count_by_signup_date(sinceDaysAgo=30)
where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
end
def self.counts_by_trust_level

View File

@@ -2,7 +2,7 @@ class UserVisit < ActiveRecord::Base
attr_accessible :visited_at, :user_id
# A list of visits in the last month by day
def self.by_day(since=30.days.ago)
where("visited_at >= ?", since).group(:visited_at).order(:visited_at).count
def self.by_day(sinceDaysAgo=30)
where("visited_at >= ?", sinceDaysAgo.days.ago).group(:visited_at).order(:visited_at).count
end
end