From 26cf0b7a11fed1ee1f9cc3042ce77534e0528d77 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Thu, 30 Nov 2023 22:27:54 +0000 Subject: [PATCH] [Northumberland] Add response time to CSV export For FD-3351 --- perllib/FixMyStreet/Cobrand/Northumberland.pm | 19 +++++++++++++++++++ perllib/FixMyStreet/Reporting.pm | 2 +- perllib/FixMyStreet/Script/CSVExport.pm | 2 +- t/cobrand/northumberland.t | 12 +++++++++--- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/perllib/FixMyStreet/Cobrand/Northumberland.pm b/perllib/FixMyStreet/Cobrand/Northumberland.pm index 2ded762c54f..cadaab76f08 100644 --- a/perllib/FixMyStreet/Cobrand/Northumberland.pm +++ b/perllib/FixMyStreet/Cobrand/Northumberland.pm @@ -4,6 +4,9 @@ use base 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; +use DateTime::Format::W3CDTF; +use Utils; + use Moo; with 'FixMyStreet::Roles::Open311Alloy'; @@ -83,13 +86,26 @@ sub dashboard_export_problems_add_columns { staff_user => 'Staff User', staff_role => 'Staff Role', assigned_to => 'Assigned To', + response_time => 'Response Time', ); + my $response_time = sub { + my $hashref = shift; + if (my $response = ($hashref->{fixed} || $hashref->{closed}) ) { + $response = DateTime::Format::W3CDTF->parse_datetime($response)->epoch; + my $confirmed = DateTime::Format::W3CDTF->parse_datetime($hashref->{confirmed})->epoch; + return Utils::prettify_duration($response - $confirmed, 'minute'); + } + return ''; + }; + if ($csv->dbi) { $csv->csv_extra_data(sub { my $report = shift; + my $hashref = shift; return { user_name_display => $report->{name}, + response_time => $response_time->($hashref), }; }); return; # Rest already covered @@ -101,6 +117,7 @@ sub dashboard_export_problems_add_columns { $csv->csv_extra_data(sub { my $report = shift; + my $hashref = shift; my $by = $report->get_extra_metadata('contributed_by'); my $staff_user = ''; @@ -110,11 +127,13 @@ sub dashboard_export_problems_add_columns { $staff_user = $self->csv_staff_user_lookup($by, $user_lookup); $staff_role = join(',', @{$userroles->{$by} || []}); } + return { user_name_display => $report->name, staff_user => $staff_user, staff_role => $staff_role, assigned_to => $problems_to_user->{$report->id} || '', + response_time => $response_time->($hashref), }; }); } diff --git a/perllib/FixMyStreet/Reporting.pm b/perllib/FixMyStreet/Reporting.pm index 5807286164e..db58992b2fa 100644 --- a/perllib/FixMyStreet/Reporting.pm +++ b/perllib/FixMyStreet/Reporting.pm @@ -338,7 +338,7 @@ sub generate_csv { $hashref->{reported_as} = $obj->get_extra_metadata('contributed_as') || ''; if (my $fn = $self->csv_extra_data) { - my $extra = $fn->($obj); + my $extra = $fn->($obj, $hashref); $hashref = { %$hashref, %$extra }; } diff --git a/perllib/FixMyStreet/Script/CSVExport.pm b/perllib/FixMyStreet/Script/CSVExport.pm index d357de1a887..172a8411b36 100644 --- a/perllib/FixMyStreet/Script/CSVExport.pm +++ b/perllib/FixMyStreet/Script/CSVExport.pm @@ -147,7 +147,7 @@ sub process_body { } process_comment($hashref, $obj); if (my $fn = $reporting->csv_extra_data) { - my $extra = $fn->($obj); + my $extra = $fn->($obj, $hashref); $hashref = { %$hashref, %$extra }; } } diff --git a/t/cobrand/northumberland.t b/t/cobrand/northumberland.t index d300ded4a71..a71770a8caa 100644 --- a/t/cobrand/northumberland.t +++ b/t/cobrand/northumberland.t @@ -17,6 +17,12 @@ my ($problem1, $problem2) = $mech->create_problems_for_body(2, $body->id, 'Test' anonymous => 't', extra => { contributed_by => $staffuser->id }, }); +$problem2->update({ state => 'fixed - council' }); +my ($update) = $mech->create_comment_for_problem( + $problem2, $staffuser, 'Title', 'text', 0, 'confirmed', 'fixed', + { confirmed => $problem2->confirmed->add(days => 1, hours => 3, minutes => 37) } +); + my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); FixMyStreet::override_config { @@ -28,20 +34,20 @@ FixMyStreet::override_config { $mech->log_in_ok( $staffuser->email ); $mech->get_ok('/dashboard?export=1'); $mech->content_contains('Test User', 'name of anonymous user'); - $mech->content_like(qr{counciluser\@example.com,"Role 1",$}, 'staff user, role, and unassigned'); + $mech->content_like(qr{counciluser\@example.com,"Role 1",,"1 day, 3 hours, 37 minutes"$}, 'staff user, role, unassigned, and response time'); $staffuser->add_to_planned_reports($problem1); $staffuser->add_to_planned_reports($problem2); $mech->get_ok('/dashboard?export=1'); my $id1 = $problem1->id; my $id2 = $problem2->id; $mech->content_like(qr{/report/$id1,.*?,"Role 1","Council User"}, 'staff user, role, and assigned to'); - $mech->content_like(qr{/report/$id2,.*?,"Role 1","Council User"}, 'staff user, role, and assigned to'); + $mech->content_like(qr{/report/$id2,.*?,"Role 1","Council User","1 day, 3 hours, 37 minutes"}, 'staff user, role, assigned to, and response time'); FixMyStreet::Script::CSVExport::process(dbh => FixMyStreet::DB->schema->storage->dbh); $mech->get_ok('/dashboard?export=1'); $mech->content_contains('Test User', 'name of anonymous user'); $mech->content_like(qr{/report/$id1,.*?,"Role 1","Council User"}, 'staff user, role, and assigned to'); - $mech->content_like(qr{/report/$id2,.*?,"Role 1","Council User"}, 'staff user, role, and assigned to'); + $mech->content_like(qr{/report/$id2,.*?,"Role 1","Council User","1 day, 3 hours, 37 minutes"}, 'staff user, role, assigned to, and response time'); }; subtest 'Staff OOH shown on National Highways roads' => sub {