From 455d0081cd6c4e2ace31087a45dcb43e17e50dd7 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Fri, 19 Apr 2024 12:53:14 -0400 Subject: [PATCH 1/6] chore: update geocoder --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2f36e15..afedb8c 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@bugsnag/js": "^7.11.0", "@bugsnag/plugin-aws-lambda": "^7.11.0", "@conveyal/lonlat": "^1.4.1", - "@opentripplanner/geocoder": "^2.2.0", + "@opentripplanner/geocoder": "^2.2.1", "geolib": "^3.3.1", "node-fetch": "^2.6.1", "serverless-api-gateway-caching": "^1.8.1", diff --git a/yarn.lock b/yarn.lock index 109ca56..fc61b37 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2521,10 +2521,10 @@ dependencies: "@octokit/openapi-types" "^12.11.0" -"@opentripplanner/geocoder@^2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-2.2.0.tgz#071f91664e898b06705c781fddd4f75dfcb3cc3f" - integrity sha512-V41WOCIpvwLRHEchBg3vRzGOOxoI+SdxczLGgLGPJ/Q/XiqaTqUgsK8WUv+hAUAGYNxI7jZbx7zdC2pXCH0m4w== +"@opentripplanner/geocoder@^2.2.1": + version "2.2.1" + resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-2.2.1.tgz#c833c7a965291daf04e712adcf25a8d4d9c5c065" + integrity sha512-JkiydCToqivnz8gN57nx14MmaUoLco/K08xIrafYO6akvZHnwVZGi9enIigfxmAH+y1hu3uCviHgu3ATUmO/NQ== dependencies: "@conveyal/geocoder-arcgis-geojson" "^0.0.3" "@conveyal/lonlat" "^1.4.1" From 9c468a919d2a5587ff8c6907ed7144b674ad6e7f Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Fri, 19 Apr 2024 13:02:05 -0400 Subject: [PATCH 2/6] add `LOCATION_COMPARISON_COORDIATE_ACCURACY` setting --- env.example.yml | 4 +++- serverless.yml | 1 + utils.ts | 17 +++++++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/env.example.yml b/env.example.yml index 9408353..095f6a7 100644 --- a/env.example.yml +++ b/env.example.yml @@ -2,4 +2,6 @@ LAMBDA_EXEC_SG: Insert AWS Security Group ID Here (it must be in the same VPC as LAMBDA_EXEC_SUBNET: Insert AWS Subnet ID Here (it must be in the same VPC as the security group) BUGSNAG_NOTIFIER_KEY: INSERT BUGSNAG NOTIFIER KEY HERE GEOCODERS: -BACKUP_GEOCODERS: +BACKUP_GEOCODERS: + +LOCATION_COMPARISON_COORDIATE_ACCURACY: defaults to 4 (~10m). What accuracy to use when comparing if two locations are the same diff --git a/serverless.yml b/serverless.yml index d34b179..da12780 100644 --- a/serverless.yml +++ b/serverless.yml @@ -12,6 +12,7 @@ provider: GEOCODERS: ${self:custom.secrets.GEOCODERS} BACKUP_GEOCODERS: ${self:custom.secrets.BACKUP_GEOCODERS} BUGSNAG_NOTIFIER_KEY: ${self:custom.secrets.BUGSNAG_NOTIFIER_KEY} + LOCATION_COMPARISON_COORDIATE_ACCURACY: ${self:custom.secrets.LOCATION_COMPARISON_COORDIATE_ACCURACY, 4} package: patterns: - pois.json diff --git a/utils.ts b/utils.ts index 60790ed..8cb7d87 100644 --- a/utils.ts +++ b/utils.ts @@ -30,6 +30,9 @@ export type ServerlessResponse = { // Consts const PREFERRED_LAYERS = ['venue', 'address', 'street', 'intersection'] +const { LOCATION_COMPARISON_COORDIATE_ACCURACY } = process.env + + /** * This method removes all characters Pelias doesn't support. * Unfortunately, these characters not only don't match if they're found in the @@ -97,17 +100,18 @@ export const convertQSPToGeocoderArgs = ( /** * Compares two GeoJSON positions and returns if they are equal within 10m accuracy - * @param a One GeoJSON Position object - * @param b One GeoJSON Position Object + * @param a One GeoJSON Position object + * @param b One GeoJSON Position Object + * @param precision How many digits after the decimal point to use when comparing * @returns True if the positions describe the same place, false if they are different */ -export const arePointsRoughlyEqual = (a: Position, b: Position): boolean => { +export const arePointsRoughlyEqual = (a: Position, b: Position, precision: number = 4): boolean => { // 4 decimal places is approximately 10 meters, which is acceptable error const aRounded = a?.map((point: number): number => - parseFloat(point?.toFixed(4)) + parseFloat(point?.toFixed(precision)) ) const bRounded = b?.map((point: number): number => - parseFloat(point?.toFixed(4)) + parseFloat(point?.toFixed(precision)) ) return ( @@ -174,7 +178,8 @@ const filterOutDuplicateStops = ( // duplicate return arePointsRoughlyEqual( feature.geometry.coordinates, - otherFeature.geometry.coordinates + otherFeature.geometry.coordinates, + parseInt(LOCATION_COMPARISON_COORDIATE_ACCURACY || '') ) }) } From bc953332ec2dace81accda6b8aa5d24a5b6685fe Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Fri, 19 Apr 2024 13:35:06 -0400 Subject: [PATCH 3/6] chore: lint --- utils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils.ts b/utils.ts index 8cb7d87..0e211d1 100644 --- a/utils.ts +++ b/utils.ts @@ -32,7 +32,6 @@ const PREFERRED_LAYERS = ['venue', 'address', 'street', 'intersection'] const { LOCATION_COMPARISON_COORDIATE_ACCURACY } = process.env - /** * This method removes all characters Pelias doesn't support. * Unfortunately, these characters not only don't match if they're found in the @@ -105,7 +104,11 @@ export const convertQSPToGeocoderArgs = ( * @param precision How many digits after the decimal point to use when comparing * @returns True if the positions describe the same place, false if they are different */ -export const arePointsRoughlyEqual = (a: Position, b: Position, precision: number = 4): boolean => { +export const arePointsRoughlyEqual = ( + a: Position, + b: Position, + precision = 4 +): boolean => { // 4 decimal places is approximately 10 meters, which is acceptable error const aRounded = a?.map((point: number): number => parseFloat(point?.toFixed(precision)) From 6c41a19f792c083af9b9978cc0b77606b2b3f6e4 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Thu, 25 Apr 2024 13:50:12 -0400 Subject: [PATCH 4/6] address pr feedback --- env.example.yml | 2 +- serverless.yml | 2 +- utils.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/env.example.yml b/env.example.yml index 095f6a7..37992db 100644 --- a/env.example.yml +++ b/env.example.yml @@ -4,4 +4,4 @@ BUGSNAG_NOTIFIER_KEY: INSERT BUGSNAG NOTIFIER KEY HERE GEOCODERS: BACKUP_GEOCODERS: -LOCATION_COMPARISON_COORDIATE_ACCURACY: defaults to 4 (~10m). What accuracy to use when comparing if two locations are the same +LOCATION_COMPARISON_COORDINATE_PRECISION: defaults to 4 (~10m). What precision to use when comparing if two locations are the same diff --git a/serverless.yml b/serverless.yml index da12780..a9719f7 100644 --- a/serverless.yml +++ b/serverless.yml @@ -12,7 +12,7 @@ provider: GEOCODERS: ${self:custom.secrets.GEOCODERS} BACKUP_GEOCODERS: ${self:custom.secrets.BACKUP_GEOCODERS} BUGSNAG_NOTIFIER_KEY: ${self:custom.secrets.BUGSNAG_NOTIFIER_KEY} - LOCATION_COMPARISON_COORDIATE_ACCURACY: ${self:custom.secrets.LOCATION_COMPARISON_COORDIATE_ACCURACY, 4} + LOCATION_COMPARISON_COORDINATE_PRECISION: ${self:custom.secrets.LOCATION_COMPARISON_COORDINATE_PRECISION, 4} package: patterns: - pois.json diff --git a/utils.ts b/utils.ts index 0e211d1..e7f28ae 100644 --- a/utils.ts +++ b/utils.ts @@ -30,7 +30,7 @@ export type ServerlessResponse = { // Consts const PREFERRED_LAYERS = ['venue', 'address', 'street', 'intersection'] -const { LOCATION_COMPARISON_COORDIATE_ACCURACY } = process.env +const { LOCATION_COMPARISON_COORDINATE_PRECISION } = process.env /** * This method removes all characters Pelias doesn't support. @@ -182,7 +182,7 @@ const filterOutDuplicateStops = ( return arePointsRoughlyEqual( feature.geometry.coordinates, otherFeature.geometry.coordinates, - parseInt(LOCATION_COMPARISON_COORDIATE_ACCURACY || '') + !!LOCATION_COMPARISON_COORDINATE_PRECISION ? parseInt(LOCATION_COMPARISON_COORDINATE_PRECISION) : undefined ) }) } From 1fab805ce2281d897c848d6a51ed660e26b1b0f8 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Thu, 25 Apr 2024 13:53:31 -0400 Subject: [PATCH 5/6] chore: lint --- utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils.ts b/utils.ts index e7f28ae..3616975 100644 --- a/utils.ts +++ b/utils.ts @@ -182,7 +182,9 @@ const filterOutDuplicateStops = ( return arePointsRoughlyEqual( feature.geometry.coordinates, otherFeature.geometry.coordinates, - !!LOCATION_COMPARISON_COORDINATE_PRECISION ? parseInt(LOCATION_COMPARISON_COORDINATE_PRECISION) : undefined + LOCATION_COMPARISON_COORDINATE_PRECISION + ? parseInt(LOCATION_COMPARISON_COORDINATE_PRECISION) + : undefined ) }) } From 24c66dc1efca990b41652a3f26fcb336083dc65f Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Mon, 6 May 2024 16:49:21 +0200 Subject: [PATCH 6/6] refactor: address pr feedback --- env.example.yml | 2 +- serverless.yml | 2 +- utils.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/env.example.yml b/env.example.yml index 37992db..39e5b48 100644 --- a/env.example.yml +++ b/env.example.yml @@ -4,4 +4,4 @@ BUGSNAG_NOTIFIER_KEY: INSERT BUGSNAG NOTIFIER KEY HERE GEOCODERS: BACKUP_GEOCODERS: -LOCATION_COMPARISON_COORDINATE_PRECISION: defaults to 4 (~10m). What precision to use when comparing if two locations are the same +COORDINATE_COMPARISON_PRECISION_DIGITS: defaults to 4 (~10m). What precision to use when comparing if two locations are the same diff --git a/serverless.yml b/serverless.yml index a9719f7..08350b4 100644 --- a/serverless.yml +++ b/serverless.yml @@ -12,7 +12,7 @@ provider: GEOCODERS: ${self:custom.secrets.GEOCODERS} BACKUP_GEOCODERS: ${self:custom.secrets.BACKUP_GEOCODERS} BUGSNAG_NOTIFIER_KEY: ${self:custom.secrets.BUGSNAG_NOTIFIER_KEY} - LOCATION_COMPARISON_COORDINATE_PRECISION: ${self:custom.secrets.LOCATION_COMPARISON_COORDINATE_PRECISION, 4} + COORDINATE_COMPARISON_PRECISION_DIGITS: ${self:custom.secrets.COORDINATE_COMPARISON_PRECISION_DIGITS, 4} package: patterns: - pois.json diff --git a/utils.ts b/utils.ts index 3616975..d0692bf 100644 --- a/utils.ts +++ b/utils.ts @@ -30,7 +30,7 @@ export type ServerlessResponse = { // Consts const PREFERRED_LAYERS = ['venue', 'address', 'street', 'intersection'] -const { LOCATION_COMPARISON_COORDINATE_PRECISION } = process.env +const { COORDINATE_COMPARISON_PRECISION_DIGITS } = process.env /** * This method removes all characters Pelias doesn't support. @@ -182,8 +182,8 @@ const filterOutDuplicateStops = ( return arePointsRoughlyEqual( feature.geometry.coordinates, otherFeature.geometry.coordinates, - LOCATION_COMPARISON_COORDINATE_PRECISION - ? parseInt(LOCATION_COMPARISON_COORDINATE_PRECISION) + COORDINATE_COMPARISON_PRECISION_DIGITS + ? parseInt(COORDINATE_COMPARISON_PRECISION_DIGITS) : undefined ) })