diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-02-25 12:18:00 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-02-25 12:18:00 +0000 |
commit | e481c2fd127c46024b1b15587981dca00eada44c (patch) | |
tree | 9b3884e8904e9e63d1b39bea4eae5f9c12009c92 /perllib/FixMyStreet/DB | |
parent | 7f41c1b26110e18c0068bcd9e209daebe26b6779 (diff) | |
parent | b9e1b1384b11acbd5d9fd51e92eb7278fb6eb43d (diff) |
Merge branch 'bugfix/1957'
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 17 |
1 files changed, 11 insertions, 6 deletions
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; |