2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

FIX: application request numbers for prev 30 day period was for current 30 day period minus today, not previous 30 days

This commit is contained in:
Neil Lalonde 2015-07-06 14:57:11 -04:00
parent 5c8302c789
commit 8c84e60df6
2 changed files with 9 additions and 5 deletions

View file

@ -63,11 +63,12 @@ class Report
ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter]) ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])
end end
filtered_results = data.where('date >= ? AND date <= ?', report.start_date.to_date, report.end_date.to_date) filtered_results = data
filtered_results = filtered_results.where(category_id: report.category_id) if report.category_id filtered_results = data.filtered_results.where(category_id: report.category_id) if report.category_id
report.data = [] report.data = []
filtered_results.order(date: :asc) filtered_results.where('date >= ? AND date <= ?', report.start_date.to_date, report.end_date.to_date)
.order(date: :asc)
.group(:date) .group(:date)
.sum(:count) .sum(:count)
.each do |date, count| .each do |date, count|
@ -75,7 +76,10 @@ class Report
end end
report.total = data.sum(:count) report.total = data.sum(:count)
report.prev30Days = filtered_results.sum(:count) report.prev30Days = filtered_results.where('date >= ? AND date <= ?',
(report.start_date - 31.days).to_date,
(report.end_date - 31.days).to_date )
.sum(:count)
end end

View file

@ -132,7 +132,7 @@ describe Report do
end end
it 'returns previous 30 days of data' do it 'returns previous 30 days of data' do
expect(report.prev30Days).to eq 14 expect(report.prev30Days).to eq 35
end end
end end
end end