Skip to content

Commit

Permalink
add LOCATION_COMPARISON_COORDIATE_ACCURACY setting
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup committed Apr 19, 2024
1 parent 455d008 commit 9c468a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion env.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Stringified JSON Array of OTP-UI `GeocoderConfig`s>
BACKUP_GEOCODERS: <Stringified JSON Array of OTP-UI `GeocoderConfig`'s. Same length and order as GEOCODERS>
BACKUP_GEOCODERS: <Stringified JSON Array of OTP-UI `GeocoderConfig`'s. Same length and order as GEOCODERS>

LOCATION_COMPARISON_COORDIATE_ACCURACY: defaults to 4 (~10m). What accuracy to use when comparing if two locations are the same
1 change: 1 addition & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export type ServerlessResponse = {
// Consts
const PREFERRED_LAYERS = ['venue', 'address', 'street', 'intersection']

const { LOCATION_COMPARISON_COORDIATE_ACCURACY } = process.env


Check failure on line 35 in utils.ts

View workflow job for this annotation

GitHub Actions / test-lambda-function

Delete `⏎`
/**
* This method removes all characters Pelias doesn't support.
* Unfortunately, these characters not only don't match if they're found in the
Expand Down Expand Up @@ -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 => {

Check failure on line 108 in utils.ts

View workflow job for this annotation

GitHub Actions / test-lambda-function

Replace `a:·Position,·b:·Position,·precision:·number·=·4` with `⏎··a:·Position,⏎··b:·Position,⏎··precision:·number·=·4⏎`

Check failure on line 108 in utils.ts

View workflow job for this annotation

GitHub Actions / test-lambda-function

Type number trivially inferred from a number literal, remove type annotation
// 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 (
Expand Down Expand Up @@ -174,7 +178,8 @@ const filterOutDuplicateStops = (
// duplicate
return arePointsRoughlyEqual(
feature.geometry.coordinates,
otherFeature.geometry.coordinates
otherFeature.geometry.coordinates,
parseInt(LOCATION_COMPARISON_COORDIATE_ACCURACY || '')
)
})
}
Expand Down

0 comments on commit 9c468a9

Please sign in to comment.