diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 4 | ||||
-rw-r--r-- | perllib/Open311.pm | 26 |
2 files changed, 25 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 46891f906..1a5682dad 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -5,6 +5,7 @@ use strict; use JSON::MaybeXS; use mySociety::MaPit; use mySociety::VotingArea; +use Utils; sub country { return 'GB'; } sub area_types { [ 'DIS', 'LBO', 'MTD', 'UTA', 'CTY', 'COI', 'LGD' ] } @@ -122,7 +123,8 @@ sub find_closest { my $data = $self->SUPER::find_closest($problem, $as_data); my $mapit_url = FixMyStreet->config('MAPIT_URL'); - my $url = $mapit_url . "nearest/4326/" . $problem->longitude . ',' . $problem->latitude; + my ($lat, $lon) = map { Utils::truncate_coordinate($_) } $problem->latitude, $problem->longitude; + my $url = $mapit_url . "nearest/4326/$lon,$lat"; my $j = LWP::Simple::get($url); if ($j) { $j = JSON->new->utf8->allow_nonref->decode($j); diff --git a/perllib/Open311.pm b/perllib/Open311.pm index c1323acfa..b52cee0ea 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -59,6 +59,24 @@ sub get_service_meta_info { return $self->_get_xml_object( $service_meta_xml ); } +sub to_bristol { + my $problem = shift; + return unless $problem->cobrand =~ /fixmystreet|bristol/; + my $bodies = $problem->bodies; + return unless %$bodies; + my $body = (values %$bodies)[0]; + return unless $body->areas->{2561}; + return 1; +} + +sub warn_failure { + my ($obj, $problem) = @_; + # Special case a poorly behaving Open311 server + my $threshold = 1; + $threshold = 5 if to_bristol($problem || $obj); + return $obj->send_fail_count && $obj->send_fail_count == $threshold; +} + sub send_service_request { my $self = shift; my $problem = shift; @@ -83,10 +101,10 @@ sub send_service_request { } warn sprintf( "Failed to submit problem %s over Open311, response\n: %s\n%s", $problem->id, $response, $self->debug_details ) - if $problem->send_fail_count && $problem->send_fail_count == 2; + if warn_failure($problem); } else { warn sprintf( "Failed to submit problem %s over Open311, details:\n%s", $problem->id, $self->error) - if $problem->send_fail_count && $problem->send_fail_count == 2; + if warn_failure($problem); } return 0; } @@ -259,10 +277,10 @@ sub post_service_request_update { } warn sprintf( "Failed to submit comment %s over Open311, response - %s\n%s\n", $comment->id, $response, $self->debug_details ) - if $comment->send_fail_count && $comment->send_fail_count == 2; + if warn_failure($comment, $comment->problem); } else { warn sprintf( "Failed to submit comment %s over Open311, details\n%s\n", $comment->id, $self->error) - if $comment->send_fail_count && $comment->send_fail_count == 2; + if warn_failure($comment, $comment->problem); } return 0; } |