2013-02-27 22:39:42 -05:00
|
|
|
class Report
|
|
|
|
|
2013-03-21 13:27:53 -04:00
|
|
|
attr_accessor :type, :data, :total
|
2013-02-27 22:39:42 -05:00
|
|
|
|
|
|
|
def initialize(type)
|
|
|
|
@type = type
|
|
|
|
@data = nil
|
2013-03-21 13:27:53 -04:00
|
|
|
@total = nil
|
2013-02-27 22:39:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def as_json
|
|
|
|
{
|
|
|
|
type: self.type,
|
|
|
|
title: I18n.t("reports.#{self.type}.title"),
|
|
|
|
xaxis: I18n.t("reports.#{self.type}.xaxis"),
|
|
|
|
yaxis: I18n.t("reports.#{self.type}.yaxis"),
|
2013-03-21 13:27:53 -04:00
|
|
|
data: self.data,
|
|
|
|
total: self.total
|
2013-02-27 22:39:42 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-03-07 11:07:59 -05:00
|
|
|
def self.find(type, opts={})
|
2013-02-27 22:39:42 -05:00
|
|
|
report_method = :"report_#{type}"
|
|
|
|
return nil unless respond_to?(report_method)
|
|
|
|
|
|
|
|
# Load the report
|
|
|
|
report = Report.new(type)
|
|
|
|
send(report_method, report)
|
|
|
|
report
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.report_visits(report)
|
|
|
|
report.data = []
|
2013-03-20 13:54:32 -04:00
|
|
|
UserVisit.by_day(30.days.ago).each do |date, count|
|
|
|
|
report.data << {x: date, y: count}
|
2013-03-07 11:07:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.report_signups(report)
|
|
|
|
report.data = []
|
2013-03-20 13:54:32 -04:00
|
|
|
User.count_by_signup_date(30.days.ago).each do |date, count|
|
|
|
|
report.data << {x: date, y: count}
|
2013-03-07 11:07:59 -05:00
|
|
|
end
|
2013-03-21 13:27:53 -04:00
|
|
|
report.total = User.count
|
2013-03-07 11:07:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.report_topics(report)
|
|
|
|
report.data = []
|
2013-03-20 13:54:32 -04:00
|
|
|
Topic.count_per_day(30.days.ago).each do |date, count|
|
|
|
|
report.data << {x: date, y: count}
|
2013-02-27 22:39:42 -05:00
|
|
|
end
|
2013-03-21 13:27:53 -04:00
|
|
|
report.total = Topic.count
|
2013-02-27 22:39:42 -05:00
|
|
|
end
|
|
|
|
|
2013-03-07 11:07:59 -05:00
|
|
|
def self.report_posts(report)
|
|
|
|
report.data = []
|
2013-03-20 13:54:32 -04:00
|
|
|
Post.count_per_day(30.days.ago).each do |date, count|
|
|
|
|
report.data << {x: date, y: count}
|
2013-03-07 11:07:59 -05:00
|
|
|
end
|
2013-03-21 13:27:53 -04:00
|
|
|
report.total = Post.count
|
2013-03-07 11:07:59 -05:00
|
|
|
end
|
|
|
|
|
2013-03-12 14:19:01 -04:00
|
|
|
def self.report_flags(report)
|
|
|
|
report.data = []
|
2013-03-20 13:54:32 -04:00
|
|
|
(0..30).to_a.reverse.each do |i|
|
|
|
|
if (count = PostAction.where('date(created_at) = ?', i.days.ago.to_date).where(post_action_type_id: PostActionType.flag_types.values).count) > 0
|
|
|
|
report.data << {x: i.days.ago.to_date.to_s, y: count}
|
2013-03-12 14:19:01 -04:00
|
|
|
end
|
|
|
|
end
|
2013-03-21 13:27:53 -04:00
|
|
|
report.total = PostAction.where(post_action_type_id: PostActionType.flag_types.values).count
|
2013-03-12 14:19:01 -04:00
|
|
|
end
|
|
|
|
|
2013-03-15 18:08:46 -04:00
|
|
|
def self.report_users_by_trust_level(report)
|
|
|
|
report.data = []
|
2013-03-20 13:54:32 -04:00
|
|
|
User.counts_by_trust_level.each do |level, count|
|
|
|
|
report.data << {x: level.to_i, y: count}
|
2013-03-15 18:08:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-17 13:53:00 -04:00
|
|
|
def self.report_likes(report)
|
|
|
|
report.data = []
|
2013-03-20 13:54:32 -04:00
|
|
|
PostAction.count_likes_per_day(30.days.ago).each do |date, count|
|
|
|
|
report.data << {x: date, y: count}
|
2013-03-17 13:53:00 -04:00
|
|
|
end
|
2013-03-21 13:27:53 -04:00
|
|
|
report.total = PostAction.where(post_action_type_id: PostActionType.types[:like]).count
|
2013-03-17 13:53:00 -04:00
|
|
|
end
|
|
|
|
|
2013-03-17 15:08:38 -04:00
|
|
|
def self.report_emails(report)
|
|
|
|
report.data = []
|
2013-03-20 13:54:32 -04:00
|
|
|
EmailLog.count_per_day(30.days.ago).each do |date, count|
|
|
|
|
report.data << {x: date, y: count}
|
2013-03-17 15:08:38 -04:00
|
|
|
end
|
2013-03-21 13:27:53 -04:00
|
|
|
report.total = EmailLog.count
|
2013-03-17 15:08:38 -04:00
|
|
|
end
|
2013-03-07 11:07:59 -05:00
|
|
|
|
2013-02-27 22:39:42 -05:00
|
|
|
end
|