aboutsummaryrefslogtreecommitdiffstats
path: root/bin/update-all-reports
diff options
context:
space:
mode:
Diffstat (limited to 'bin/update-all-reports')
-rwxr-xr-xbin/update-all-reports18
1 files changed, 12 insertions, 6 deletions
diff --git a/bin/update-all-reports b/bin/update-all-reports
index 0627cedc2..d951756e4 100755
--- a/bin/update-all-reports
+++ b/bin/update-all-reports
@@ -17,10 +17,12 @@ BEGIN {
require "$d/../setenv.pl";
}
-use FixMyStreet::App;
+use FixMyStreet;
+use FixMyStreet::DB;
+
use File::Path ();
use File::Slurp;
-use JSON;
+use JSON::MaybeXS;
use List::MoreUtils qw(zip);
my $fourweeks = 4*7*24*60*60;
@@ -32,13 +34,13 @@ if ( FixMyStreet->config('BASE_URL') =~ /zurich|zueri/ ) {
$age_column = 'created';
}
-my $problems = FixMyStreet::App->model("DB::Problem")->search(
+my $problems = FixMyStreet::DB->resultset('Problem')->search(
{
state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
},
{
columns => [
- 'id', 'bodies_str', 'state', 'areas',
+ 'id', 'bodies_str', 'state', 'areas', 'cobrand',
{ duration => { extract => "epoch from current_timestamp-lastupdate" } },
{ age => { extract => "epoch from current_timestamp-$age_column" } },
]
@@ -47,10 +49,12 @@ my $problems = FixMyStreet::App->model("DB::Problem")->search(
$problems = $problems->cursor; # Raw DB cursor for speed
my ( %fixed, %open );
-my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'duration', 'age' );
+my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'duration', 'age' );
while ( my @problem = $problems->next ) {
my %problem = zip @cols, @problem;
my @bodies;
+ my $cobrand = $problem{cobrand};
+
if ( !$problem{bodies_str} ) {
# Problem was not sent to any bodies, add to all areas
@bodies = grep { $_ } split( /,/, $problem{areas} );
@@ -68,9 +72,11 @@ while ( my @problem = $problems->next ) {
if (FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}} || FixMyStreet::DB::Result::Problem->closed_states()->{$problem{state}}) {
# Fixed problems are either old or new
$fixed{$body}{$duration_str}++;
+ $fixed{$cobrand}{$body}{$duration_str}++;
} else {
# Open problems are either unknown, older, or new
$open{$body}{$type}++;
+ $open{$cobrand}{$body}{$type}++;
}
}
}
@@ -83,7 +89,7 @@ if ( FixMyStreet->config('BASE_URL') =~ /emptyhomes/ ) {
}
}
-my $body = JSON->new->utf8(1)->encode( {
+my $body = encode_json( {
fixed => \%fixed,
open => \%open,
} );