aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/populate_bing_cache25
-rw-r--r--db/schema.sql3
-rw-r--r--db/schema_0009_add_gecode_column_to_problem.sql7
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Rss.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm35
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm28
6 files changed, 88 insertions, 15 deletions
diff --git a/bin/populate_bing_cache b/bin/populate_bing_cache
new file mode 100644
index 000000000..f61b4a4bd
--- /dev/null
+++ b/bin/populate_bing_cache
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+require 5.8.0;
+
+use Data::Dumper;
+
+use FixMyStreet::App;
+use FixMyStreet::Geocode::Bing;
+
+my $reports = FixMyStreet::App->model('DB::Problem')->search( {geocode
+ => undef }, { select => [qw/id geocode confirmed latitude longitude/] } );
+
+while ( my $report = $reports->next ) {
+ next unless $report->latitude && $report->longitude;
+ print $report->id . "\n";
+
+ my $j = FixMyStreet::Geocode::Bing::reverse( $report->latitude, $report->longitude );
+
+ $report->geocode( $j );
+ $report->update;
+
+ sleep 10;
+}
diff --git a/db/schema.sql b/db/schema.sql
index 99cf2832d..c0f225aa1 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -184,7 +184,8 @@ create table problem (
lastupdate timestamp not null default ms_current_timestamp(),
whensent timestamp,
send_questionnaire boolean not null default 't',
- flagged boolean not null default 'f'
+ flagged boolean not null default 'f',
+ geocode bytea
);
create index problem_state_latitude_longitude_idx on problem(state, latitude, longitude);
create index problem_user_id_idx on problem ( user_id );
diff --git a/db/schema_0009_add_gecode_column_to_problem.sql b/db/schema_0009_add_gecode_column_to_problem.sql
new file mode 100644
index 000000000..730212ead
--- /dev/null
+++ b/db/schema_0009_add_gecode_column_to_problem.sql
@@ -0,0 +1,7 @@
+
+begin;
+
+ALTER table problem
+ ADD column geocode BYTEA;
+
+commit;
diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm
index 23345df65..6152f5a17 100755
--- a/perllib/FixMyStreet/App/Controller/Rss.pm
+++ b/perllib/FixMyStreet/App/Controller/Rss.pm
@@ -265,8 +265,9 @@ sub add_row : Private {
}
if ( $row->{used_map} ) {
- #my $address = $c->cobrand->find_closest_address_for_rss( $row->{latitude}, $row->{longitude} );
- #$item{description} .= ent("\n<br>$address");
+ # TODO: uncomment these when the populate script has been run
+ # my $address = $c->cobrand->find_closest_address_for_rss( $row->{latitude}, $row->{longitude}, $row );
+ # $item{description} .= ent("\n<br>$address");
}
my $recipient_name = $c->cobrand->contact_name;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 1e87468ac..283de7d75 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -576,18 +576,33 @@ Used by rss feeds to provide a bit more context
=cut
sub find_closest_address_for_rss {
- my ( $self, $latitude, $longitude ) = @_;
+ my ( $self, $latitude, $longitude, $problem ) = @_;
my $str = '';
- if ( my $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 ) ) {
- if ($j->{resourceSets}[0]{resources}[0]{name}) {
- my $address = $j->{resourceSets}[0]{resources}[0]{address};
- my @address;
- push @address, $address->{addressLine} if $address->{addressLine} ne 'Street';
- push @address, $address->{locality};
- $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"),
- join( ', ', @address ) );
- }
+ my $j;
+ if ( $problem && ref($problem) =~ /FixMyStreet/ && $problem->can( 'geocode' ) ) {
+ $j = $problem->geocode;
+ } else {
+ $problem = FixMyStreet::App->model('DB::Problem')->find( { id => $problem->{id} } );
+ $j = $problem->geocode;
+ }
+
+ # if we've not cached it then we don't want to look it up in order to avoid
+ # hammering the bing api
+ # if ( !$j ) {
+ # $j = FixMyStreet::Geocode::Bing::reverse( $latitude, $longitude, 1 );
+
+ # $problem->geocode( $j );
+ # $problem->update;
+ # }
+
+ if ($j && $j->{resourceSets}[0]{resources}[0]{name}) {
+ my $address = $j->{resourceSets}[0]{resources}[0]{address};
+ my @address;
+ push @address, $address->{addressLine} if $address->{addressLine} ne 'Street';
+ push @address, $address->{locality};
+ $str .= sprintf(_("Nearest road to the pin placed on the map (automatically generated by Bing Maps): %s"),
+ join( ', ', @address ) );
}
return $str;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 987c92c64..abe781c92 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -78,8 +78,12 @@ __PACKAGE__->add_columns(
{ data_type => "timestamp", is_nullable => 1 },
"send_questionnaire",
{ data_type => "boolean", default_value => \"true", is_nullable => 0 },
+ "extra",
+ { data_type => "text", is_nullable => 1 },
"flagged",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "geocode",
+ { data_type => "bytea", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many(
@@ -102,8 +106,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 15:49:48
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3sw/1dqxlTvcWEI/eJTm4w
+# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-09-19 14:38:43
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nq8Ufn/SEoDGSrrGlHIxag
# Add fake relationship to stored procedure table
__PACKAGE__->has_one(
@@ -113,6 +117,26 @@ __PACKAGE__->has_one(
{ cascade_copy => 0, cascade_delete => 0 },
);
+__PACKAGE__->filter_column(
+ geocode => {
+ filter_from_storage => sub {
+ my $self = shift;
+ my $ser = shift;
+ return undef unless defined $ser;
+ my $h = new IO::String($ser);
+ return RABX::wire_rd($h);
+ },
+ filter_to_storage => sub {
+ my $self = shift;
+ my $data = shift;
+ my $ser = '';
+ my $h = new IO::String($ser);
+ RABX::wire_wr( $data, $h );
+ return $ser;
+ },
+ }
+);
+
use DateTime::TimeZone;
use Image::Size;
use Moose;