aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tasks
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-09-04 09:49:34 +0100
committerLouise Crow <louise.crow@gmail.com>2013-09-04 09:49:34 +0100
commit95afa296f8989ac691df24cc28a963c06a4c86e3 (patch)
treeb1b80813f963ee4a417b05d4bb4d012648d30dff /lib/tasks
parent05f9fca1fb2161e078429b6a1f3796a0bf13eade (diff)
parent4656b24591593bdf5521030ce6bdf68baec6d160 (diff)
Merge branch 'body-statistics' into rails-3-develop
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/stats.rake21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake
index 9d7d70540..1242575fe 100644
--- a/lib/tasks/stats.rake
+++ b/lib/tasks/stats.rake
@@ -91,4 +91,25 @@ namespace :stats do
end
end
+ desc 'Update statistics in the public_bodies table'
+ task :update_public_bodies_stats => :environment do
+ PublicBody.all.each do |public_body|
+ puts "Counting overdue requests for #{public_body.name}"
+ # Look for values of 'waiting_response_overdue' and
+ # 'waiting_response_very_overdue' which aren't directly in the
+ # described_state column, and instead need to be calculated:
+ overdue_count = 0
+ very_overdue_count = 0
+ InfoRequest.find_each(:conditions => {:public_body_id => public_body.id}) do |ir|
+ case ir.calculate_status
+ when 'waiting_response_very_overdue'
+ very_overdue_count += 1
+ when 'waiting_response_overdue'
+ overdue_count += 1
+ end
+ end
+ public_body.info_requests_overdue_count = overdue_count + very_overdue_count
+ public_body.save!
+ end
+ end
end