aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Reports.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2017-11-30 15:19:39 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-12-15 17:35:53 +0000
commitfb75d4f912c504b42d11f2c8f32b5dcff2b348b6 (patch)
tree794942f1aa5fff74c3dd40439764c1ad86456692 /perllib/FixMyStreet/App/Controller/Reports.pm
parentf8f4d505ee63e3e8eb83576b3e3ce64c2b35c322 (diff)
[fixmystreet.com] Marketing page, filterable stats
Uses the dashboard stats code to display a rough table of stats which can be used as the basis for a chart later
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm93
1 files changed, 80 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index b6281f0ca..5ac3da197 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -69,19 +69,8 @@ sub index : Path : Args(0) {
}
}
- my $dashboard = eval {
- my $data = FixMyStreet->config('TEST_DASHBOARD_DATA');
- # uncoverable branch true
- unless ($data) {
- my $fn = '../data/all-reports-dashboard';
- if ($c->stash->{body}) {
- $fn .= '-' . $c->stash->{body}->id;
- }
- $data = decode_json(path(FixMyStreet->path_to($fn . '.json'))->slurp_utf8);
- }
- $c->stash($data);
- return 1;
- };
+ my $dashboard = $c->forward('load_dashboard_data');
+
my $table = !$c->stash->{body} && eval {
my $data = path(FixMyStreet->path_to('../data/all-reports.json'))->slurp_utf8;
$c->stash(decode_json($data));
@@ -425,6 +414,65 @@ sub ward_check : Private {
$c->detach( 'redirect_body' );
}
+=head2 summary
+
+This is the summary page used on fixmystreet.com
+
+=cut
+
+sub summary : Private {
+ my ($self, $c) = @_;
+ my $dashboard = $c->forward('load_dashboard_data');
+
+ eval {
+ my $data = path(FixMyStreet->path_to('../data/all-reports-dashboard.json'))->slurp_utf8;
+ $data = decode_json($data);
+ $c->stash(
+ top_five_bodies => $data->{top_five_bodies},
+ average => $data->{average},
+ );
+ };
+
+ my $dtf = $c->model('DB')->storage->datetime_parser;
+ my $period = $c->stash->{period} = $c->get_param('period') || '';
+ my $start_date;
+ if ($period eq 'ever') {
+ $start_date = DateTime->new(year => 2007);
+ } elsif ($period eq 'year') {
+ $start_date = DateTime->now->subtract(years => 1);
+ } elsif ($period eq '3months') {
+ $start_date = DateTime->now->subtract(months => 3);
+ } elsif ($period eq 'week') {
+ $start_date = DateTime->now->subtract(weeks => 1);
+ } else {
+ $c->stash->{period} = 'month';
+ $start_date = DateTime->now->subtract(months => 1);
+ }
+
+ # required to stop errors in generate_grouped_data
+ $c->stash->{q_state} = '';
+ $c->stash->{ward} = $c->get_param('ward');
+ $c->stash->{start_date} = $dtf->format_date($start_date);
+ $c->stash->{end_date} = $c->get_param('end_date');
+
+ $c->stash->{group_by_default} = 'category';
+
+ my $area_id = $c->stash->{body}->body_areas->first->area_id;
+ my $children = mySociety::MaPit::call('area/children', $area_id,
+ type => $c->cobrand->area_types_children,
+ );
+ $c->stash->{children} = $children;
+
+ $c->forward('/admin/fetch_contacts');
+ $c->stash->{contacts} = [ $c->stash->{contacts}->all ];
+
+ $c->forward('/dashboard/construct_rs_filter');
+
+ $c->forward('/dashboard/generate_grouped_data');
+
+ $c->stash->{template} = 'reports/summary.html';
+}
+
=head2 check_canonical_url
Given an already found (case-insensitively) body, check what URL
@@ -441,6 +489,25 @@ sub check_canonical_url : Private {
$c->detach( 'redirect_body' ) unless $body_short eq $url_short;
}
+sub load_dashboard_data : Private {
+ my ($self, $c) = @_;
+ my $dashboard = eval {
+ my $data = FixMyStreet->config('TEST_DASHBOARD_DATA');
+ # uncoverable branch true
+ unless ($data) {
+ my $fn = '../data/all-reports-dashboard';
+ if ($c->stash->{body}) {
+ $fn .= '-' . $c->stash->{body}->id;
+ }
+ $data = decode_json(path(FixMyStreet->path_to($fn . '.json'))->slurp_utf8);
+ }
+ $c->stash($data);
+ return 1;
+ };
+
+ return $dashboard;
+}
+
sub load_and_group_problems : Private {
my ( $self, $c ) = @_;