aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/import-flickr14
-rwxr-xr-xbin/send-reports46
-rwxr-xr-xbin/test-run79
-rwxr-xr-xbin/update-areas4
4 files changed, 105 insertions, 38 deletions
diff --git a/bin/import-flickr b/bin/import-flickr
index 992a6ac8e..21ea5822a 100755
--- a/bin/import-flickr
+++ b/bin/import-flickr
@@ -72,19 +72,19 @@ while ($result =~ /<photo id="([^"]*)" owner="([^"]*)" secret="([^"]*)" server="
sub problem_create {
my ($photo_id, $owner, $title, $lat, $lon, $image) = @_;
my ($name, $email) = dbh()->selectrow_array("select name, email from partial_user where service='flickr' and nsid=?", {}, $owner);
- my ($easting, $northing) = (0,0);
+
+ # set some defaults
$name ||= '';
- if ($lat && $lon) {
- # XXX This appears to be going wrong :(
- ($easting, $northing) = mySociety::GeoUtil::wgs84_to_national_grid($lat, $lon, 'G');
- }
+ $lat ||= 0;
+ $lon ||= 0;
+
my $id = dbh()->selectrow_array("select nextval('problem_id_seq')");
Utils::workaround_pg_bytea("insert into problem
- (id, postcode, easting, northing, title, detail, name,
+ (id, postcode, latitude, longitude, title, detail, name,
email, phone, photo, state, used_map, anonymous, category, areas)
values
(?, '', ?, ?, ?, '', ?, ?, '', ?, 'partial', 't', 'f', '', '')", 7,
- $id, $easting, $northing, $title, $name, $email, $image
+ $id, $latitude, $longitude, $title, $name, $email, $image
);
dbh()->do('insert into flickr_imported (id, problem_id) values (?, ?)', {}, $photo_id, $id);
diff --git a/bin/send-reports b/bin/send-reports
index 9da9b6238..6254337c6 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -27,6 +27,7 @@ use mySociety::Config;
use mySociety::DBHandle qw(dbh);
use mySociety::Email;
use mySociety::EmailUtil;
+use mySociety::GeoUtil;
use mySociety::Locale;
use mySociety::MaPit;
use mySociety::Random qw(random_bytes);
@@ -49,10 +50,12 @@ my $base_url = mySociety::Config::get('BASE_URL');
my $site = CronFns::site($base_url);
my $query = "SELECT id, council, category, title, detail, name, email, phone,
- used_map, easting, northing, (photo is not null) as has_photo, lang,
+ used_map, latitude, longitude, (photo is not null) as has_photo, lang,
cobrand, cobrand_data
- FROM problem WHERE state in ('confirmed','fixed') AND whensent IS NULL
- AND council IS NOT NULL";
+ FROM problem
+ WHERE state in ('confirmed','fixed')
+ AND whensent IS NULL
+ AND council IS NOT NULL";
my $unsent = dbh()->selectall_arrayref($query, { Slice => {} });
my (%notgot, %note);
@@ -81,7 +84,7 @@ foreach my $row (@$unsent) {
# Template variables for the email
my $email_base_url = Cobrand::base_url_for_emails($cobrand, $cobrand_data);
- my %h = map { $_ => $row->{$_} } qw/title detail name email phone category easting northing/;
+ my %h = map { $_ => $row->{$_} } qw/title detail name email phone category latitude longitude/;
$h{url} = $email_base_url . '/report/' . $row->{id};
$h{phone_line} = $h{phone} ? _('Phone:') . " $h{phone}\n\n" : '';
if ($row->{has_photo}) {
@@ -95,6 +98,21 @@ foreach my $row (@$unsent) {
: _('The user could not locate the problem on a map, but to see the area around the location they entered');
$h{closest_address} = '';
$h{closest_address_machine} = '';
+
+ # If we are in the UK include eastings and northings
+ $h{easting_northing} = '';
+ if ( mySociety::Config::get('COUNTRY') eq 'GB' ) {
+
+ ( $h{easting}, $h{northing} ) =
+ mySociety::GeoUtil::wgs84_to_national_grid( #
+ $h{latitude}, $h{longitude}, 'G'
+ );
+
+ # email templates don't have conditionals so we need to farmat this here
+ $h{easting_northing} #
+ = "Easting: $h{easting}\n\n" #
+ . "Northing: $h{northing}\n\n";
+ }
my (@to, @recips, $template, $areas_info);
if ($site eq 'emptyhomes') {
@@ -137,8 +155,8 @@ foreach my $row (@$unsent) {
my ($council_email, $confirmed, $note) = dbh()->selectrow_array(
"SELECT email,confirmed,note FROM contacts WHERE deleted='f'
and area_id=? AND category=?", {}, $council, $row->{category});
- $council_email = essex_contact($row->{easting}, $row->{northing}) if $council == 2225;
- $council_email = oxfordshire_contact($row->{easting}, $row->{northing}) if $council == 2237 && $council_email eq 'SPECIAL';
+ $council_email = essex_contact($row->{latitude}, $row->{longitude}) if $council == 2225;
+ $council_email = oxfordshire_contact($row->{latitude}, $row->{longitude}) if $council == 2237 && $council_email eq 'SPECIAL';
unless ($confirmed) {
$all_confirmed = 0;
$note = 'Council ' . $row->{council} . ' deleted'
@@ -255,13 +273,19 @@ if ($verbose) {
}
}
+sub _get_district_for_contact {
+ my ( $lat, $lon ) = @_;
+ my $district =
+ mySociety::MaPit::call( 'point', "4326/$lon,$lat", type => 'DIS' );
+ ($district) = keys %$district;
+ return $district;
+}
+
# Essex has different contact addresses depending upon the district
# Might be easier if we start storing in the db all areas covered by a point
# Will do for now :)
sub essex_contact {
- my ($E, $N) = @_;
- my $district = mySociety::MaPit::call('point', "27700/$E,$N", type => 'DIS');
- ($district) = keys %$district;
+ my $district = _get_district_for_contact(@_);
my $email;
$email = 'eastarea' if $district == 2315 || $district == 2312;
$email = 'midarea' if $district == 2317 || $district == 2314 || $district == 2316;
@@ -273,9 +297,7 @@ sub essex_contact {
# Oxfordshire has different contact addresses depending upon the district
sub oxfordshire_contact {
- my ($E, $N) = @_;
- my $district = mySociety::MaPit::call('point', "27700/$E,$N", type => 'DIS');
- ($district) = keys %$district;
+ my $district = _get_district_for_contact(@_);
my $email;
$email = 'northernarea' if $district == 2419 || $district == 2420 || $district == 2421;
$email = 'southernarea' if $district == 2417 || $district == 2418;
diff --git a/bin/test-run b/bin/test-run
index 15f9c3ed2..b2fea2fb5 100755
--- a/bin/test-run
+++ b/bin/test-run
@@ -27,11 +27,14 @@ use FindBin;
use mySociety::Config;
mySociety::Config::set_file('../conf/general');
use mySociety::DBHandle qw(dbh);
+use mySociety::GeoUtil;
use mySociety::WebTestHarness;
use Test::Harness;
use File::Find;
use lib "$FindBin::Bin/../perllib";
use Cobrand;
+use FixMyStreet::Geocode;
+use Utils;
my @actions = ('report', 'update', 'questionnaire', 'alert', 'static', 'cobrand', 'unit', 'eha_alert', 'import', 'rss');
my %actions_desc = (
@@ -213,6 +216,11 @@ sub submit_postcode{
sub submit_report {
my ($postcode, $x, $y, $easting, $northing, $user_num, $council, $texts, $cobrand ) = @_;
my @messages = @{$texts};
+
+ # convert easting, northing to lat lon
+ my ( $latitude, $longitude ) =
+ Utils::convert_en_to_latlon( $easting, $northing );
+
submit_postcode($cobrand, $postcode, $messages[0]);
{
# Writing values to hidden fields, so switching
@@ -235,8 +243,8 @@ sub submit_report {
y => $y,
pc => $postcode,
council => -1,
- easting => $easting,
- northing => $northing,
+ latitude => $latitude,
+ longitude => $longitude,
title => 'My test problem',
detail => 'Detail of my test problem',
anonymous => 1,
@@ -377,13 +385,23 @@ sub do_alert {
# sign up for alerts in an area
my $postcode = 'EH1 2NG';
- my $x = 2015; my $e = 325066;
- my $y = 4175; my $n = 673533;
+
+ my $x = 2015;
+ my $y = 4175;
+
+ my $e = 325066;
+ my $n = 673533;
+
+ # get the lat,lon from the postcode so that it matches
+ my ( $lat, $lon ) =
+ map { Utils::truncate_coordinate($_) }
+ FixMyStreet::Geocode::lookup( $postcode, undef );
+
my $messages = english_fms_messages();
submit_postcode('', $postcode, 'Problems in this area');
$wth->browser_follow_link(text => 'Email me new local problems');
$wth->browser_submit_form(form_name => 'alerts',
- fields => {feed => "local:" . $e . ":" . $n,
+ fields => {feed => "local:$lat:$lon",
rznvy => email_n(2)} );
$wth->browser_check_contents('Nearly Done!');
my $confirmation_email = $wth->email_get_containing(
@@ -396,7 +414,7 @@ sub do_alert {
$wth->browser_check_contents('successfully confirmed your alert');
# create and confirm a new problem in the area
- submit_report($postcode, $x, $y, 325000, 673387.096774193, 3, undef, $messages, '');
+ submit_report($postcode, $x, $y, $e, $n, 3, undef, $messages, '');
# run the alert script
call_send_emails();
@@ -419,6 +437,12 @@ sub do_eha_alert {
my $postcode = 'EH1 2NG';
my $x = 2015; my $e = 325066;
my $y = 4175; my $n = 673533;
+
+ # get the lat,lon from the postcode so that it matches
+ my ( $lat, $lon ) =
+ map { Utils::truncate_coordinate($_) }
+ FixMyStreet::Geocode::lookup( $postcode, undef );
+
my @texts = ('Eiddo gwag yn yr ardal hon',
'Adrodd am eiddo gwag',
'Nawr, gwiriwch eich e-bost',
@@ -428,7 +452,7 @@ sub do_eha_alert {
submit_postcode('cy.emptyhomes.', $postcode, $texts[0]);
$wth->browser_follow_link(text => 'Anfonwch fanylion eiddo gwag lleol newydd ataf i drwy\'r e-bost');
$wth->browser_submit_form(form_name => 'alerts',
- fields => {feed => "local:" . $e . ":" . $n,
+ fields => {feed => "local:$lat:$lon",
rznvy => email_n(4)} );
$wth->browser_check_contents($texts[2]);
my $confirmation_email = $wth->email_get_containing(
@@ -441,7 +465,7 @@ sub do_eha_alert {
$wth->browser_check_contents('Rydych wedi cadarnhau\'ch hysbysiad yn llwyddiannus.');
# create and confirm a new problem in the area
- submit_report($postcode, $x, $y, 325000, 673387.096774193, 3, undef, \@texts, 'cy.emptyhomes.');
+ submit_report($postcode, $x, $y, $e, $n, 3, undef, \@texts, 'cy.emptyhomes.');
# run the alert script
call_send_emails();
@@ -513,16 +537,37 @@ sub do_static {
# Check RSS feeds redirect to the right places and so on.
# Just checks header, doesn't check any contents.
sub do_rss {
- $wth->browser_get($base_url . '/rss/l/52.5/-1.9');
- die "Lat/lon redirect failed" unless $wth->browser_uri() =~ m{/rss/n/406886,289126$};
- $wth->browser_get($base_url . '/rss/2524/1779');
- die "Tile redirect failed" unless $wth->browser_uri() =~ m{/rss/n/407097,286935$};
- $wth->browser_get($base_url . '/rss/n/407097,286935');
+
+ my %redirects = (
+
+ # should always go to lat lon
+ '/rss/n/406886,289126' => '/rss/l/52.499994,-1.899993',
+ '/rss/2524/1779' => '/rss/l/52.480294,-1.896931',
+ '/rss/pc/SW1A1AA' => '/rss/l/51.50101,-0.141587',
+ '/rss/l/52.5/-1.9' => '/rss/l/52.5/-1.9',
+
+ # go to reports
+ '/rss/area/Birmingham' => '/rss/reports/Birmingham',
+ '/rss/area/Birmingham/Lozells' => '/rss/reports/Birmingham/Lozells',
+ );
+
+ my $error_count = 0;
+ foreach my $from ( sort keys %redirects ) {
+ my $to = $redirects{$from};
+ $wth->browser_get( $base_url . $from );
+ my ($got) = $wth->browser_uri() =~ m{(/rss/.*)$};
+
+ next if $got eq $to;
+
+ warn "RSS redirect from '$from' to '$to' failed - got '$got'";
+ $error_count++;
+ }
+
+ die "Found errors doing redirect - aborting" if $error_count;
+
+ $wth->browser_get($base_url . '/rss/l/52.5/-1.94');
$wth->browser_check_contents('New local problems on FixMyStreet');
- $wth->browser_get($base_url . '/rss/pc/SW1A1AA');
- die "Postcode redirect failed" unless $wth->browser_uri() =~ m{/rss/n/529090,179645$};
- $wth->browser_get($base_url . '/rss/area/Birmingham');
- die "One-tier redirect failed" unless $wth->browser_uri() =~ m{/rss/reports/Birmingham$};
+
$wth->browser_get($base_url . '/rss/reports/Birmingham');
$wth->browser_check_contents('New problems to Birmingham City Council on FixMyStreet');
$wth->browser_get($base_url . '/rss/reports/Birmingham/Lozells');
diff --git a/bin/update-areas b/bin/update-areas
index ed463708a..bbc933faf 100755
--- a/bin/update-areas
+++ b/bin/update-areas
@@ -33,11 +33,11 @@ BEGIN {
}
print "Fetching problems...\n";
-my $ids = select_all("select id, easting, northing from problem where areas=''");
+my $ids = select_all("select id, latitude, longitude from problem where areas=''");
print "Updating areas...\n";
my $c = 0;
foreach (@$ids) {
- my $areas = mySociety::MaPit::get_voting_areas_by_location({easting=>$_->{easting}, northing=>$_->{northing}}, 'polygon');
+ my $areas = mySociety::MaPit::get_voting_areas_by_location({latitude=>$_->{latitude}, longitude=>$_->{longitude}}, 'polygon');
$areas = ',' . join(',', sort keys %$areas) . ',';
dbh()->do('update problem set areas=? where id=?', {}, $areas, $_->{id});
dbh()->commit();