diff options
-rwxr-xr-x | bin/update-all-reports | 3 | ||||
-rwxr-xr-x | perllib/FixMyStreet/Script/UpdateAllReports.pm | 40 |
2 files changed, 28 insertions, 15 deletions
diff --git a/bin/update-all-reports b/bin/update-all-reports index 250901312..4c0e96d31 100755 --- a/bin/update-all-reports +++ b/bin/update-all-reports @@ -22,12 +22,13 @@ use Getopt::Long::Descriptive; my ($opt, $usage) = describe_options( '%c %o', [ 'table', "Output JSON for old table-style page." ], + [ 'areas', "Include area IDs in output JSON." ], [ 'help', "print usage message and exit", { shortcircuit => 1 } ], ); print($usage->text), exit if $opt->help; if ($opt->table) { - FixMyStreet::Script::UpdateAllReports::generate(); + FixMyStreet::Script::UpdateAllReports::generate($opt->areas); } else { FixMyStreet::Script::UpdateAllReports::generate_dashboard(); } 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( { |