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])
end
filtered_results = data.where('date >= ? AND date <= ?', report.start_date.to_date, report.end_date.to_date)
filtered_results = filtered_results.where(category_id: report.category_id) if report.category_id
filtered_results = data
filtered_results = data.filtered_results.where(category_id: report.category_id) if report.category_id
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)
.sum(:count)
.each do |date, count|
@ -75,7 +76,10 @@ class Report
end
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

View File

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