aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Script
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/Script')
-rwxr-xr-xperllib/FixMyStreet/Script/UpdateAllReports.pm36
1 files changed, 22 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm
index 21d8d28a0..e3ea63e6e 100755
--- a/perllib/FixMyStreet/Script/UpdateAllReports.pm
+++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm
@@ -99,13 +99,14 @@ sub generate {
}
sub end_period {
- my $period = shift;
- FixMyStreet->set_time_zone(DateTime->now)->truncate(to => $period)->add($period . 's' => 1)->subtract(seconds => 1);
+ my ($period, $end) = @_;
+ $end ||= DateTime->now;
+ FixMyStreet->set_time_zone($end)->truncate(to => $period)->add($period . 's' => 1)->subtract(seconds => 1);
}
sub loop_period {
- my ($date, $period, $extra) = @_;
- my $end = end_period($period);
+ my ($date, $extra, $period, $end) = @_;
+ $end = end_period($period, $end);
my @out;
while ($date <= $end) {
push @out, { n => $date->$period, $extra ? (d => $date->$extra) : () };
@@ -114,6 +115,21 @@ sub loop_period {
return @out;
}
+sub get_period_group {
+ my ($start, $end) = @_;
+ my ($group_by, $extra);
+ if (DateTime::Duration->compare($end - $start, DateTime::Duration->new(months => 1)) < 0) {
+ $group_by = 'day';
+ } elsif (DateTime::Duration->compare($end - $start, DateTime::Duration->new(years => 1)) < 0) {
+ $group_by = 'month';
+ $extra = 'month_abbr';
+ } else {
+ $group_by = 'year';
+ }
+
+ return ($group_by, $extra);
+}
+
sub generate_dashboard {
my $body = shift;
@@ -138,16 +154,8 @@ sub generate_dashboard {
$min_confirmed = FixMyStreet->set_time_zone(DateTime->now)->truncate(to => 'day');
}
- my ($group_by, $extra);
- if (DateTime::Duration->compare($end_today - $min_confirmed, DateTime::Duration->new(months => 1)) < 0) {
- $group_by = 'day';
- } elsif (DateTime::Duration->compare($end_today - $min_confirmed, DateTime::Duration->new(years => 1)) < 0) {
- $group_by = 'month';
- $extra = 'month_abbr';
- } else {
- $group_by = 'year';
- }
- my @problem_periods = loop_period($min_confirmed, $group_by, $extra);
+ my ($group_by, $extra) = get_period_group($min_confirmed, $end_today);
+ my @problem_periods = loop_period($min_confirmed, $extra, $group_by);
my %problems_reported_by_period = stuff_by_day_or_year(
$group_by, $rs,