aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm68
-rw-r--r--templates/web/default/dashboard/index.html22
2 files changed, 54 insertions, 36 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index 0273e0eda..3de050cf9 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -61,7 +61,7 @@ sub index : Path : Args(0) {
$c->stash->{ward} = $c->req->param('ward');
$c->stash->{category} = $c->req->param('category');
- $c->stash->{q_state} = $c->req->param('state');
+ $c->stash->{q_state} = $c->req->param('state') || '';
my %where = (
council => $council, # XXX This will break in a two tier council. Restriction needs looking at...
@@ -76,35 +76,29 @@ sub index : Path : Args(0) {
} elsif ( $c->stash->{q_state} ) {
$where{'problem.state'} = $c->stash->{q_state}
}
+ $c->stash->{where} = \%where;
+ my $prob_where = { %where };
+ $prob_where->{state} = $prob_where->{'problem.state'};
+ delete $prob_where->{'problem.state'};
+ $c->stash->{prob_where} = $prob_where;
my %counts;
my $t = DateTime->today;
-
- $counts{wtd} = $c->forward( 'updates_search', [ {
- %where,
- 'me.confirmed' => { '>=', $t->subtract( days => $t->dow - 1 )
- } } ] );
-
- $counts{week} = $c->forward( 'updates_search', [ {
- %where,
- 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 1 )
- } } ] );
-
- $counts{weeks} = $c->forward( 'updates_search', [ {
- %where,
- 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 4 )
- } } ] );
-
- $counts{ytd} = $c->forward( 'updates_search', [ {
- %where,
- 'me.confirmed' => { '>=', DateTime->today->set( day => 1, month => 1 )
- } } ] );
+ $counts{wtd} = $c->forward( 'updates_search', [ $t->subtract( days => $t->dow - 1 ) ] );
+ $counts{week} = $c->forward( 'updates_search', [ DateTime->now->subtract( weeks => 1 ) ] );
+ $counts{weeks} = $c->forward( 'updates_search', [ DateTime->now->subtract( weeks => 4 ) ] );
+ $counts{ytd} = $c->forward( 'updates_search', [ DateTime->today->set( day => 1, month => 1 ) ] );
$c->stash->{problems} = \%counts;
}
sub updates_search : Private {
- my ( $self, $c, $params ) = @_;
+ my ( $self, $c, $time ) = @_;
+
+ my $params = {
+ %{$c->stash->{where}},
+ 'me.confirmed' => { '>=', $time },
+ };
my $comments = $c->model('DB::Comment')->search(
$params,
@@ -124,12 +118,38 @@ sub updates_search : Private {
'fixed - user', 'fixed', 'unconfirmed', 'hidden',
'partial', 'planned');
+ for my $vars (
+ [ 'time_to_fix', 'fixed - council' ],
+ [ 'time_to_mark', 'in progress', 'planned', 'investigating' ],
+ ) {
+ my $col = shift @$vars;
+ my $substmt = "select min(id) from comment where me.problem_id=comment.problem_id and problem_state in ('"
+ . join("','", @$vars) . "')";
+ $comments = $c->model('DB::Comment')->search(
+ { %$params,
+ problem_state => $vars,
+ 'me.id' => \"= ($substmt)",
+ },
+ {
+ select => [
+ { count => 'me.id' },
+ { avg => { extract => "epoch from me.confirmed-problem.confirmed" } },
+ ],
+ as => [ qw/state_count time/ ],
+ join => 'problem'
+ }
+ )->first;
+ $counts{$col} = int( $comments->get_column('time') / 60 / 60 / 24 + 0.5 );
+ }
+
$counts{fixed_user} = $c->model('DB::Comment')->search(
{ %$params, mark_fixed => 1 }, { join => 'problem' }
)->count;
- $params->{state} = $params->{'problem.state'};
- delete $params->{'problem.state'};
+ $params = {
+ %{$c->stash->{prob_where}},
+ 'me.confirmed' => { '>=', $time },
+ };
$counts{total} = $c->cobrand->problems->search( $params )->count;
return \%counts;
diff --git a/templates/web/default/dashboard/index.html b/templates/web/default/dashboard/index.html
index a0ef7b911..931415fe7 100644
--- a/templates/web/default/dashboard/index.html
+++ b/templates/web/default/dashboard/index.html
@@ -88,19 +88,19 @@
</tr>
<tr>
- <th scope="row">Average time to fix</th>
- <td>-</td>
- <td>-</td>
- <td>-</td>
- <td>-</td>
+ <th scope="row">Average time to council marking fixed (days)</th>
+ <td>[% problems.wtd.time_to_fix %]</td>
+ <td>[% problems.week.time_to_fix %]</td>
+ <td>[% problems.weeks.time_to_fix %]</td>
+ <td>[% problems.ytd.time_to_fix %]</td>
</tr>
<tr>
- <th scope="row">Average time to mark</th>
- <td>-</td>
- <td>-</td>
- <td>-</td>
- <td>-</td>
+ <th scope="row">Average time to first council state change (days)</th>
+ <td>[% problems.wtd.time_to_mark %]</td>
+ <td>[% problems.week.time_to_mark %]</td>
+ <td>[% problems.weeks.time_to_mark %]</td>
+ <td>[% problems.ytd.time_to_mark %]</td>
</tr>
<tr class='subtotal'>
@@ -131,13 +131,11 @@
<th scope="col">Less than 7 days old</th>
<th scope="col">7-14 days old</th>
<th scope="col">14-30 days old</th>
- <th scope="col">30+ days old</th>
</tr>
<tr>
<td><ul><li></li></ul></td>
<td><ul><li></li></ul></td>
<td><ul><li></li></ul></td>
- <td><ul><li></li></ul></td>
</tr>
</table>