diff options
author | Dave Arter <davea@mysociety.org> | 2017-06-21 13:30:02 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2017-07-17 14:17:45 +0100 |
commit | 105b2fbd64f4e2482c578ad499ec220f5ee49384 (patch) | |
tree | 8249c0993e4fe5a984f82ac829b8ac881d0c085a /perllib/FixMyStreet/Script/UpdateAllReports.pm | |
parent | 104a583de563aa340ecbd8e86f14683bc46194c7 (diff) |
Include area stats in all-reports.json
This makes it possible to display stats per area on /reports
Cobrands using this functionality should use the pre-dashboard
reports/index.html template and pass --areas when calling bin/update-all-reports
Diffstat (limited to 'perllib/FixMyStreet/Script/UpdateAllReports.pm')
-rwxr-xr-x | perllib/FixMyStreet/Script/UpdateAllReports.pm | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm index b68f0d6e0..0af7be9ba 100755 --- a/perllib/FixMyStreet/Script/UpdateAllReports.pm +++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm @@ -22,9 +22,12 @@ if ( FixMyStreet->config('BASE_URL') =~ /zurich|zueri/ ) { } sub generate { + my $include_areas = shift; + my $problems = FixMyStreet::DB->resultset('Problem')->search( { state => [ FixMyStreet::DB::Result::Problem->visible_states() ], + bodies_str => \'is not null', }, { columns => [ @@ -41,23 +44,21 @@ sub generate { while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; my @bodies; + my @areas; my $cobrand = $problem{cobrand}; + my $duration_str = ( $problem{duration} > 2 * $fourweeks ) ? 'old' : 'new'; + my $type = ( $problem{duration} > 2 * $fourweeks ) + ? 'unknown' + : ($problem{age} > $fourweeks ? 'older' : 'new'); + my $problem_fixed = + FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}} + || FixMyStreet::DB::Result::Problem->closed_states()->{$problem{state}}; + + # Add to bodies it was sent to + @bodies = split( /,/, $problem{bodies_str} ); - if ( !$problem{bodies_str} ) { - # Problem was not sent to any bodies, add to all areas - @bodies = grep { $_ } split( /,/, $problem{areas} ); - $problem{bodies} = 0; - } else { - # Add to bodies it was sent to - @bodies = split( /,/, $problem{bodies_str} ); - $problem{bodies} = scalar @bodies; - } foreach my $body ( @bodies ) { - my $duration_str = ( $problem{duration} > 2 * $fourweeks ) ? 'old' : 'new'; - my $type = ( $problem{duration} > 2 * $fourweeks ) - ? 'unknown' - : ($problem{age} > $fourweeks ? 'older' : 'new'); - if (FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}} || FixMyStreet::DB::Result::Problem->closed_states()->{$problem{state}}) { + if ( $problem_fixed ) { # Fixed problems are either old or new $fixed{$body}{$duration_str}++; $fixed{$cobrand}{$body}{$duration_str}++; @@ -67,6 +68,17 @@ sub generate { $open{$cobrand}{$body}{$type}++; } } + + if ( $include_areas ) { + @areas = grep { $_ } split( /,/, $problem{areas} ); + foreach my $area ( @areas ) { + if ( $problem_fixed ) { + $fixed{areas}{$area}{$duration_str}++; + } else { + $open{areas}{$area}{$type}++; + } + } + } } my $body = encode_json( { |