aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-05-18 15:30:35 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-05-18 15:30:35 +0100
commit173abd37716cb49cde3d4836a9cf51a285bd3b79 (patch)
tree4be29d9830e00b243d6b7bfdbf410a9bfad84c64
parentd4a75fd58381f2964607a2937946202e34cb6f30 (diff)
parent1a1bfff12415a7793fee22bcd4e5e39e10dbd4d3 (diff)
Merge branch '1286-catching-gaze'
-rw-r--r--conf/general.yml-example2
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm7
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Rss.pm10
-rw-r--r--perllib/FixMyStreet/Gaze.pm24
-rw-r--r--perllib/FixMyStreet/Map.pm10
-rw-r--r--perllib/FixMyStreet/Map/Google.pm4
-rw-r--r--perllib/FixMyStreet/Map/OSM.pm4
-rw-r--r--perllib/FixMyStreet/Script/Alerts.pm6
-rw-r--r--t/app/load_general_config.t5
-rw-r--r--t/fixmystreet.t6
10 files changed, 46 insertions, 32 deletions
diff --git a/conf/general.yml-example b/conf/general.yml-example
index 097d81b19..749b9e716 100644
--- a/conf/general.yml-example
+++ b/conf/general.yml-example
@@ -180,7 +180,7 @@ SMTP_PASSWORD: ''
# Gaze is a world-wide service for population density lookups. You can leave
# this as is.
-GAZE_URL: 'http://gaze.mysociety.org/gaze'
+GAZE_URL: 'https://gaze.mysociety.org/gaze'
# Should problem reports link to the council summary pages?
AREA_LINKS_FROM_PROBLEMS: '0'
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 = (
diff --git a/t/app/load_general_config.t b/t/app/load_general_config.t
index 1051aac3f..16ca2fc54 100644
--- a/t/app/load_general_config.t
+++ b/t/app/load_general_config.t
@@ -5,7 +5,6 @@ use Test::More tests => 2;
use_ok 'FixMyStreet::App';
-# GAZE_URL chosen as it is unlikely to change
-is FixMyStreet::App->config->{GAZE_URL}, #
- 'http://gaze.mysociety.org/gaze', #
+is FixMyStreet::App->config->{GAZE_URL},
+ 'https://gaze.mysociety.org/gaze',
"check that known config param is loaded";
diff --git a/t/fixmystreet.t b/t/fixmystreet.t
index d7f00b047..a601c10d5 100644
--- a/t/fixmystreet.t
+++ b/t/fixmystreet.t
@@ -18,17 +18,17 @@ is "$path_to_path", $file_path, "got $file_path";
# check that the config gets loaded and is immutable
my $config = FixMyStreet->config;
isa_ok $config, 'HASH';
-is $config->{GAZE_URL}, 'http://gaze.mysociety.org/gaze',
+is $config->{GAZE_URL}, 'https://gaze.mysociety.org/gaze',
"got GAZE_URL correctly";
throws_ok(
sub { $config->{GAZE_URL} = 'some other value'; },
qr/Modification of a read-only value attempted/,
'attempt to change config caught'
);
-is $config->{GAZE_URL}, 'http://gaze.mysociety.org/gaze', "GAZE_URL unchanged";
+is $config->{GAZE_URL}, 'https://gaze.mysociety.org/gaze', "GAZE_URL unchanged";
# check that we can get the value by key as well
-is FixMyStreet->config('GAZE_URL'), 'http://gaze.mysociety.org/gaze',
+is FixMyStreet->config('GAZE_URL'), 'https://gaze.mysociety.org/gaze',
"GAZE_URL correct when got by key";
is FixMyStreet->config('BAD_KEY_DOES_NOT_EXIST'), undef, "config miss is undef";