aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result/Body.pm
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 /perllib/FixMyStreet/DB/Result/Body.pm
parent1fcda0014022042efb17920699638c30156b04d2 (diff)
[FixaMinGata] Adds a cobrand hook (threshold for responsiveness top 5 list)
Fixes #1957
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Body.pm')
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm16
1 files changed, 10 insertions, 6 deletions
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;