From: Llewellyn Marshall Date: Thu, 11 Aug 2022 15:03:32 +0000 (-0400) Subject: vicinity calc uses geo module for recalculations. bulk calculation breaks org units... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=cd32c2948bca6bc4d142ae11d38140790cfb020f;p=working%2FEvergreen.git vicinity calc uses geo module for recalculations. bulk calculation breaks org units into chunks to fit API requirements. --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index c4f5202a48..ed7318a6d6 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -4134,7 +4134,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + @@ -4142,9 +4142,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - - + + + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-shipping-hub-distance.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-shipping-hub-distance.component.ts index 8e7b7311e0..535a0a5772 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-shipping-hub-distance.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit-shipping-hub-distance.component.ts @@ -15,9 +15,9 @@ import {AuthService} from '@eg/core/auth.service';
- Entries in this table contain the distance in miles between shipping locations. Shipping hubs are configured from the Orginizational Units page. These numbers are used for sorting hold targets during inter-library lending. Entries can be created manually or calculated using the free Bing Maps API if a key has been set up in the opensrf core config file. Running the API will remove any existing data from this table. + Entries in this table contain the distance in kilometers between shipping hub locations. If configured for your service, driving distance will be used instead of as-the-crow-flies. Shipping hubs are configured from the Orginizational Units page. These numbers are used for sorting hold targets during inter-library lending. Entries can be created manually or calculated using your geolocation service. Recalculating the distances will clear out any existing data..
- +

@@ -44,7 +44,7 @@ export class OrgUnitShippingHubDistanceComponent implements OnInit { constructor( private route: ActivatedRoute, private idl: IdlService, - private net: NetService + private net: NetService, private auth: AuthService ) { } diff --git a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts index d9242bdf7b..1cbaf3f7d7 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts @@ -237,9 +237,10 @@ export class AdminPageComponent implements OnInit { this.canCreate = false; const pc = this.idlClassDef.permacrud || {}; const perms = pc.create ? pc.create.perms : []; - if (perms.length === 0) { return; } - + console.log(perms); + if (perms.length === 0) { return; } this.perm.hasWorkPermAt(perms, true).then(permMap => { + console.log(permMap); Object.keys(permMap).forEach(key => { if (permMap[key].length > 0) { this.canCreate = true; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Geo.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Geo.pm index ddf2a16fa4..3e8ade3fc9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Geo.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Geo.pm @@ -131,19 +131,17 @@ sub _post_request { my ($bing, $uri, $form, $json_coder) = @_; my $json = $json_coder->encode($form); return unless $uri; - $logger->info($uri); - $logger->info($form); + #$logger->info($uri); + #$logger->info($form); my $res = $bing->{response} = $bing->ua->post($uri,'Content-Length' => 3500,'Content-Type' => 'application/json',Content => $json); unless($res->is_success){ $logger->error("API ERROR\n"); + my @error = split /\n/, $res->decoded_content; + foreach(@error){ + $logger->error($_); + } return; - } - - my @error = split /\n/, $res->decoded_content; - foreach(@error){ - $logger->error($_); - } - + } # Change the content type of the response from 'application/json' so # HTTP::Message will decode the character encoding. $res->content_type('text/plain'); @@ -204,7 +202,7 @@ sub calculate_bulk_driving_distance { $dcoord{'longitude'} = $_->[1]; push(@destinations, \%dcoord); } - $logger->info(Dumper(\@destinations)); + #$logger->info(Dumper(\@destinations)); # find out how many coords we can process per request. my $budget = int(2500 / scalar(@origins)); @@ -268,7 +266,7 @@ sub calculate_bulk_driving_distance { return \@results; } - return []; + return \@results; } __PACKAGE__->register_method( diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/VicinityCalculator.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/VicinityCalculator.pm index d9ee04e0c5..11ad652f6f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/VicinityCalculator.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/VicinityCalculator.pm @@ -49,21 +49,25 @@ sub calculate_distance_matrix { my $geo = OpenSRF::AppSession->create('open-ils.geo'); my $geo_request = $geo->request('open-ils.geo.calculate_bulk_driving_distance', $self->{auth}, \@origins, \@destinations); - my @distance_matrix = @{$geo_request}; + my $result = $geo_request->recv(); + my $content = $result->content(); + $logger->info("content from API: ".Dumper($content)); + my @distance_matrix = @{$content}; if(@distance_matrix){ $self->{editor}->xact_begin; # clear out existing matrix + $logger->info("Old distance matrix is being cleared out."); $self->clear_hub_distances(); - for my $ref (@distance_matrix) { - for (@$ref){ + foreach(@distance_matrix) { + print(Dumper $_); # create our AOUSHD objects for the data returned my $dist = Fieldmapper::actor::org_unit_shipping_hub_distance->new; - $dist->orig_hub($hub_ids[$_->{originIndex}]); - $dist->dest_hub($hub_ids[$_->{destinationIndex}]); - $dist->distance($_->{travelDistance}); + $dist->orig_hub($hub_ids[$_->{origin}]); + $dist->dest_hub($hub_ids[$_->{destination}]); + $dist->distance($_->{distance}); # place AOUSHD into the DB $self->{editor}->runmethod('create', 'actor.org_unit_shipping_hub_distance', 'aoushd', $dist); - } + } # commit to DB $self->{editor}->xact_commit; @@ -73,6 +77,36 @@ sub calculate_distance_matrix { } } +sub get_coord_from_ou { +my($self,@org_ids) = @_; + my @ma = $self->{editor}->json_query({ + select => { + aoa => [ + { + column => 'org_unit', + }, + { + column => 'latitude', + },{ + column => 'longitude', + },{ + column => 'address_type', + } + ] + }, + from => 'aoa', + where => {org_unit=>[@org_ids], address_type=>['MAILING']} + }); + my %coords; + + for my $ref (@ma) { + for (@$ref){ + $coords{$_->{org_unit}} = [$_->{latitude}, $_->{longitude}]; + } + } + return %coords; +} + # remove all existing distance calculations. # TODO make this all happen in one query # what could the analog to DELETE FROM TABLE be?