aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Script
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2017-11-30 15:22:31 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-12-15 17:35:53 +0000
commitaf7a457bfaed2ba143aaeccfc7ccf2b8d443e22d (patch)
tree7c8244118b58600e314d77b682817927f68f2500 /perllib/FixMyStreet/Script
parentfb75d4f912c504b42d11f2c8f32b5dcff2b348b6 (diff)
[fixmystreet.com] Council average response time.
Diffstat (limited to 'perllib/FixMyStreet/Script')
-rwxr-xr-xperllib/FixMyStreet/Script/UpdateAllReports.pm27
1 files changed, 3 insertions, 24 deletions
diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm
index f4f444d5b..d6f3eb64b 100755
--- a/perllib/FixMyStreet/Script/UpdateAllReports.pm
+++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm
@@ -199,7 +199,7 @@ sub generate_dashboard {
if ($body) {
calculate_top_five_wards(\%data, $rs, $body);
} else {
- calculate_top_five_bodies(\%data, $rs_c);
+ calculate_top_five_bodies(\%data);
}
my $week_ago = $dtf->format_datetime(DateTime->now->subtract(days => 7));
@@ -247,34 +247,13 @@ sub stuff_by_day_or_year {
}
sub calculate_top_five_bodies {
- my ($data, $rs_c) = @_;
+ my ($data) = @_;
my(@top_five_bodies);
my $bodies = FixMyStreet::DB->resultset('Body')->search;
- 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)";
while (my $body = $bodies->next) {
- my $subquery = $rs_c->to_body($body)->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');
+ my $avg = $body->calculate_average;
push @top_five_bodies, { name => $body->name, days => int($avg / 60 / 60 / 24 + 0.5) }
if defined $avg;
}