aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2017-06-21 13:30:02 +0100
committerDave Arter <davea@mysociety.org>2017-07-17 14:17:45 +0100
commit105b2fbd64f4e2482c578ad499ec220f5ee49384 (patch)
tree8249c0993e4fe5a984f82ac829b8ac881d0c085a
parent104a583de563aa340ecbd8e86f14683bc46194c7 (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
-rwxr-xr-xbin/update-all-reports3
-rwxr-xr-xperllib/FixMyStreet/Script/UpdateAllReports.pm40
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( {