aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Siltberg <git@joesiltberg.se>2019-02-21 15:38:32 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2019-02-25 10:08:07 +0000
commitf582e71e03d8d661768b8f977107a87e6bd2d2b8 (patch)
tree7154b6c0f05159c64cb84c482f2db3a8a9fab7de
parent1fcda0014022042efb17920699638c30156b04d2 (diff)
[FixaMinGata] Adds a cobrand hook (threshold for responsiveness top 5 list)
Fixes #1957
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/FixaMinGata.pm7
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm16
-rwxr-xr-xperllib/FixMyStreet/Script/UpdateAllReports.pm2
4 files changed, 19 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index d597ff0ea..5bc82444d 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -292,7 +292,7 @@ sub generate_summary_figures {
sub generate_body_response_time : Private {
my ( $self, $c ) = @_;
- my $avg = $c->stash->{body}->calculate_average;
+ my $avg = $c->stash->{body}->calculate_average($c->cobrand->call_hook("body_responsiveness_threshold"));
$c->stash->{body_average} = $avg ? int($avg / 60 / 60 / 24 + 0.5) : 0;
}
diff --git a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm
index 9233d479e..d1a1980a7 100644
--- a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm
+++ b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm
@@ -185,4 +185,11 @@ sub always_view_body_contribute_details {
return 1;
}
+# Average responsiveness will only be calculated if a body
+# has at least this many fixed reports.
+# (Used in the Top 5 list in /reports)
+sub body_responsiveness_threshold {
+ return 5;
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index d459d5f02..cccb1ddf3 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -204,7 +204,8 @@ sub get_cobrand_handler {
}
sub calculate_average {
- my ($self) = @_;
+ my ($self, $threshold) = @_;
+ $threshold ||= 0;
my $substmt = "select min(id) from comment where me.problem_id=comment.problem_id and (problem_state in ('fixed', 'fixed - council', 'fixed - user') or mark_fixed)";
my $subquery = FixMyStreet::DB->resultset('Comment')->to_body($self)->search({
@@ -224,12 +225,15 @@ sub calculate_average {
join => 'problem'
})->as_subselect_rs;
- my $avg = $subquery->search({
+ my $result = $subquery->search({
}, {
- select => [ { avg => "time" } ],
- as => [ qw/avg/ ],
- })->first->get_column('avg');
- return $avg;
+ select => [ { avg => "time" }, { count => "time" } ],
+ as => [ qw/avg count/ ],
+ })->first;
+ my $avg = $result->get_column('avg');
+ my $count = $result->get_column('count');
+
+ return $count >= $threshold ? $avg : undef;
}
1;
diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm
index e3ea63e6e..33665b9da 100755
--- a/perllib/FixMyStreet/Script/UpdateAllReports.pm
+++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm
@@ -269,7 +269,7 @@ sub calculate_top_five_bodies {
my $bodies = FixMyStreet::DB->resultset('Body')->search;
while (my $body = $bodies->next) {
- my $avg = $body->calculate_average;
+ my $avg = $body->calculate_average($cobrand_cls->call_hook("body_responsiveness_threshold"));
push @top_five_bodies, { name => $body->name, days => int($avg / 60 / 60 / 24 + 0.5) }
if defined $avg;
}