distance calculations ¶
background ¶
System has a need to calculate distance information between addresses.
Address table has latitude/longitude pairs along with normalizaed address information. This information is pulled from mapbox.
code ¶
Command core:travel-distance will calculate driving distance and driving time estimates from mapbox by iterating through a collection of to/from address pairs.
core:travel-distance {--user=all} {--to=all} {--sleep=1} {--max-mileage=150}
When iterating over one or more user addresses, the ‘to’ parameter is inspected. One or more hospital site addresses will be paired against the user address.
The lat/lon of the pair will be compared with a distance estimating function,
and pairs that are under the ‘max-mileage’ parameter will be calculated.
Pairs that exceed the max-mileage estimate will be skipped. This will prevent
generally unhelpful values from being calculated (saving time and api calls) -
knowing that the drive time from Connecticut to Tennessee is 11 hours
generally hot helpful for the ‘drive time’ use case.
When a site address is updated, the system will attempt to update distances table with the new site address against all doctor pairs (subject to the max-mileage estimate).
When a user address is updated, the system will attempt to update distances table with the new user address against all hospital address pairs (subject to the max-mileage estimate).
When updating a user or site address distance combination, the previous distance information is deleted before the api call is made. This was to avoid a new known address displaying previously calculated and potentially ‘wrong’ information.
If the estimated mileage is over the cutoff range, we’ll store just the estimated mileage and a -1 in the ‘seconds’ time. This will indicate that the mileage is rough ‘great circle’ estimate.
config ¶
config/core.php has ‘max-mileage-estimate’ which is referenced via
```php config(‘core.max-mileage-estimate’) ````
The default value is 150, but can be overridden with an environment key of MAX_MILEAGE_ESTIMATE