aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/send-reports10
-rwxr-xr-xbin/update-areas46
-rwxr-xr-xweb/index.cgi17
3 files changed, 62 insertions, 11 deletions
diff --git a/bin/send-reports b/bin/send-reports
index 4d5546a55..222d99318 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: send-reports,v 1.45 2007-08-02 11:44:59 matthew Exp $
+# $Id: send-reports,v 1.46 2007-08-24 12:27:30 matthew Exp $
use strict;
require 5.8.0;
@@ -161,8 +161,8 @@ if ($verbose) {
# Will do for now :)
sub essex_contact {
my ($E, $N) = @_;
- my $district = mySociety::MaPit::get_voting_area_by_location_en($E, $N, 'polygon', 'DIS');
- $district = $district->[0];
+ my $district = mySociety::MaPit::get_voting_areas_by_location({easting=>$E, northing=>$N}, 'polygon', 'DIS');
+ ($district) = keys %$district;
my $email;
$email = 'eastarea' if $district == 2315 || $district == 2312;
$email = 'midarea' if $district == 2317 || $district == 2314 || $district == 2316;
@@ -175,8 +175,8 @@ sub essex_contact {
# Notts has different contact addresses depending upon the district
sub notts_contact {
my ($E, $N) = @_;
- my $district = mySociety::MaPit::get_voting_area_by_location_en($E, $N, 'polygon', 'DIS');
- $district = $district->[0];
+ my $district = mySociety::MaPit::get_voting_areas_by_location({easting=>$E, northing=>$N}, 'polygon', 'DIS');
+ ($district) = keys %$district;
my $email;
$email = 'cshighsouth.en' if $district == 2411 || $district == 2412 || $district == 2415;
$email = 'etwall' if $district == 2413 || $district == 2416;
diff --git a/bin/update-areas b/bin/update-areas
new file mode 100755
index 000000000..b161d039b
--- /dev/null
+++ b/bin/update-areas
@@ -0,0 +1,46 @@
+#!/usr/bin/perl -w
+
+# update-areas:
+# One-off script to populate the areas column of the problem table
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+#
+# $Id: update-areas,v 1.1 2007-08-24 12:27:30 matthew Exp $
+
+use strict;
+require 5.8.0;
+
+# Horrible boilerplate to set up appropriate library paths.
+use FindBin;
+use lib "$FindBin::Bin/../perllib";
+use lib "$FindBin::Bin/../../perllib";
+
+use mySociety::Config;
+use mySociety::DBHandle qw(dbh select_all);
+use mySociety::MaPit;
+use mySociety::VotingArea;
+
+BEGIN {
+ mySociety::Config::set_file("$FindBin::Bin/../conf/general");
+ mySociety::DBHandle::configure(
+ Name => mySociety::Config::get('BCI_DB_NAME'),
+ User => mySociety::Config::get('BCI_DB_USER'),
+ Password => mySociety::Config::get('BCI_DB_PASS'),
+ Host => mySociety::Config::get('BCI_DB_HOST', undef),
+ Port => mySociety::Config::get('BCI_DB_PORT', undef)
+ );
+}
+
+print "Fetching problems...\n";
+my $ids = select_all("select id, easting, northing 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');
+ $areas = ',' . join(',', sort keys %$areas) . ',';
+ dbh()->do('update problem set areas=? where id=?', {}, $areas, $_->{id});
+ dbh()->commit();
+ print "Done: " . (++$c) . "/" . @$ids . "\n";
+}
+
diff --git a/web/index.cgi b/web/index.cgi
index 07c75616d..9a64bf7c4 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.159 2007-08-24 00:24:15 matthew Exp $
+# $Id: index.cgi,v 1.160 2007-08-24 12:27:30 matthew Exp $
use strict;
require 5.8.0;
@@ -242,12 +242,14 @@ sub submit_problem {
my $areas;
if ($input{easting} && $input{northing}) {
- $areas = mySociety::MaPit::get_voting_area_by_location_en($input{easting}, $input{northing}, 'polygon');
- $areas = ',' . join(',', @$areas) . ',';
+ $areas = mySociety::MaPit::get_voting_areas_by_location({easting=>$input{easting}, northing=>$input{northing}}, 'polygon');
if ($input{council} =~ /^[\d,]+(\|[\d,]+)?$/) {
my $no_details = $1 || '';
- my $councils = mySociety::MaPit::get_voting_area_by_location_en($input{easting}, $input{northing}, 'polygon', $mySociety::VotingArea::council_parent_types);
- my %councils = map { $_ => 1 } @$councils;
+ my %va = map { $_ => 1 } @$mySociety::VotingArea::council_parent_types;
+ my %councils;
+ foreach (keys %$areas) {
+ $councils{$_} = 1 if $va{$areas->{$_}};
+ }
my @input_councils = split /,|\|/, $input{council};
foreach (@input_councils) {
if (!$councils{$_}) {
@@ -278,6 +280,7 @@ sub submit_problem {
}
$input{council} = join(',', @valid_councils) . $no_details;
}
+ $areas = ',' . join(',', sort keys %$areas) . ',';
} elsif ($input{easting} || $input{northing}) {
push(@errors, 'Somehow, you only have one co-ordinate. Please try again.');
} else {
@@ -414,8 +417,10 @@ sub display_form {
$northing = $input_h{northing};
}
- my $all_councils = mySociety::MaPit::get_voting_area_by_location_en($easting, $northing,
+ my $all_councils = mySociety::MaPit::get_voting_areas_by_location(
+ { easting => $easting, northing => $northing },
'polygon', $mySociety::VotingArea::council_parent_types);
+ $all_councils = [ keys %$all_councils ];
return display_location($q, 'That spot does not appear to be covered by a council - if it is past the shoreline, for example, please specify the closest point on land.') unless @$all_councils;
my $areas_info = mySociety::MaPit::get_voting_areas_info($all_councils);