aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/info_request.rb
diff options
context:
space:
mode:
authorMark Longair <mhl@pobox.com>2013-11-01 18:34:15 +0000
committerMark Longair <mhl@pobox.com>2013-11-05 15:47:17 +0000
commit26c1dfce9392e65c20cf348fbded1fc1542c82c4 (patch)
tree2538bdc8b77d56b7e5af940f8a104e905b741c1c /app/models/info_request.rb
parentf22df45505fb12056e7c062e8f522c313aaa0aee (diff)
Update the calculation of the numerator for percentage statistics
We have changed the denominator of the proportion-based statistics to only include requests that are both visible and not 'awaiting_description'. This would mean, however, that the numerator could be larger than the denominator. This commit updates the calculation of those statistics to also exclude any hidden or unclassified requests.
Diffstat (limited to 'app/models/info_request.rb')
-rw-r--r--app/models/info_request.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index bb6a5eb1d..9463a236e 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -1182,18 +1182,23 @@ public
after_save :update_counter_cache
after_destroy :update_counter_cache
+ # This method updates the count columns of the PublicBody that
+ # store the number of "not held", "to some extent successful" and
+ # "both visible and classified" requests when saving or destroying
+ # an InfoRequest associated with the body:
def update_counter_cache
PublicBody.skip_callback(:save, :after, :purge_in_cache)
- self.public_body.info_requests_not_held_count = InfoRequest.where(
- :public_body_id => self.public_body.id,
- :described_state => 'not_held').count
- 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(
+ basic_params = {
:public_body_id => self.public_body_id,
:awaiting_description => false,
- :prominence => 'normal').count
+ :prominence => 'normal'
+ }
+ [['info_requests_not_held_count', {:described_state => 'not_held'}],
+ ['info_requests_successful_count', {:described_state => ['successful', 'partially_successful']}],
+ ['info_requests_visible_classified_count', {}]].each do |column, extra_params|
+ params = basic_params.clone.update extra_params
+ self.public_body.send "#{column}=", InfoRequest.where(params).count
+ end
self.public_body.without_revision do
public_body.no_xapian_reindex = true
public_body.save