aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/populate_bing_cache58
-rwxr-xr-xbin/send-reports12
2 files changed, 69 insertions, 1 deletions
diff --git a/bin/populate_bing_cache b/bin/populate_bing_cache
new file mode 100755
index 000000000..a3bef6759
--- /dev/null
+++ b/bin/populate_bing_cache
@@ -0,0 +1,58 @@
+#!/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,
+ confirmed => { '!=', undef },
+ latitude => { '!=', 0 },
+ longitude => { '!=', 0 },
+ },
+ {
+ select => [qw/id geocode confirmed latitude longitude/],
+ order_by => { -desc => 'confirmed' }
+ }
+);
+
+my $num_reports = $reports->count();
+print "Found $num_reports lacking geocode information\n";
+
+my $time_to_do = ( $num_reports * 10 ) / 60 / 60;
+if ( $time_to_do > 24 ) {
+ my $days = $time_to_do / 24;
+ my $hours = $time_to_do % 24;
+ printf( "Should take %d days and %d hours to finish\n", $days, $hours );
+}
+elsif ( $time_to_do < 1 ) {
+ printf( "Should take %d minutes to finish\n", $time_to_do * 60 );
+}
+else {
+ my $mins = ( $num_reports * 10 ) / 60 % 60;
+ printf( "Should take %d hours and %d minutes to finish\n",
+ $time_to_do, $mins );
+}
+
+while ( my $report = $reports->next ) {
+ $num_reports--;
+ next unless $report->latitude && $report->longitude;
+ next if $report->geocode;
+
+ my $j = FixMyStreet::Geocode::Bing::reverse( $report->latitude,
+ $report->longitude );
+
+ $report->geocode($j);
+ $report->update;
+
+ print "$num_reports left to populate\n" unless $num_reports % 100;
+ sleep 10;
+}
+
+print "done\n";
diff --git a/bin/send-reports b/bin/send-reports
index 648e83192..427d02ec8 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -92,7 +92,7 @@ while (my $row = $unsent->next) {
}
if ( $row->used_map ) {
- $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude} );
+ $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row );
}
my (@to, @recips, $template, $areas_info, @open311_councils);
@@ -273,8 +273,18 @@ while (my $row = $unsent->next) {
$open311->endpoints( { services => 'Services', requests => 'Requests' } );
}
+ # required to get round issues with CRM constraints
+ if ( $row->council =~ /2218/ ) {
+ $row->user->name( $row->user->id . ' ' . $row->user->name );
+ }
+
my $resp = $open311->send_service_request( $row, \%h, $contact->email );
+ # make sure we don't save user changes from above
+ if ( $row->council =~ /2218/ ) {
+ $row->discard_changes();
+ }
+
if ( $resp ) {
$row->external_id( $resp );
$result *= 0;