aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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.pm17
-rwxr-xr-xperllib/FixMyStreet/Script/UpdateAllReports.pm2
4 files changed, 20 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..3c013378c 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({
@@ -214,6 +215,7 @@ sub calculate_average {
],
'me.id' => \"= ($substmt)",
'me.state' => 'confirmed',
+ 'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ],
}, {
select => [
{ extract => "epoch from me.confirmed-problem.confirmed", -as => 'time' },
@@ -224,12 +226,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;
}