Skip to content

Commit

Permalink
[Northumberland] Add response time to CSV export
Browse files Browse the repository at this point in the history
  • Loading branch information
davea committed Dec 13, 2023
1 parent 999621a commit 26cf0b7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
19 changes: 19 additions & 0 deletions perllib/FixMyStreet/Cobrand/Northumberland.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand All @@ -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 = '';
Expand All @@ -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),
};
});
}
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Reporting.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Script/CSVExport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
Expand Down
12 changes: 9 additions & 3 deletions t/cobrand/northumberland.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 26cf0b7

Please sign in to comment.