Skip to content

Commit

Permalink
[Bexley] Ignore duplicate log entries from Whitespace
Browse files Browse the repository at this point in the history
Sometimes Whitespace will return identical logs which only differ by a
few seconds, but have different IDs. We want to ignore these as they
don't give us any extra information and look confusing when displayed to
the user.
  • Loading branch information
chrismytton committed Jan 7, 2025
1 parent 583a4f6 commit 316359b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
8 changes: 8 additions & 0 deletions perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ sub _in_cab_logs {
my @property_logs;
my @street_logs;
my %completed_or_attempted_collections;
my %seen_logs;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L631 was not covered by tests

return ( \@property_logs, \@street_logs, \%completed_or_attempted_collections )
unless $cab_logs;
Expand All @@ -646,6 +647,13 @@ sub _in_cab_logs {
# Gather property-level and street-level exceptions
if ( $_->{Reason} && $_->{Reason} ne 'N/A' ) {
if ( $_->{Uprn} && $_->{Uprn} eq $property->{uprn} ) {
# Create a unique key for this log entry based on the actual event details
# using just the date portion of LogDate since multiple logs for the same
# event might have different timestamps on the same day
my $date_only = $logdate->ymd;
my $log_key = join(':', $_->{Reason}, $_->{RoundCode}, $date_only);

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

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L653-L654

Added lines #L653 - L654 were not covered by tests
next if $seen_logs{$log_key}++;

push @property_logs, {
uprn => $_->{Uprn},
round => $_->{RoundCode},
Expand Down
68 changes: 68 additions & 0 deletions t/app/controller/waste_bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,74 @@ FixMyStreet::override_config {
set_fixed_time('2024-03-31T02:00:00'); # March 31st, 02:00 BST
};

subtest 'Deduplication of in-cab logs' => sub {
$whitespace_mock->mock('GetInCabLogsByUsrn', sub {
return [
# Two logs with same reason, round code and date but different times
{
LogID => 1,
Reason => 'Refuse - Not Out',
RoundCode => 'RES-R3',
LogDate => '2024-04-01T10:02:15.7',
Uprn => '10001',
Usrn => '321',
},
{
LogID => 2,
Reason => 'Refuse - Not Out',
RoundCode => 'RES-R3',
LogDate => '2024-04-01T10:05:20.1',
Uprn => '10001',
Usrn => '321',
},
# Different date, should be included
{
LogID => 3,
Reason => 'Refuse - Not Out',
RoundCode => 'RES-R3',
LogDate => '2024-04-02T10:02:15.7',
Uprn => '10001',
Usrn => '321',
},
# Different reason, should be included
{
LogID => 4,
Reason => 'Food - Not Out',
RoundCode => 'RES-R3',
LogDate => '2024-04-01T10:02:15.7',
Uprn => '10001',
Usrn => '321',
},
# Different round code, should be included
{
LogID => 5,
Reason => 'Refuse - Not Out',
RoundCode => 'RES-R4',
LogDate => '2024-04-01T10:02:15.7',
Uprn => '10001',
Usrn => '321',
},
];
});

set_fixed_time('2024-04-03T12:00:00');
$mech->get_ok('/waste/10001');
$mech->content_contains('Service status');
$mech->content_contains('Our collection teams have reported the following problems with your bins:');

# Count occurrences of each type of message
my $content = $mech->content;
my $refuse_not_out_count = () = $content =~ /Refuse - Not Out/g;
my $food_not_out_count = () = $content =~ /Food - Not Out/g;

is($refuse_not_out_count, 3, "Shows three 'Refuse - Not Out' messages (two different dates, one different round)");
is($food_not_out_count, 1, "Shows one 'Food - Not Out' message");

# Reset mock and time
default_mocks();
set_fixed_time('2024-03-31T01:00:00');
};

subtest 'Missed enquiry form for properties with no collections' => sub {
$mech->delete_problems_for_body( $body->id );

Expand Down

0 comments on commit 316359b

Please sign in to comment.