diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 29 | ||||
-rwxr-xr-x | perllib/FixMyStreet/Script/UpdateAllReports.pm | 27 | ||||
-rw-r--r-- | templates/web/fixmystreet.com/reports/summary.html | 1 |
5 files changed, 41 insertions, 24 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index cff4c8dab..e1183c247 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -287,6 +287,13 @@ sub generate_summary_figures { } } +sub generate_body_response_time : Private { + my ( $self, $c ) = @_; + + my $avg = $c->stash->{body}->calculate_average; + $c->stash->{body_average} = $avg ? int($avg / 60 / 60 / 24 + 0.5) : 0; +} + sub export_as_csv { my ($self, $c) = @_; require Text::CSV; diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 5ac3da197..724fc7fbd 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -469,6 +469,7 @@ sub summary : Private { $c->forward('/dashboard/construct_rs_filter'); $c->forward('/dashboard/generate_grouped_data'); + $c->forward('/dashboard/generate_body_response_time'); $c->stash->{template} = 'reports/summary.html'; } 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; 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; } diff --git a/templates/web/fixmystreet.com/reports/summary.html b/templates/web/fixmystreet.com/reports/summary.html index 6ea664331..8b7f84f59 100644 --- a/templates/web/fixmystreet.com/reports/summary.html +++ b/templates/web/fixmystreet.com/reports/summary.html @@ -100,6 +100,7 @@ [% END %] </tbody> <tfoot> + <tr><td>[% body.name %]</td><td>[% tprintf(nget("%s day", "%s days", body_average), body_average) %]</td></tr> <tr><td>[% loc('Overall average') %]</td><td>[% tprintf(nget("%s day", "%s days", average), average) %]</td></tr> </tfoot> </table> |