ApplicationRequest can return a report

This commit is contained in:
Neil Lalonde 2015-02-04 15:05:16 -05:00
parent 3948a960cd
commit 27557b8402
1 changed files with 22 additions and 0 deletions

View File

@ -82,6 +82,28 @@ class ApplicationRequest < ActiveRecord::Base
"app_req_#{req_type}#{time.strftime('%Y%m%d')}" "app_req_#{req_type}#{time.strftime('%Y%m%d')}"
end end
def self.stats
@stats ||= begin
s = HashWithIndifferentAccess.new({
all_total: 0,
all_30_days: 0,
all_7_days: 0
})
self.req_types.each do |key, i|
query = self.where(req_type: i)
s["#{key}_total"] = query.sum(:count)
s["#{key}_30_days"] = query.where("date > ?", 30.days.ago).sum(:count)
s["#{key}_7_days"] = query.where("date > ?", 7.days.ago).sum(:count)
s[:all_total] += s["#{key}_total"]
s[:all_30_days] += s["#{key}_30_days"]
s[:all_7_days] += s["#{key}_7_days"]
end
s
end
end
end end
# == Schema Information # == Schema Information