diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-05-18 15:30:35 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-05-18 15:30:35 +0100 |
commit | 173abd37716cb49cde3d4836a9cf51a285bd3b79 (patch) | |
tree | 4be29d9830e00b243d6b7bfdbf410a9bfad84c64 /perllib | |
parent | d4a75fd58381f2964607a2937946202e34cb6f30 (diff) | |
parent | 1a1bfff12415a7793fee22bcd4e5e39e10dbd4d3 (diff) |
Merge branch '1286-catching-gaze'
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 7 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Gaze.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Google.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Alerts.pm | 6 |
7 files changed, 40 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 6972bbc04..ddda02abd 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use mySociety::EmailUtil qw(is_valid_email); +use FixMyStreet::Gaze; =head1 NAME @@ -441,11 +442,7 @@ sub determine_location : Private { $c->go('index'); } - my $dist = - mySociety::Gaze::get_radius_containing_population( $c->stash->{latitude}, - $c->stash->{longitude}, 200000 ); - $dist = int( $dist * 10 + 0.5 ); - $dist = $dist / 10.0; + my $dist = FixMyStreet::Gaze::get_radius_containing_population($c->stash->{latitude}, $c->stash->{longitude}); $c->stash->{population_radius} = $dist; return 1; diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 8d4f8313c..183b233a8 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -8,7 +8,7 @@ use XML::RSS; use FixMyStreet::App::Model::PhotoSet; -use mySociety::Gaze; +use FixMyStreet::Gaze; use mySociety::Locale; use mySociety::MaPit; use mySociety::Sundries qw(ordinal); @@ -143,10 +143,10 @@ sub local_problems_ll : Private { $c->stash->{qs} .= ";d=$d"; $d = 100 if $d > 100; } else { - $d = mySociety::Gaze::get_radius_containing_population( $lat, $lon, 200000 ); - $d = int( $d * 10 + 0.5 ) / 10; - mySociety::Locale::in_gb_locale { - $d = sprintf("%f", $d); + $d = FixMyStreet::Gaze::get_radius_containing_population($lat, $lon); + # Needs to be with a '.' for db passing + $d = mySociety::Locale::in_gb_locale { + sprintf("%f", $d); } } diff --git a/perllib/FixMyStreet/Gaze.pm b/perllib/FixMyStreet/Gaze.pm new file mode 100644 index 000000000..a072cd246 --- /dev/null +++ b/perllib/FixMyStreet/Gaze.pm @@ -0,0 +1,24 @@ +package FixMyStreet::Gaze; + +use strict; +use warnings; + +use mySociety::Gaze; + +sub get_radius_containing_population ($$) { + my ($lat, $lon) = @_; + + my $dist = eval { + mySociety::Locale::in_gb_locale { + mySociety::Gaze::get_radius_containing_population($lat, $lon, 200_000); + }; + }; + if ($@) { + # Error fetching from gaze, let's fall back to 10km + $dist = 10; + } + $dist = int( $dist * 10 + 0.5 ) / 10.0; + return $dist; +} + +1; diff --git a/perllib/FixMyStreet/Map.pm b/perllib/FixMyStreet/Map.pm index 81b81f656..6d641331f 100644 --- a/perllib/FixMyStreet/Map.pm +++ b/perllib/FixMyStreet/Map.pm @@ -16,7 +16,7 @@ use Module::Pluggable # Get the list of maps we want and load map classes at compile time my @ALL_MAP_CLASSES = allowed_maps(); -use mySociety::Gaze; +use FixMyStreet::Gaze; use mySociety::Locale; use Utils; @@ -105,13 +105,7 @@ sub _map_features { ? $c->cobrand->problems->around_map( @around_args, $around_limit, $category, $states ) : $around_map; - my $dist; - mySociety::Locale::in_gb_locale { - $dist = - mySociety::Gaze::get_radius_containing_population( $lat, $lon, - 200000 ); - }; - $dist = int( $dist * 10 + 0.5 ) / 10; + my $dist = FixMyStreet::Gaze::get_radius_containing_population( $lat, $lon ); my $limit = 20; my @ids = map { $_->id } @$around_map_list; diff --git a/perllib/FixMyStreet/Map/Google.pm b/perllib/FixMyStreet/Map/Google.pm index 46823f358..8ddf4f4e9 100644 --- a/perllib/FixMyStreet/Map/Google.pm +++ b/perllib/FixMyStreet/Map/Google.pm @@ -7,7 +7,7 @@ package FixMyStreet::Map::Google; use strict; -use mySociety::Gaze; +use FixMyStreet::Gaze; use Utils; use constant ZOOM_LEVELS => 6; @@ -30,7 +30,7 @@ sub display_map { # Adjust zoom level dependent upon population density my $dist = $c->stash->{distance} - || mySociety::Gaze::get_radius_containing_population( $params{latitude}, $params{longitude}, 200_000 ); + || FixMyStreet::Gaze::get_radius_containing_population( $params{latitude}, $params{longitude} ); my $default_zoom = $c->cobrand->default_map_zoom() ? $c->cobrand->default_map_zoom() : $numZoomLevels - 4; $default_zoom = $numZoomLevels - 3 if $dist < 10; diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm index 7d91a9ee7..ae9e73a0a 100644 --- a/perllib/FixMyStreet/Map/OSM.pm +++ b/perllib/FixMyStreet/Map/OSM.pm @@ -8,7 +8,7 @@ package FixMyStreet::Map::OSM; use strict; use Math::Trig; -use mySociety::Gaze; +use FixMyStreet::Gaze; use Utils; use constant ZOOM_LEVELS => 6; @@ -59,7 +59,7 @@ sub display_map { # Adjust zoom level dependent upon population density my $dist = $c->stash->{distance} - || mySociety::Gaze::get_radius_containing_population( $params{latitude}, $params{longitude}, 200_000 ); + || FixMyStreet::Gaze::get_radius_containing_population( $params{latitude}, $params{longitude} ); my $default_zoom = $c->cobrand->default_map_zoom() ? $c->cobrand->default_map_zoom() : $numZoomLevels - 4; $default_zoom = $numZoomLevels - 3 if $dist < 10; diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index e799a5446..fc5fef953 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -7,7 +7,7 @@ use DateTime::Format::Pg; use IO::String; use mySociety::DBHandle qw(dbh); -use mySociety::Gaze; +use FixMyStreet::Gaze; use mySociety::Locale; use mySociety::MaPit; use RABX; @@ -175,10 +175,10 @@ sub send() { my $longitude = $alert->parameter; my $latitude = $alert->parameter2; - my $d = mySociety::Gaze::get_radius_containing_population($latitude, $longitude, 200000); + my $d = FixMyStreet::Gaze::get_radius_containing_population($latitude, $longitude); # Convert integer to GB locale string (with a ".") $d = mySociety::Locale::in_gb_locale { - sprintf("%f", int($d*10+0.5)/10); + sprintf("%f", $d); }; my $states = "'" . join( "', '", FixMyStreet::DB::Result::Problem::visible_states() ) . "'"; my %data = ( |