aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorMark Longair <mhl@pobox.com>2013-11-04 11:06:13 +0000
committerMark Longair <mhl@pobox.com>2013-11-05 15:47:17 +0000
commit23ca1b442493f30f07cf80bdd20f8f060464bb92 (patch)
treec249c3491d0b3ef90ddd818934d2e5383b793723 /spec/models
parentb16ed7188e0df7329da7c5d6c07ce16df2c0682d (diff)
For percentage stats, exclude hidden or unclassified requests
The WDTK volunteers pointed out that it's not fair to include hidden requests in the denominator, since they're typically hidden for a good reason (e.g. being vexatious, spam, etc.), and we have no information about those that are awaiting_description (i.e. unclassified) so they should be excluded as well.
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/public_body_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 714934ee3..3ef4c71e7 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -530,3 +530,33 @@ describe PublicBody, " when override all public body request emails set" do
@geraldine.request_email.should == "catch_all_test_email@foo.com"
end
end
+
+describe PublicBody, "when calculating statistics" do
+ it "should not include unclassified or hidden requests in percentages" do
+ with_hidden_and_successful_requests do
+ totals_data = PublicBody.get_request_totals(n=3,
+ highest=true,
+ minimum_requests=1)
+ # For the total number of requests, we still include
+ # hidden or unclassified requests:
+ totals_data['public_bodies'][-1].name.should == "Geraldine Quango"
+ totals_data['totals'][-1].should == 4
+
+ # However, for percentages, don't include the hidden or
+ # unclassified requests. So, for the Geraldine Quango
+ # we've made sure that there are only two visible and
+ # classified requests, one of which is successful, so the
+ # percentage should be 50%:
+
+ percentages_data = PublicBody.get_request_percentages(column='info_requests_successful_count',
+ n=3,
+ highest=false,
+ minimum_requests=1)
+ geraldine_index = percentages_data['public_bodies'].index do |pb|
+ pb.name == "Geraldine Quango"
+ end
+
+ percentages_data['y_values'][geraldine_index].should == 50
+ end
+ end
+end