aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/info_request.rb4
-rw-r--r--app/models/public_body.rb42
-rw-r--r--db/migrate/20131101155844_add_stats_denominator.rb15
-rw-r--r--spec/fixtures/public_bodies.yml48
-rw-r--r--spec/models/public_body_spec.rb41
5 files changed, 90 insertions, 60 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index eba620f53..bb6a5eb1d 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -1190,6 +1190,10 @@ public
self.public_body.info_requests_successful_count = InfoRequest.where(
:public_body_id => self.public_body.id,
:described_state => ['successful', 'partially_successful']).count
+ self.public_body.info_requests_visible_classified_count = InfoRequest.where(
+ :public_body_id => self.public_body_id,
+ :awaiting_description => false,
+ :prominence => 'normal').count
self.public_body.without_revision do
public_body.no_xapian_reindex = true
public_body.save
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 9e77eb181..7f8356dcf 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -3,26 +3,27 @@
#
# Table name: public_bodies
#
-# id :integer not null, primary key
-# name :text not null
-# short_name :text not null
-# request_email :text not null
-# version :integer not null
-# last_edit_editor :string(255) not null
-# last_edit_comment :text not null
-# created_at :datetime not null
-# updated_at :datetime not null
-# url_name :text not null
-# home_page :text default(""), not null
-# notes :text default(""), not null
-# first_letter :string(255) not null
-# publication_scheme :text default(""), not null
-# api_key :string(255) not null
-# info_requests_count :integer default(0), not null
-# disclosure_log :text default(""), not null
-# info_requests_successful_count :integer
-# info_requests_not_held_count :integer
-# info_requests_overdue_count :integer
+# id :integer not null, primary key
+# name :text not null
+# short_name :text not null
+# request_email :text not null
+# version :integer not null
+# last_edit_editor :string(255) not null
+# last_edit_comment :text not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# url_name :text not null
+# home_page :text default(""), not null
+# notes :text default(""), not null
+# first_letter :string(255) not null
+# publication_scheme :text default(""), not null
+# api_key :string(255) not null
+# info_requests_count :integer default(0), not null
+# disclosure_log :text default(""), not null
+# info_requests_successful_count :integer
+# info_requests_not_held_count :integer
+# info_requests_overdue_count :integer
+# info_requests_visible_classified_count :integer
#
require 'csv'
@@ -193,6 +194,7 @@ class PublicBody < ActiveRecord::Base
acts_as_versioned
self.non_versioned_columns << 'created_at' << 'updated_at' << 'first_letter' << 'api_key'
self.non_versioned_columns << 'info_requests_count' << 'info_requests_successful_count'
+ self.non_versioned_columns << 'info_requests_count' << 'info_requests_visible_classified_count'
self.non_versioned_columns << 'info_requests_not_held_count' << 'info_requests_overdue'
self.non_versioned_columns << 'info_requests_overdue_count'
diff --git a/db/migrate/20131101155844_add_stats_denominator.rb b/db/migrate/20131101155844_add_stats_denominator.rb
new file mode 100644
index 000000000..7df4c8200
--- /dev/null
+++ b/db/migrate/20131101155844_add_stats_denominator.rb
@@ -0,0 +1,15 @@
+class AddStatsDenominator < ActiveRecord::Migration
+ def up
+ add_column :public_bodies, :info_requests_visible_classified_count, :integer
+ PublicBody.connection.execute("UPDATE public_bodies
+ SET info_requests_visible_classified_count =
+ (SELECT COUNT(*) FROM info_requests
+ WHERE awaiting_description = FALSE AND
+ prominence = 'normal' AND
+ public_body_id = public_bodies.id);")
+ end
+
+ def down
+ remove_column :public_bodies, :info_requests_visible_classified_count
+ end
+end
diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml
index e382b3cf6..d0eb572b3 100644
--- a/spec/fixtures/public_bodies.yml
+++ b/spec/fixtures/public_bodies.yml
@@ -2,26 +2,27 @@
#
# Table name: public_bodies
#
-# id :integer not null, primary key
-# name :text not null
-# short_name :text not null
-# request_email :text not null
-# version :integer not null
-# last_edit_editor :string(255) not null
-# last_edit_comment :text not null
-# created_at :datetime not null
-# updated_at :datetime not null
-# url_name :text not null
-# home_page :text default(""), not null
-# notes :text default(""), not null
-# first_letter :string(255) not null
-# publication_scheme :text default(""), not null
-# api_key :string(255) not null
-# info_requests_count :integer default(0), not null
-# disclosure_log :text default(""), not null
-# info_requests_successful_count :integer
-# info_requests_not_held_count :integer
-# info_requests_overdue_count :integer
+# id :integer not null, primary key
+# name :text not null
+# short_name :text not null
+# request_email :text not null
+# version :integer not null
+# last_edit_editor :string(255) not null
+# last_edit_comment :text not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# url_name :text not null
+# home_page :text default(""), not null
+# notes :text default(""), not null
+# first_letter :string(255) not null
+# publication_scheme :text default(""), not null
+# api_key :string(255) not null
+# info_requests_count :integer default(0), not null
+# disclosure_log :text default(""), not null
+# info_requests_successful_count :integer
+# info_requests_not_held_count :integer
+# info_requests_overdue_count :integer
+# info_requests_visible_classified_count :integer
#
geraldine_public_body:
@@ -38,6 +39,7 @@ geraldine_public_body:
created_at: 2007-10-24 10:51:01.161639
api_key: 1
info_requests_count: 4
+ info_requests_visible_classified_count: 4
info_requests_successful_count: 0
info_requests_not_held_count: 0
info_requests_overdue_count: 3
@@ -56,6 +58,7 @@ humpadink_public_body:
notes: An albatross told me!!!
api_key: 2
info_requests_count: 2
+ info_requests_visible_classified_count: 2
info_requests_successful_count: 1
info_requests_not_held_count: 0
info_requests_overdue_count: 1
@@ -74,6 +77,7 @@ forlorn_public_body:
notes: A very lonely public body that no one has corresponded with
api_key: 3
info_requests_count: 0
+ info_requests_visible_classified_count: 0
info_requests_successful_count: 0
info_requests_not_held_count: 0
info_requests_overdue_count: 0
@@ -92,6 +96,7 @@ silly_walks_public_body:
notes: You know the one.
api_key: 4
info_requests_count: 2
+ info_requests_visible_classified_count: 2
info_requests_successful_count: 2
info_requests_not_held_count: 0
info_requests_overdue_count: 0
@@ -110,6 +115,7 @@ sensible_walks_public_body:
created_at: 2008-10-25 10:51:01.161639
api_key: 5
info_requests_count: 1
+ info_requests_visible_classified_count: 1
info_requests_successful_count: 1
info_requests_not_held_count: 0
info_requests_overdue_count: 0
@@ -128,6 +134,7 @@ other_public_body:
created_at: 2008-10-25 10:51:01.161639
api_key: 6
info_requests_count: 0
+ info_requests_visible_classified_count: 0
info_requests_successful_count: 0
info_requests_not_held_count: 0
info_requests_overdue_count: 0
@@ -146,6 +153,7 @@ accented_public_body:
created_at: 2008-10-25 10:51:01.161639
api_key: 7
info_requests_count: 0
+ info_requests_visible_classified_count: 0
info_requests_successful_count: 0
info_requests_not_held_count: 0
info_requests_overdue_count: 0
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 78fc6e516..714934ee3 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -3,26 +3,27 @@
#
# Table name: public_bodies
#
-# id :integer not null, primary key
-# name :text not null
-# short_name :text not null
-# request_email :text not null
-# version :integer not null
-# last_edit_editor :string(255) not null
-# last_edit_comment :text not null
-# created_at :datetime not null
-# updated_at :datetime not null
-# url_name :text not null
-# home_page :text default(""), not null
-# notes :text default(""), not null
-# first_letter :string(255) not null
-# publication_scheme :text default(""), not null
-# api_key :string(255) not null
-# info_requests_count :integer default(0), not null
-# disclosure_log :text default(""), not null
-# info_requests_successful_count :integer
-# info_requests_not_held_count :integer
-# info_requests_overdue_count :integer
+# id :integer not null, primary key
+# name :text not null
+# short_name :text not null
+# request_email :text not null
+# version :integer not null
+# last_edit_editor :string(255) not null
+# last_edit_comment :text not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# url_name :text not null
+# home_page :text default(""), not null
+# notes :text default(""), not null
+# first_letter :string(255) not null
+# publication_scheme :text default(""), not null
+# api_key :string(255) not null
+# info_requests_count :integer default(0), not null
+# disclosure_log :text default(""), not null
+# info_requests_successful_count :integer
+# info_requests_not_held_count :integer
+# info_requests_overdue_count :integer
+# info_requests_visible_classified_count :integer
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')