diff options
author | Matthew Somerville <matthew@balti.ukcod.org.uk> | 2010-07-22 14:39:37 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@balti.ukcod.org.uk> | 2010-07-22 14:39:37 +0100 |
commit | c8fc4502121fc1c3cb5857708c32e1a5bb2d0a33 (patch) | |
tree | e85f5fc1494a225563efe6446d38334e54555b70 | |
parent | d1c37ea5edb5277376b6200324224388b4475375 (diff) |
Update all FixMyStreet mapit calls.
-rwxr-xr-x | bin/send-questionnaires | 2 | ||||
-rwxr-xr-x | bin/send-questionnaires-eha | 1 | ||||
-rwxr-xr-x | bin/send-reports | 8 | ||||
m--------- | commonlib | 0 | ||||
-rw-r--r-- | perllib/Page.pm | 29 | ||||
-rw-r--r-- | perllib/Problems.pm | 2 | ||||
-rwxr-xr-x | web-admin/index.cgi | 20 | ||||
-rwxr-xr-x | web/alert.cgi | 3 | ||||
-rwxr-xr-x | web/index.cgi | 35 | ||||
-rwxr-xr-x | web/questionnaire.cgi | 1 | ||||
-rwxr-xr-x | web/reports.cgi | 28 | ||||
-rwxr-xr-x | web/rss.cgi | 2 |
12 files changed, 57 insertions, 74 deletions
diff --git a/bin/send-questionnaires b/bin/send-questionnaires index 840f70b2c..eb67cd5d1 100755 --- a/bin/send-questionnaires +++ b/bin/send-questionnaires @@ -70,7 +70,7 @@ foreach my $row (@$unsent) { next unless (Cobrand::email_host($cobrand)); my ($councils, $missing) = $row->{council} =~ /^([\d,]+)(?:\|([\d,]+))?/; my @councils = split /,/, $councils; - my $areas_info = mySociety::MaPit::get_voting_areas_info(\@all_councils); + my $areas_info = mySociety::MaPit::call('areas', \@all_councils); my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/questionnaire"); my %h = map { $_ => $row->{$_} } qw/name title detail category/; diff --git a/bin/send-questionnaires-eha b/bin/send-questionnaires-eha index 18375b8c6..2e0af8f4f 100755 --- a/bin/send-questionnaires-eha +++ b/bin/send-questionnaires-eha @@ -25,7 +25,6 @@ use mySociety::Config; use mySociety::DBHandle qw(dbh select_all); use mySociety::Email; use mySociety::Locale; -use mySociety::MaPit; use mySociety::EmailUtil; use mySociety::Random qw(random_bytes); diff --git a/bin/send-reports b/bin/send-reports index 18f097188..c91de5e33 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -108,7 +108,7 @@ foreach my $row (@$unsent) { if ($site eq 'emptyhomes') { my $council = $row->{council}; - $areas_info = mySociety::MaPit::get_voting_areas_info([ $council ]); + $areas_info = mySociety::MaPit::call('areas', $council); my $name = $areas_info->{$council}->{name}; my ($council_email, $confirmed, $note) = dbh()->selectrow_array( "SELECT email,confirmed,note FROM contacts WHERE deleted='f' @@ -132,7 +132,7 @@ foreach my $row (@$unsent) { my @all_councils = split /,|\|/, $row->{council}; my ($councils, $missing) = $row->{council} =~ /^([\d,]+)(?:\|([\d,]+))?/; my @councils = split /,/, $councils; - $areas_info = mySociety::MaPit::get_voting_areas_info(\@all_councils); + $areas_info = mySociety::MaPit::call('areas', \@all_councils); my (@dear, %recips); my $all_confirmed = 1; foreach my $council (@councils) { @@ -267,7 +267,7 @@ if ($verbose) { # Will do for now :) sub essex_contact { my ($E, $N) = @_; - my $district = mySociety::MaPit::get_voting_areas_by_location({easting=>$E, northing=>$N}, 'polygon', 'DIS'); + my $district = mySociety::MaPit::call('point', "27700/$E,$N", type => 'DIS'); ($district) = keys %$district; my $email; $email = 'eastarea' if $district == 2315 || $district == 2312; @@ -281,7 +281,7 @@ sub essex_contact { # Oxfordshire has different contact addresses depending upon the district sub oxfordshire_contact { my ($E, $N) = @_; - my $district = mySociety::MaPit::get_voting_areas_by_location({easting=>$E, northing=>$N}, 'polygon', 'DIS'); + my $district = mySociety::MaPit::call('point', "27700/$E,$N", type => 'DIS'); ($district) = keys %$district; my $email; $email = 'northernarea' if $district == 2419 || $district == 2420 || $district == 2421; diff --git a/commonlib b/commonlib -Subproject bb08a3792606b83f74dc1566706c3b903255a0e +Subproject ccd1837c99ec0f7bf028bd45a6a78eff06c4503 diff --git a/perllib/Page.pm b/perllib/Page.pm index cafd9ba91..77cf27b07 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -799,7 +799,7 @@ sub display_problem_meta_line($$) { if ($problem->{whensent}) { $problem->{council} =~ s/\|.*//g; my @councils = split /,/, $problem->{council}; - my $areas_info = mySociety::MaPit::get_voting_areas_info(\@councils); + my $areas_info = mySociety::MaPit::call('areas', \@councils); my $council = join(' and ', map { $areas_info->{$_}->{name} } @councils); $out .= '<small class="council_sent_info">'; $out .= $q->br() . sprintf(_('Sent to %s %s later'), $council, prettify_duration($problem->{whensent}, 'minute')); @@ -898,6 +898,19 @@ sub display_problem_updates($$) { return $out; } +sub mapit_check_error { + my $location = shift; + if ($location->{error}) { + return _('That postcode was not recognised, sorry.') if $location->{code} =~ /^4/; + return $location->{error}; + } + my $island = $location->{coordsyst}; + if ($island eq 'I') { + return _("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region."); + } + return 0; +} + # geocode STRING QUERY # Given a user-inputted string, try and convert it into co-ordinates using either # MaPit if it's a postcode, or Google Maps API otherwise. Returns an array of @@ -908,10 +921,8 @@ sub geocode { my ($s, $q) = @_; my ($x, $y, $easting, $northing, $error); if (mySociety::PostcodeUtil::is_valid_postcode($s)) { - try { - my $location = mySociety::MaPit::get_location($s); - my $island = $location->{coordsyst}; - throw RABX::Error(_("We do not cover Northern Ireland, I'm afraid, as our licence doesn't include any maps for the region.")) if $island eq 'I'; + my $location = mySociety::MaPit::call('postcode', $s); + unless ($error = mapit_check_error($location)) { $easting = $location->{easting}; $northing = $location->{northing}; my $xx = Page::os_to_tile($easting); @@ -920,14 +931,6 @@ sub geocode { $y = int($yy); $x -= 1 if ($xx - $x < 0.5); $y -= 1 if ($yy - $y < 0.5); - } catch RABX::Error with { - my $e = shift; - if ($e->value() && ($e->value() == mySociety::MaPit::BAD_POSTCODE - || $e->value() == mySociety::MaPit::POSTCODE_NOT_FOUND)) { - $error = _('That postcode was not recognised, sorry.'); - } else { - $error = $e; - } } } else { ($x, $y, $easting, $northing, $error) = geocode_string($s, $q); diff --git a/perllib/Problems.pm b/perllib/Problems.pm index 7ce082129..161306845 100644 --- a/perllib/Problems.pm +++ b/perllib/Problems.pm @@ -253,7 +253,7 @@ sub problems_matching_criteria { $problem->{council} = \@council_ids; } } - my $areas_info = mySociety::MaPit::get_voting_areas_info(\@councils); + my $areas_info = mySociety::MaPit::call('areas', \@councils); foreach my $problem (@$problems){ if ($problem->{council}) { my @council_names = map { $areas_info->{$_}->{name}} @{$problem->{council}} ; diff --git a/web-admin/index.cgi b/web-admin/index.cgi index 8ac3eb132..b7946d600 100755 --- a/web-admin/index.cgi +++ b/web-admin/index.cgi @@ -189,17 +189,11 @@ sub admin_councils_list ($) { # Table of councils print $q->h2("Councils"); - my @councils; my $ignore = 'LGD'; $ignore .= '|CTY' if $q->{site} eq 'emptyhomes'; my @types = grep { !/$ignore/ } @$mySociety::VotingArea::council_parent_types; # LGD are NI councils - foreach my $type (@types) { - my $areas = mySociety::MaPit::get_areas_by_type($type); - push @councils, @$areas; - } - my $councils = mySociety::MaPit::get_voting_areas_info(\@councils); - my @councils_ids = keys %$councils; - @councils_ids = sort { $councils->{$a}->{name} cmp $councils->{$b}->{name} } @councils_ids; + my $areas = mySociety::MaPit::call('areas', \@types); + my @councils_ids = sort { $areas->{$a}->{name} cmp $areas->{$b}->{name} } keys %$areas; my $bci_info = dbh()->selectall_hashref(" select area_id, count(*) as c, count(case when deleted then 1 else null end) as deleted, count(case when confirmed then 1 else null end) as confirmed @@ -214,7 +208,7 @@ sub admin_councils_list ($) { print $q->p(join($q->br(), map { $q->a({ href => NewURL($q, area_id => $_, page => 'councilcontacts') }, - $councils->{$_}->{name}) . " " . + $areas->{$_}->{name}) . " " . ($bci_info->{$_} && $q->{site} ne 'emptyhomes' ? $bci_info->{$_}->{c} . ' addresses' : '') @@ -306,7 +300,7 @@ sub admin_council_contacts ($$) { $q->delete_all(); # No need for state! # Title - my $mapit_data = mySociety::MaPit::get_voting_area_info($area_id); + my $mapit_data = mySociety::MaPit::call('area', $area_id); my $title = 'Council contacts for ' . $mapit_data->{name}; print html_head($q, $title); print $q->h1($title); @@ -314,7 +308,7 @@ sub admin_council_contacts ($$) { # Example postcode, link to list of problem reports my $links_html; - my $example_postcode = mySociety::MaPit::get_example_postcode($area_id); + my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id); if ($example_postcode) { $links_html .= $q->a({ href => mySociety::Config::get('BASE_URL') . '/?pc=' . $q->escape($example_postcode) }, "Example postcode " . $example_postcode) . " | "; @@ -387,7 +381,7 @@ sub admin_council_edit ($$$) { my $bci_data = select_all("select * from contacts where area_id = ? and category = ?", $area_id, $category); $bci_data = $bci_data->[0]; my $bci_history = select_all("select * from contacts_history where area_id = ? and category = ? order by contacts_history_id", $area_id, $category); - my $mapit_data = mySociety::MaPit::get_voting_area_info($area_id); + my $mapit_data = mySociety::MaPit::call('area', $area_id); # Title my $title = 'Council contacts for ' . $mapit_data->{name}; @@ -395,7 +389,7 @@ sub admin_council_edit ($$$) { print $q->h1($title); # Example postcode - my $example_postcode = mySociety::MaPit::get_example_postcode($area_id); + my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id); if ($example_postcode) { print $q->p("Example postcode: ", $q->a({ href => mySociety::Config::get('BASE_URL') . '/?pc=' . $q->escape($example_postcode) }, diff --git a/web/alert.cgi b/web/alert.cgi index 59b6607a4..d6cff7ff3 100755 --- a/web/alert.cgi +++ b/web/alert.cgi @@ -104,13 +104,12 @@ sub alert_list { my @types = (@$mySociety::VotingArea::council_parent_types, @$mySociety::VotingArea::council_child_types); my %councils = map { $_ => 1 } @$mySociety::VotingArea::council_parent_types; - my $areas = mySociety::MaPit::get_voting_areas_by_location({easting=>$e, northing=>$n}, 'polygon', \@types); + my $areas = mySociety::MaPit::call('point', "27700/$e,$n", type => \@types); my $cobrand = Page::get_cobrand($q); my ($success, $error_msg) = Cobrand::council_check($cobrand, $areas, $q, 'alert'); if (!$success){ return alert_front_page($q, $error_msg); } - $areas = mySociety::MaPit::get_voting_areas_info([ keys %$areas ]); return alert_front_page($q, _('That location does not appear to be covered by a council, perhaps it is offshore - please try somewhere more specific.')) if keys %$areas == 0; diff --git a/web/index.cgi b/web/index.cgi index e39dd8921..563465c37 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -306,10 +306,7 @@ sub submit_problem { my $areas; if ($input{easting} && $input{northing}) { - $areas = mySociety::MaPit::get_voting_areas_by_location( - { easting=>$input{easting}, northing=>$input{northing} }, - 'polygon', [qw(WMC CTY CED DIS DIW MTD MTW COI COP LGD LGE UTA UTE UTW LBO LBW LAC SPC WAC NIE)] - ); + $areas = mySociety::MaPit::call('point', "27700/$input{easting},$input{northing}"); if ($input{council} =~ /^[\d,]+(\|[\d,]+)?$/) { my $no_details = $1 || ''; my %va = map { $_ => 1 } @$mySociety::VotingArea::council_parent_types; @@ -515,9 +512,7 @@ sub display_form { $parent_types = [qw(DIS LBO MTD UTA LGD COI)] # No CTY if $q->{site} eq 'emptyhomes'; # XXX: I think we want in_gb_locale around the next line, needs testing - my $all_councils = mySociety::MaPit::get_voting_areas_by_location( - { easting => $easting, northing => $northing }, - 'polygon', $parent_types); + my $all_councils = mySociety::MaPit::call('point', "27700/$easting,$northing", type => $parent_types); # Let cobrand do a check my ($success, $error_msg) = Cobrand::council_check($cobrand, $all_councils, $q, 'submit_problem'); @@ -531,17 +526,15 @@ sub display_form { # Norwich is responsible for everything in its areas, no Norfolk delete $all_councils->{2233} if $all_councils->{2391}; - $all_councils = [ keys %$all_councils ]; return display_location($q, _('That spot does not appear to be covered by a council. If you have tried to report an issue 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); +please specify the closest point on land.')) unless %$all_councils; # Look up categories for this council or councils my $category = ''; my (%council_ok, @categories); my $categories = select_all("select area_id, category from contacts - where deleted='f' and area_id in (" . join(',', @$all_councils) . ')'); + where deleted='f' and area_id in (" . join(',', keys %$all_councils) . ')'); if ($q->{site} ne 'emptyhomes') { @$categories = sort { $a->{category} cmp $b->{category} } @$categories; foreach (@$categories) { @@ -574,7 +567,7 @@ please specify the closest point on land.')) unless @$all_councils; # Work out what help text to show, depending on whether we have council details my @councils = keys %council_ok; my $details; - if (@councils == @$all_councils) { + if (@councils == scalar keys %$all_councils) { $details = 'all'; } elsif (@councils == 0) { $details = 'none'; @@ -629,7 +622,7 @@ If this is not the correct location, simply click on the map again. ')); $vars{page_heading} = $q->h1(_('Reporting a problem')); if ($details eq 'all') { - my $council_list = join('</strong> or <strong>', map { $areas_info->{$_}->{name} } @$all_councils); + my $council_list = join('</strong> or <strong>', map { $_->{name} } values %$all_councils); if ($q->{site} eq 'emptyhomes'){ $vars{text_help} = '<p>' . sprintf(_('All the information you provide here will be sent to <strong>%s</strong>. On the site, we will show the subject and details of the problem, plus your @@ -639,18 +632,18 @@ name if you give us permission.'), $council_list); The subject and details of the problem will be public, plus your name if you give us permission.'), $council_list); } - $vars{text_help} .= '<input type="hidden" name="council" value="' . join(',',@$all_councils) . '">'; + $vars{text_help} .= '<input type="hidden" name="council" value="' . join(',', keys %$all_councils) . '">'; } elsif ($details eq 'some') { my $e = Cobrand::contact_email($cobrand); my %councils = map { $_ => 1 } @councils; my @missing; - foreach (@$all_councils) { + foreach (keys %$all_councils) { push @missing, $_ unless $councils{$_}; } my $n = @missing; - my $list = join(' or ', map { $areas_info->{$_}->{name} } @missing); + my $list = join(' or ', map { $all_councils->{$_}->{name} } @missing); $vars{text_help} = '<p>All the information you provide here will be sent to <strong>' - . join('</strong> or <strong>', map { $areas_info->{$_}->{name} } @councils) + . join('</strong> or <strong>', map { $all_councils->{$_}->{name} } @councils) . '</strong>. The subject and details of the problem will be public, plus your name if you give us permission.'; $vars{text_help} .= ' We do <strong>not</strong> yet have details for the other council'; @@ -661,8 +654,8 @@ problems for $list and emailing it to us at <a href='mailto:$e'>$e</a>."; . '|' . join(',', @missing) . '">'; } else { my $e = Cobrand::contact_email($cobrand); - my $list = join(' or ', map { $areas_info->{$_}->{name} } @$all_councils); - my $n = @$all_councils; + my $list = join(' or ', map { $_->{name} } values %$all_councils); + my $n = scalar keys %$all_councils; if ($q->{site} ne 'emptyhomes') { $vars{text_help} = '<p>We do not yet have details for the council'; $vars{text_help} .= ($n>1) ? 's that cover' : ' that covers'; @@ -812,9 +805,7 @@ sub display_location { return front_page($q, $error) if ($error); my $parent_types = $mySociety::VotingArea::council_parent_types; if ($easting && $northing) { - my $all_councils = mySociety::MaPit::get_voting_areas_by_location( - { easting => $easting, northing => $northing }, - 'polygon', $parent_types); + my $all_councils = mySociety::MaPit::call('point', "27700/$easting,$northing", type => $parent_types); my ($success, $error_msg) = Cobrand::council_check($cobrand, $all_councils, $q, 'display_location'); if (!$success){ return front_page($q, $error_msg); diff --git a/web/questionnaire.cgi b/web/questionnaire.cgi index f7b7df0e1..1da410b80 100755 --- a/web/questionnaire.cgi +++ b/web/questionnaire.cgi @@ -14,7 +14,6 @@ use Error qw(:try); use CrossSell; use mySociety::AuthToken; use mySociety::Locale; -use mySociety::MaPit; use mySociety::Web qw(ent); sub main { diff --git a/web/reports.cgi b/web/reports.cgi index 6c5796079..eb7f67b27 100755 --- a/web/reports.cgi +++ b/web/reports.cgi @@ -33,28 +33,27 @@ sub main { my ($one_council, $area_type, $area_name); if ($q_council =~ /^(\d\d)([a-z]{2})?([a-z]{2})?$/i) { - my $va_info = mySociety::MaPit::get_voting_area_info(uc $q_council); + my $va_info = mySociety::MaPit::call('area/ons', uc $q_council); $area_name = Page::short_name($va_info->{name}); if (length($q_council) == 6) { - $va_info = mySociety::MaPit::get_voting_area_info($va_info->{parent_area_id}); + $va_info = mySociety::MaPit::call('area', $va_info->{parent_area}); $area_name = Page::short_name($va_info->{name}) . '/' . $area_name; } $rss = '/rss' if $rss; print $q->redirect($base_url . $rss . '/reports/' . $area_name); return; } elsif ($q_council =~ /\D/) { - (my $qc = $q_council) =~ s/ and / & /; - my $areas = mySociety::MaPit::get_voting_area_by_name($qc, $mySociety::VotingArea::council_parent_types, 10); + my $areas = mySociety::MaPit::call('areas', $q_council, type => $mySociety::VotingArea::council_parent_types, min_generation=>10 ); if (keys %$areas == 1) { ($one_council) = keys %$areas; $area_type = $areas->{$one_council}->{type}; $area_name = $areas->{$one_council}->{name}; } else { foreach (keys %$areas) { - if ($areas->{$_}->{name} =~ /^\Q$qc\E (Borough|City|District|County) Council$/) { + if ($areas->{$_}->{name} =~ /^\Q$q_council\E (Borough|City|District|County) Council$/) { $one_council = $_; $area_type = $areas->{$_}->{type}; - $area_name = $qc; + $area_name = $q_council; } } } @@ -63,7 +62,7 @@ sub main { return; } } elsif ($q_council =~ /^\d+$/) { - my $va_info = mySociety::MaPit::get_voting_area_info($q_council); + my $va_info = mySociety::MaPit::call('area', $q_council); $area_name = $va_info->{name}; print $q->redirect($base_url . '/reports/' . Page::short_name($area_name)); return; @@ -74,9 +73,9 @@ sub main { my $q_ward = $q->param('ward') || ''; my $ward; if ($one_council && $q_ward) { - my $qw = mySociety::MaPit::get_voting_area_by_name($q_ward, $mySociety::VotingArea::council_child_types, 10); + my $qw = mySociety::MaPit::call('areas', $q_ward, type => $mySociety::VotingArea::council_child_types, min_generation => 10); foreach my $id (sort keys %$qw) { - if ($qw->{$id}->{parent_area_id} == $one_council) { + if ($qw->{$id}->{parent_area} == $one_council) { $ward = $id; last; } @@ -116,21 +115,21 @@ sub main { return; } - my %councils; + my $areas_info; if ($one_council) { - %councils = ( $one_council => 1 ); + $areas_info = mySociety::MaPit::call('areas', $one_council); } else { # Show all councils on main report page my $ignore = 'LGD'; $ignore .= '|CTY' if $q->{site} eq 'emptyhomes'; my @types = grep { !/$ignore/ } @$mySociety::VotingArea::council_parent_types; - %councils = map { $_ => 1 } @{mySociety::MaPit::get_areas_by_type(\@types, 10)}; + $areas_info = mySociety::MaPit::call('areas', [ @types ], min_generation=>10 ); } my $problems = Problems::council_problems($ward, $one_council); my (%fixed, %open); - my $re_councils = join('|', keys %councils); + my $re_councils = join('|', keys %$areas_info); foreach my $row (@$problems) { if (!$row->{council}) { # Problem was not sent to any council, add to possible councils @@ -148,7 +147,6 @@ sub main { } } - my $areas_info = mySociety::MaPit::get_voting_areas_info([keys %councils]); if (!$one_council) { print Page::header($q, title=>_('Summary reports'), expires=>'+1h'); print $q->p( @@ -162,7 +160,7 @@ sub main { print '<th>' . _('Old problems,<br>state unknown') . '</th>'; } print '<th>' . _('Recently fixed') . '</th><th>' . _('Older fixed') . '</th></tr>'; - foreach (sort { $areas_info->{$a}->{name} cmp $areas_info->{$b}->{name} } keys %councils) { + foreach (sort { $areas_info->{$a}->{name} cmp $areas_info->{$b}->{name} } keys %$areas_info) { print '<tr align="center"'; ++$c; if ($areas_info->{$_}->{generation_high}==10) { diff --git a/web/rss.cgi b/web/rss.cgi index a2810aee8..7060d1709 100755 --- a/web/rss.cgi +++ b/web/rss.cgi @@ -43,7 +43,7 @@ sub main { $out = mySociety::Alert::generate_rss($type, $xsl, $qs, [$id], undef, $cobrand. $q); } elsif ($type eq 'area_problems') { my $id = $q->param('id'); - my $va_info = mySociety::MaPit::get_voting_area_info($id); + my $va_info = mySociety::MaPit::call('area', $id); my $qs = '/'.$id; $out = mySociety::Alert::generate_rss($type, $xsl, $qs, [$id], { NAME => $va_info->{name} }, $cobrand, $q); } elsif ($type eq 'all_problems') { |