diff options
author | Struan Donald <struan@exo.org.uk> | 2017-11-30 15:22:31 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-12-15 17:35:53 +0000 |
commit | af7a457bfaed2ba143aaeccfc7ccf2b8d443e22d (patch) | |
tree | 7c8244118b58600e314d77b682817927f68f2500 /perllib/FixMyStreet/DB | |
parent | fb75d4f912c504b42d11f2c8f32b5dcff2b348b6 (diff) |
[fixmystreet.com] Council average response time.
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index da5c38168..e5cd2b907 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -183,4 +183,33 @@ sub get_cobrand_handler { return FixMyStreet::Cobrand->body_handler($self->areas); } +sub calculate_average { + my ($self) = @_; + + 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({ + -or => [ + problem_state => [ FixMyStreet::DB::Result::Problem->fixed_states() ], + mark_fixed => 1, + ], + 'me.id' => \"= ($substmt)", + 'me.state' => 'confirmed', + }, { + select => [ + { extract => "epoch from me.confirmed-problem.confirmed", -as => 'time' }, + ], + as => [ qw/time/ ], + rows => 100, + order_by => { -desc => 'me.confirmed' }, + join => 'problem' + })->as_subselect_rs; + + my $avg = $subquery->search({ + }, { + select => [ { avg => "time" } ], + as => [ qw/avg/ ], + })->first->get_column('avg'); + return $avg; +} + 1; |