Skip to content

Commit

Permalink
Allow cobrands to customise nearby lookup distances for duplicates
Browse files Browse the repository at this point in the history
For UK councils this is picked up from cobrand feature config.

For FD-2997.
  • Loading branch information
davea committed May 22, 2023
1 parent c07b05b commit f65a1b2
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fix RSS feed subscription from alert page button.
- Development improvements:
- Extra data columns now stored as JSON, not RABX. #3216
- Cobrands can provide custom distances for duplicate lookup.
- Changes:
- Switch to OpenStreetMap for reverse geocoding. #4444

Expand Down
8 changes: 6 additions & 2 deletions perllib/FixMyStreet/App/Controller/Report.pm
Original file line number Diff line number Diff line change
Expand Up @@ -679,10 +679,14 @@ sub _nearby_json :Private {
$c->stash->{page} = 'report';

# distance in metres
my $dist = $c->get_param('distance') || '';
my $dist;
if (my $mode = $c->get_param('mode')) {
$dist = $c->cobrand->nearby_distances->{$mode};
}
$dist ||= $c->get_param('distance') || '';
$dist = 1000 unless $dist =~ /^\d+$/;
$dist = 1000 if $dist > 1000;
$params->{distance} = $dist / 1000 unless $params->{distance};
$params->{distance} = $dist / 1000 unless $params->{distance}; # DB measures in km

my $pin_size = $c->get_param('pin_size') || '';
$pin_size = 'small' unless $pin_size =~ /^(mini|small|normal|big)$/;
Expand Down
25 changes: 25 additions & 0 deletions perllib/FixMyStreet/Cobrand/Default.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1464,4 +1464,29 @@ sub post_report_report_problem_link {
return;
}


=item nearby_distances
Specifies the distance in metres to search for nearby reports for
inspector de-duplication and report duplicate suggestions features.
Defaults to 1000m for inspectors, 250m for duplicate suggestions.
Should return a hashref of the form
{
inspector => 1000,
suggestions => 250,
}
where each key corresponds to value for the C<mode> query param passed to
/report/<id>/nearby.json or /around/nearby
=cut

sub nearby_distances { {
inspector => 1000,
suggestions => 250,
} }

1;
5 changes: 5 additions & 0 deletions perllib/FixMyStreet/Cobrand/UKCouncils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,9 @@ sub csv_staff_user_lookup {
};
}

sub nearby_distances {
my $self = shift;
return $self->feature('nearby_distances') || $self->next::method();
}

1;
46 changes: 44 additions & 2 deletions t/app/controller/around.t
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ subtest 'check assigned-only list items do not display shortlist buttons' => sub

}; # End big override_config

my $body = $mech->create_body_ok(2237, "Oxfordshire");
my $body = $mech->create_body_ok(2237, "Oxfordshire", {}, { cobrand => 'oxfordshire' });

subtest 'check category, status and extra filtering works on /around' => sub {
my $categories = [ 'Pothole', 'Vegetation', 'Flytipping' ];
Expand Down Expand Up @@ -516,12 +516,54 @@ subtest 'check map zoom level customisation' => sub {
};
};

