-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
120 changed files
with
9,755 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,7 @@ hypnotoad.pid | |
|
||
cover_db/ | ||
schema.png | ||
|
||
etc/code-point-open/codepo_gb/ | ||
|
||
pear-local_loop.production.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
* email: [email protected] | ||
* password: abc123 | ||
* Test Org | ||
* email: test5@example.com | ||
* email: org@example.com | ||
* password: abc123 | ||
* Test Admin | ||
* email: [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ORDNANCE SURVEY DATA LICENCE | ||
|
||
Your use of data is subject to terms at www.ordnancesurvey.co.uk/opendata/licence. | ||
|
||
Contains Ordnance Survey data � Crown copyright and database right 2017. | ||
|
||
Contains Royal Mail data � Royal Mail copyright and database right 2017. | ||
Contains National Statistics data � Crown copyright and database right 2017. | ||
|
||
August 2017 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package Pear::LocalLoop::Command::codepoint_open; | ||
use Mojo::Base 'Mojolicious::Command'; | ||
|
||
use Mojo::Util 'getopt'; | ||
|
||
use Geo::UK::Postcode::CodePointOpen; | ||
|
||
has description => 'Manage Codepoint Open Data'; | ||
|
||
has usage => sub { shift->extract_usage }; | ||
|
||
sub run { | ||
my ( $self, @args ) = @_; | ||
|
||
getopt \@args, | ||
'o|outcodes=s' => \my @outcodes, | ||
'q|quiet' => \my $quiet_mode; | ||
|
||
my $cpo_dir = $self->app->home->child('etc')->child('code-point-open'); | ||
my $zip_file = $cpo_dir->child('codepo_gb.zip')->realpath->to_string; | ||
my $output_dir = $cpo_dir->child('codepo_gb')->realpath->to_string; | ||
|
||
unless ( -d $output_dir ) { | ||
print "Unzipping code-point-open data\n" unless $quiet_mode; | ||
system( 'unzip', '-q', $zip_file, '-d', $output_dir ); | ||
} | ||
|
||
my $cpo = Geo::UK::Postcode::CodePointOpen->new( path => $output_dir ); | ||
|
||
printf( "Importing data for %s outcode(s)\n", @outcodes ? join( ' ', @outcodes ) : 'all' ) | ||
unless $quiet_mode; | ||
|
||
my $iter = $cpo->read_iterator( | ||
outcodes => \@outcodes, | ||
include_lat_long => 1, | ||
split_postcode => 1, | ||
); | ||
|
||
my $pc_rs = $self->app->schema->resultset('GbPostcode'); | ||
while ( my $pc = $iter->() ) { | ||
$pc_rs->find_or_create( | ||
{ | ||
outcode => $pc->{Outcode}, | ||
incode => $pc->{Incode}, | ||
latitude => $pc->{Latitude}, | ||
longitude => $pc->{Longitude}, | ||
}, | ||
{ key => 'primary' }, | ||
); | ||
} | ||
} | ||
|
||
=head1 SYNOPSIS | ||
Usage: APPLICATION codepoint_open [OPTIONS] | ||
Options: | ||
-o|--outcodes <outcode> : limit to specified outcodes (can be defined | ||
multiple times) | ||
=cut | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package Pear::LocalLoop::Command::latlong_setup; | ||
use Mojo::Base 'Mojolicious::Command'; | ||
|
||
use Mojo::Util 'getopt'; | ||
|
||
use Geo::UK::Postcode::Regex; | ||
use GIS::Distance; | ||
|
||
has description => 'Set lat/long data on customers and orgs'; | ||
|
||
has usage => sub { shift->extract_usage }; | ||
|
||
sub run { | ||
my ( $self, @args ) = @_; | ||
|
||
my $customer_rs = $self->app->schema->resultset('Customer'); | ||
my $org_rs = $self->app->schema->resultset('Organisation'); | ||
|
||
for my $result ( $customer_rs->all, $org_rs->all ) { | ||
$self->_set_lat_long_for_result( $result ); | ||
} | ||
|
||
my $transaction_rs = $self->app->schema->resultset('Transaction'); | ||
|
||
for my $result ( $transaction_rs->all ) { | ||
my $distance = $self->_calculate_distance( | ||
$result->buyer->${\$result->buyer->type}, | ||
$result->seller->${\$result->seller->type}, | ||
); | ||
$result->update({ distance => $distance }) if defined $distance; | ||
} | ||
} | ||
|
||
sub _set_lat_long_for_result { | ||
my ( $self, $result ) = @_; | ||
|
||
my $parsed_postcode = Geo::UK::Postcode::Regex->parse($result->postcode); | ||
my $pc_rs = $self->app->schema->resultset('GbPostcode'); | ||
|
||
if ( $parsed_postcode->{valid} && !$parsed_postcode->{non_geographical} ) { | ||
my $gb_pc = $pc_rs->find({ | ||
outcode => $parsed_postcode->{outcode}, | ||
incode => $parsed_postcode->{incode}, | ||
}); | ||
if ( $gb_pc ) { | ||
$result->update({ | ||
latitude => $gb_pc->latitude, | ||
longitude => $gb_pc->longitude, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
sub _calculate_distance { | ||
my ( $self, $buyer, $seller ) = @_; | ||
|
||
my $gis = GIS::Distance->new(); | ||
|
||
my $buyer_lat = $buyer->latitude; | ||
my $buyer_long = $buyer->longitude; | ||
my $seller_lat = $seller->latitude; | ||
my $seller_long = $seller->longitude; | ||
|
||
if ( $buyer_lat && $buyer_long | ||
&& $seller_lat && $seller_long ) { | ||
return $gis->distance( $buyer_lat, $buyer_long => $seller_lat, $seller_long )->meters; | ||
} else { | ||
print STDERR "missing lat-long for: " . $buyer->name . " or " . $seller->name . "\n"; | ||
} | ||
return; | ||
} | ||
|
||
=head1 SYNOPSIS | ||
Usage: APPLICATION latlong_setup [OPTIONS] | ||
Options: | ||
none for now | ||
=cut | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.