Skip to content

Commit

Permalink
fixup! fixup! [Bexley][WW] Fetch successful collections alongside oth…
Browse files Browse the repository at this point in the history
…er in-cab logs
  • Loading branch information
nephila-nacrea committed May 28, 2024
1 parent d0cd1c4 commit 8dcc334
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 41 deletions.
80 changes: 39 additions & 41 deletions perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@ sub bin_services_for_address {
= $self->_missed_collection_reports($property);
$property->{recent_collections} = $self->_recent_collections($property);

my ( $property_logs, $street_logs, $successful_collection_logs )
my ( $property_logs, $street_logs, $successful_collections )

Check warning on line 212 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L212

Added line #L212 was not covered by tests
= $self->_in_cab_logs($property);
$property->{successful_collections}
= { map { $_->{round} => $_->{date} } @$successful_collection_logs };
$property->{successful_collections} = $successful_collections;

Check warning on line 214 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L214

Added line #L214 was not covered by tests
$property->{red_tags} = $property_logs;
$property->{service_updates} = grep { $_->{service_update} } @$street_logs;

Expand Down Expand Up @@ -518,46 +517,46 @@ sub _in_cab_logs {

my @property_logs;
my @street_logs;
my @successful_collection_logs;
my %successful_collections;

Check warning on line 520 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L520

Added line #L520 was not covered by tests

return ( \@property_logs, \@street_logs, \@successful_collection_logs )
return ( \@property_logs, \@street_logs, \%successful_collections )
unless $cab_logs;

for (@$cab_logs) {
my $logdate = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%S' )->parse_datetime( $_->{LogDate} );

# Successful collection log should:
# not have a reason
# AND
# should have property's UPRN OR no URPN
if (
( !$_->{Reason} || $_->{Reason} eq 'N/A')
&& ( !$_->{Uprn} || $_->{Uprn} eq $property->{uprn} )
) {
push @successful_collection_logs, {
round => $_->{RoundCode},
date => $logdate,
};
} elsif ( $_->{Uprn} && $_->{Uprn} eq $property->{uprn} ) {
push @property_logs, {
uprn => $_->{Uprn},
round => $_->{RoundCode},
reason => $_->{Reason},
date => $logdate,
ordinal => ordinal( $logdate->day ),
};
} else {
push @street_logs, {
service_update => $_->{Uprn} ? 0 : 1,
round => $_->{RoundCode},
reason => $_->{Reason},
date => $logdate,
ordinal => ordinal( $logdate->day ),
};
# There aren't necessarily round completion logs; the presence of any
# log against a round code should be taken as a sign that the round
# has been completed or at least attempted for the property.
# Overwrite entry for given round if a later logdate is found.
$successful_collections{ $_->{RoundCode} } = $logdate
if !$successful_collections{ $_->{RoundCode} }
|| $successful_collections{ $_->{RoundCode} } < $logdate;

# Gather property-level and street-level exceptions
if ( $_->{Reason} && $_->{Reason} ne 'N/A' ) {
if ( $_->{Uprn} && $_->{Uprn} eq $property->{uprn} ) {
push @property_logs, {
uprn => $_->{Uprn},
round => $_->{RoundCode},
reason => $_->{Reason},
date => $logdate,

Check warning on line 543 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L543

Added line #L543 was not covered by tests
ordinal => ordinal( $logdate->day ),
};
} else {
push @street_logs, {
# TODO This shouldn't be needed
service_update => $_->{Uprn} ? 0 : 1,
round => $_->{RoundCode},
reason => $_->{Reason},
date => $logdate,
ordinal => ordinal( $logdate->day ),
};
}
}
}

return ( \@property_logs, \@street_logs, \@successful_collection_logs );
return ( \@property_logs, \@street_logs, \%successful_collections );

Check warning on line 559 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L559

Added line #L559 was not covered by tests
}

sub can_report_missed {
Expand All @@ -583,15 +582,14 @@ sub can_report_missed {
if ($last_expected_collection_dt) {
# TODO We can probably get successful collections directly off the
# property rather than query _in_cab_logs again
my ( undef, undef, $successful_collection_logs )
my ( undef, undef, $successful_collections )

Check warning on line 585 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L585

Added line #L585 was not covered by tests
= $self->_in_cab_logs($property);

# If there is a log for this collection, that is when
# the round was completed so we can make a report if
# we're within that time
my ($log_for_round)
= grep { $_->{round} eq $service->{round} }
@$successful_collection_logs;
my $logged_time_for_round
= $successful_collections->{ $service->{round} };

Check warning on line 592 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L592

Added line #L592 was not covered by tests

# log time needs to be greater than or equal to 3 working days ago,
# less than today
Expand All @@ -606,9 +604,9 @@ sub can_report_missed {
# fortnightly, but they share a round code prefix.
return 0 if $last_expected_collection_dt < $min_dt && !$service->{next}{is_today};

return ( $log_for_round->{date} < $now_dt
&& $log_for_round->{date} >= $min_dt ) ? 1 : 0
if $log_for_round;
return ( $logged_time_for_round < $now_dt
&& $logged_time_for_round >= $min_dt ) ? 1 : 0
if $logged_time_for_round;

$service->{last}{is_delayed} =
($last_expected_collection_dt < $today_dt && $last_expected_collection_dt >= $min_dt)
Expand Down
45 changes: 45 additions & 0 deletions t/app/controller/waste_bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,51 @@ FixMyStreet::override_config {
];
});
$mech->get_ok('/waste/10001');
$mech->content_lacks(
'Our collection teams have reported the following problems with your bins:'
);
$mech->content_lacks('Being collected today');
$mech->content_contains('Collection completed or attempted earlier today');

# Property has red tag on collection attempted earlier today
$whitespace_mock->mock( 'GetInCabLogsByUprn', sub {
return [
{
LogID => 1,
Reason => 'Bin has gone feral',
RoundCode => 'RND-8-9',
LogDate => '2024-04-01T12:00:00.417',
Uprn => '10001',
Usrn => '321',
},
];
});
$whitespace_mock->mock( 'GetInCabLogsByUsrn', sub { [] } );
$mech->get_ok('/waste/10001');
$mech->content_contains(
'Our collection teams have reported the following problems with your bins:'
);
$mech->content_lacks('Being collected today');
$mech->content_contains('Collection completed or attempted earlier today');

# Red tag on other property on same street
$whitespace_mock->mock( 'GetInCabLogsByUprn', sub { [] } );
$whitespace_mock->mock( 'GetInCabLogsByUsrn', sub {
return [
{
LogID => 1,
Reason => 'Bin has gone feral',
RoundCode => 'RND-8-9',
LogDate => '2024-04-01T12:00:00.417',
Uprn => '19991',
Usrn => '321',
},
];
});
$mech->get_ok('/waste/10001');
$mech->content_lacks(
'Our collection teams have reported the following problems with your bins:'
);
$mech->content_lacks('Being collected today');
$mech->content_contains('Collection completed or attempted earlier today');

Expand Down

0 comments on commit 8dcc334

Please sign in to comment.