add support for reports of 'time to first response' from a set of users

This commit is contained in:
Neil Lalonde 2015-09-14 13:36:41 -04:00
parent 60bbd81607
commit 30999de3e2
2 changed files with 4 additions and 3 deletions

View File

@ -114,7 +114,7 @@ class Report
def self.report_time_to_first_response(report) def self.report_time_to_first_response(report)
report.data = [] report.data = []
Topic.time_to_first_response_per_day(report.start_date, report.end_date, report.category_id).each do |r| Topic.time_to_first_response_per_day(report.start_date, report.end_date, {category_id: report.category_id}).each do |r|
report.data << { x: Date.parse(r["date"]), y: r["hours"].to_f.round(2) } report.data << { x: Date.parse(r["date"]), y: r["hours"].to_f.round(2) }
end end
report.total = Topic.time_to_first_response_total(category_id: report.category_id) report.total = Topic.time_to_first_response_total(category_id: report.category_id)

View File

@ -911,12 +911,13 @@ class Topic < ActiveRecord::Base
builder.where("p.deleted_at IS NULL") builder.where("p.deleted_at IS NULL")
builder.where("p.post_number > 1") builder.where("p.post_number > 1")
builder.where("p.user_id != t.user_id") builder.where("p.user_id != t.user_id")
builder.where("p.user_id in (:user_ids)", {user_ids: opts[:user_ids]}) if opts[:user_ids]
builder.where("EXTRACT(EPOCH FROM p.created_at - t.created_at) > 0") builder.where("EXTRACT(EPOCH FROM p.created_at - t.created_at) > 0")
builder.exec builder.exec
end end
def self.time_to_first_response_per_day(start_date, end_date, category_id=nil) def self.time_to_first_response_per_day(start_date, end_date, opts={})
time_to_first_response(TIME_TO_FIRST_RESPONSE_SQL, start_date: start_date, end_date: end_date, category_id: category_id) time_to_first_response(TIME_TO_FIRST_RESPONSE_SQL, opts.merge({start_date: start_date, end_date: end_date}))
end end
def self.time_to_first_response_total(opts=nil) def self.time_to_first_response_total(opts=nil)