subtest 'check nearby lookup' => sub {
subtest 'check nearby lookup, default behaviour' => sub {
my $p = FixMyStreet::DB->resultset("Problem")->search({ external_body => "Pothole-confirmed" })->first;
$mech->get_ok('/around/nearby?latitude=51.754926&longitude=-1.256179&filter_category=Pothole');
$mech->content_contains('[51.754926,-1.256179,"yellow",' . $p->id . ',"Around page Test 1 for ' . $body->id . '","small",false]');
};

subtest 'check nearby lookup, cobrand custom distances' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'oxfordshire',
MAPIT_URL => 'http://mapit.uk/',
COBRAND_FEATURES => {
nearby_distances => { oxfordshire => {
inspector => 500,
suggestions => 100,
} },
}
}, sub {

$mech->delete_problems_for_body($body->id);
my ($p) = $mech->create_problems_for_body( 1, $body->id, 'Around page', {
postcode => 'OX20 1SZ',
latitude => 51.754926,
longitude => -1.256179,
category => "Pothole",
});
for my $test (
{ lat => 51.7549, lon => -1.256, mode => undef, contains => 1}, # 12m away
{ lat => 51.752, lon => -1.256, mode => undef, contains => 1}, # 325m away
{ lat => 51.7485, lon => -1.256, mode => undef, contains => 1}, # 714m away
{ lat => 51.74, lon => -1.256, mode => undef, contains => 0}, # 1660m away

{ lat => 51.7549, lon => -1.256, mode => 'inspector', contains => 1}, # 12m away
{ lat => 51.752, lon => -1.256, mode => 'inspector', contains => 1}, # 325m away
{ lat => 51.7485, lon => -1.256, mode => 'inspector', contains => 0}, # 714m away
{ lat => 51.74, lon => -1.256, mode => 'inspector', contains => 0}, # 1660m away

{ lat => 51.7549, lon => -1.256, mode => 'suggestions', contains => 1}, # 12m away
{ lat => 51.752, lon => -1.256, mode => 'suggestions', contains => 0}, # 325m away
{ lat => 51.7485, lon => -1.256, mode => 'suggestions', contains => 0}, # 714m away
{ lat => 51.74, lon => -1.256, mode => 'suggestions', contains => 0}, # 1660m away

) {
$mech->get_ok('/around/nearby?latitude='.$test->{lat}.'&longitude='.$test->{lon}.'&filter_category=Pothole' . ( $test->{mode} ? '&mode='.$test->{mode} : ''));
$mech->contains_or_lacks($test->{contains}, '[51.754926,-1.256179,"yellow",' . $p->id . ',"Open: Around page Test 1 for ' . $body->id . '","small",false]');
}
};
};

my $he = Test::MockModule->new('HighwaysEngland');
$he->mock('_lookup_db', sub {
my ($road, $table, $thing, $thing_name) = @_;
Expand Down
1 change: 1 addition & 0 deletions templates/web/base/admin/config_page_cobrand.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h2>By feature</h2>
[% CASE 'heatmap' %] - heatmap enabled
[% CASE 'heatmap_dashboard_body' %] - anyone with council gov.uk email can access the heatmap
[% CASE 'internal_ips' %] - (TfL only) IPs that can skip 2FA
[% CASE 'nearby_distances' %] - distances to use when searching for duplicate reports
[% CASE 'noise' %] - enabling of the noise section
[% CASE 'oidc_login' %] - third party OIDC login details
[% CASE 'open311_email' %] - special additional emails to Open311 (e.g. Bexley out of hours or Bucks flytipping)
Expand Down
2 changes: 2 additions & 0 deletions templates/web/base/admin/config_page_value.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
Username: [% value.username %]
[% CASE 'govuk_notify' %]
Template ID: [% value.template_id %]
[% CASE 'nearby_distances' %]
Inspectors: [% value.inspector %]m, Suggestions: [% value.suggestions %]m
[% CASE 'oidc_login' %]
Display name: [% value.display_name %]
[% CASE 'throttle_username' %]
Expand Down
4 changes: 2 additions & 2 deletions web/js/duplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

if ( report_id ) {
nearby_url = '/report/' + report_id + '/nearby.json';
url_params.distance = 1000; // Inspectors might want to see reports fairly far away (1000 metres)
url_params.mode = 'inspector'; // Inspectors might want to see reports fairly far away (default 1000 metres)
url_params.pin_size = 'small'; // How it's always been
} else {
nearby_url = '/around/nearby';
url_params.distance = 250; // Only want to bother public with very nearby reports (250 metres)
url_params.mode = 'suggestions'; // Only want to bother public with very nearby reports (default 250 metres)
url_params.pin_size = 'normal';
}

Expand Down

0 comments on commit f65a1b2

Please sign in to comment.