aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-04-16 14:41:31 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-04-23 15:00:26 +0100
commitce4d1c9214d211dc33444c900e759cd1cb4377b2 (patch)
tree55fbdb13413ed38f0143cd1b22039d745ea412e3
parent797d47897505837d1b77c28221c87586cefc12f1 (diff)
Add a cobrand hook to table dashboard generation.
This allows a cobrand to categorise the reports however it wishes.
-rwxr-xr-xperllib/CronFns.pm1
-rwxr-xr-xperllib/FixMyStreet/Script/UpdateAllReports.pm42
-rw-r--r--t/app/controller/reports.t3
3 files changed, 29 insertions, 17 deletions
diff --git a/perllib/CronFns.pm b/perllib/CronFns.pm
index 888817e05..58237d322 100755
--- a/perllib/CronFns.pm
+++ b/perllib/CronFns.pm
@@ -27,6 +27,7 @@ sub site {
my $base_url = shift;
my $site = 'fixmystreet';
$site = 'zurich' if $base_url =~ /zurich|zueri/;
+ $site = 'smidsy' if $base_url =~ /smidsy|collideosco/;
return $site;
}
diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm
index d6f3eb64b..21d8d28a0 100755
--- a/perllib/FixMyStreet/Script/UpdateAllReports.pm
+++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm
@@ -6,23 +6,24 @@ use warnings;
use FixMyStreet;
use FixMyStreet::Cobrand;
use FixMyStreet::DB;
+use CronFns;
use List::MoreUtils qw(zip);
use List::Util qw(sum);
+my $site = CronFns::site(FixMyStreet->config('BASE_URL'));
+
my $fourweeks = 4*7*24*60*60;
# Age problems from when they're confirmed, except on Zurich
# where they appear as soon as they're created.
my $age_column = 'confirmed';
-if ( FixMyStreet->config('BASE_URL') =~ /zurich|zueri/ ) {
- $age_column = 'created';
-}
+$age_column = 'created' if $site eq 'zurich';
my $dtf = FixMyStreet::DB->schema->storage->datetime_parser;
-my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('default')->new;
-FixMyStreet::DB->schema->cobrand($cobrand);
+my $cobrand_cls = FixMyStreet::Cobrand->get_class_for_moniker($site)->new;
+FixMyStreet::DB->schema->cobrand($cobrand_cls);
sub generate {
my $include_areas = shift;
@@ -34,7 +35,7 @@ sub generate {
},
{
columns => [
- 'id', 'bodies_str', 'state', 'areas', 'cobrand',
+ 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'category',
{ duration => { extract => "epoch from current_timestamp-lastupdate" } },
{ age => { extract => "epoch from current_timestamp-$age_column" } },
]
@@ -43,13 +44,26 @@ sub generate {
$problems = $problems->cursor; # Raw DB cursor for speed
my ( %fixed, %open );
- my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'duration', 'age' );
+ my %stats = (
+ fixed => \%fixed,
+ open => \%open,
+ );
+ my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'category', 'duration', 'age' );
while ( my @problem = $problems->next ) {
my %problem = zip @cols, @problem;
- my @bodies;
- my @areas;
+ my @bodies = split( /,/, $problem{bodies_str} );
my $cobrand = $problem{cobrand};
+
+ if (my $type = $cobrand_cls->call_hook(dashboard_categorize_problem => \%problem)) {
+ foreach my $body ( @bodies ) {
+ $stats{$type}{$body}++;
+ $stats{$cobrand}{$type}{$body}++;
+ }
+ next;
+ }
+
my $duration_str = ( $problem{duration} > 2 * $fourweeks ) ? 'old' : 'new';
+
my $type = ( $problem{duration} > 2 * $fourweeks )
? 'unknown'
: ($problem{age} > $fourweeks ? 'older' : 'new');
@@ -57,9 +71,6 @@ sub generate {
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} );
-
foreach my $body ( @bodies ) {
if ( $problem_fixed ) {
# Fixed problems are either old or new
@@ -73,7 +84,7 @@ sub generate {
}
if ( $include_areas ) {
- @areas = grep { $_ } split( /,/, $problem{areas} );
+ my @areas = grep { $_ } split( /,/, $problem{areas} );
foreach my $area ( @areas ) {
if ( $problem_fixed ) {
$fixed{areas}{$area}{$duration_str}++;
@@ -84,10 +95,7 @@ sub generate {
}
}
- return {
- fixed => \%fixed,
- open => \%open,
- };
+ return \%stats;
}
sub end_period {
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index 76c920562..8cdfddd1b 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -95,6 +95,9 @@ $fife_problems[10]->update( {
state => 'hidden',
});
+# Run the cron script old-data (for the table no longer used by default)
+FixMyStreet::Script::UpdateAllReports::generate(1);
+
# Run the cron script that makes the data for /reports so we don't get an error.
my $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard();