aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tasks/stats.rake
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-09-24 09:23:44 +0100
committerLouise Crow <louise.crow@gmail.com>2013-09-24 09:23:44 +0100
commit7d9b66d1ff31afa8d73ea1a81f4e612e41f89cb0 (patch)
tree5206d9fbaf8d6af58bdaa35cefdfeb34a88c84ff /lib/tasks/stats.rake
parent40a28fa2fe21d752a15c11938791d620dd31d17f (diff)
parent8e7432be764254e6a50e6a06e77bb93bb5bba9fe (diff)
Merge branch 'release/0.14' into wdtk
Conflicts: app/views/request/show.html.erb
Diffstat (limited to 'lib/tasks/stats.rake')
-rw-r--r--lib/tasks/stats.rake26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake
index 9d7d70540..4eda27289 100644
--- a/lib/tasks/stats.rake
+++ b/lib/tasks/stats.rake
@@ -91,4 +91,30 @@ namespace :stats do
end
end
+ desc 'Update statistics in the public_bodies table'
+ task :update_public_bodies_stats => :environment do
+ verbose = ENV['VERBOSE'] == '1'
+ PublicBody.all.each do |public_body|
+ puts "Counting overdue requests for #{public_body.name}" if verbose
+
+ # 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.no_xapian_reindex = true
+ public_body.without_revision do
+ public_body.save!
+ end
+ end
+ end
end