UpdaterAgent calculates ETAs and detects delays using a hybrid routing approach that keeps API costs low without sacrificing accuracy. The primary engine is OSRM (OpenStreetMap Routing Machine), a self-hosted, zero-cost router. Google Maps is called only when OSRM produces an unrealistic result or when a truck is meaningfully behind schedule. Additional fallbacks — Valhalla and HERE Maps — are available if Google Maps is unavailable.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ShohjahonSohibov/repo-for-agent/llms.txt
Use this file to discover all available pages before exploring further.
Routing strategy
The routing decision is made per ELD position check-in using the following priority order:Call OSRM (primary)
Every check-in calls OSRM first. OSRM is self-hosted and free, so there is no per-call cost. It returns a distance in meters and a duration in seconds for the driving route from the truck’s current GPS position to the delivery stop.
Validate the OSRM result
The OSRM distance is compared against the straight-line (Haversine) distance between the two points. If
osrmDistance > straightLineDistance × 2, the route is considered unrealistic (for example, a ferry crossing or off-road path) and OSRM is discarded.Compute deviation
The remaining duration from OSRM is compared against the time available before the delivery appointment:
| deviationPct | TripStatus | Google Maps called? |
|---|---|---|
| ≤ 10% | OnSchedule | No — ETA from OSRM |
| 10–25% | Behind | Yes, if cooldown expired |
| > 25% | Critical | Yes, if cooldown expired |
Call Google Maps (conditional fallback)
Google Maps is called only when a truck is
Behind or Critical and the per-truck 30-minute cooldown has expired. If the same truck was already charged a Google call within the last 30 minutes, the previous ETA is reused.All Google Maps calls are logged to GoogleMapsApiCallLog with endpoint, timestamp, and estimated cost for billing visibility.OSRM
OSRM (Open Source Routing Machine) is the primary routing engine. It is deployed as a self-hosted service using OpenStreetMap road data.- Auth: None — internal network only
- Endpoint:
GET /route/v1/driving/{lon,lat};{lon,lat}?overview=false - Returns: Distance (meters) + duration (seconds)
- Cost: Free
OnSchedule trucks and as the deviation baseline for Behind/Critical trucks.
Google Maps
Google Maps is the paid fallback for routing and geocoding. All calls are rate-limited (50 requests/second) and tracked inGoogleMapsApiCallLog.
- Auth: API key in
appsettings.json - Capabilities: Route calculation, geocoding, reverse geocoding, distance matrix
- Cost: Per-call billing — calls are minimized by the OSRM-first strategy and the 30-minute cooldown
Valhalla and HERE Maps
Valhalla and HereRouting serve as secondary fallbacks if Google Maps is unavailable.| Engine | Auth | Self-hosted |
|---|---|---|
| Valhalla | None | Optional |
| HereRouting | API key | No (cloud service) |
CalculateRouteAsync interface as OSRM and Google Maps, so the routing layer can swap between them without changing business logic.
Geocoding
Delivery addresses must have latitude and longitude coordinates before OSRM can route to them. UpdaterAgent geocodes addresses lazily — the first time a truck routes to an address, its coordinates are resolved and stored permanently.Geocoding flow
Check stored coordinates
If
Address.Lat and Address.Lng are already set, no geocoding call is made. The coordinates stored at import time are reused for all future routing to that address.Call Nominatim (primary geocoder)
Nominatim is the OpenStreetMap geocoder — free, no API key required.On success, coordinates are written back to the
- Endpoint:
GET /search?q={address}&format=json&limit=1 - Auth: None
- Cost: Free
addresses table. The geocoding cost for any given address is paid exactly once.The geocoding result is persisted to
addresses.lat and addresses.lng after the first successful lookup. Subsequent routing calls for the same address skip geocoding entirely.GeoNames — timezone lookup
GeoNames provides timezone resolution for coordinates. It is called on-demand when UpdaterAgent needs to express appointment times or ETAs in the local timezone of a delivery address.- Auth: None
- Cost: Free
ETA calculation
ETA is calculated per ELD position check-in using the routing result:EldPosition entity and surfaced via the Update Board and load detail endpoints.
Geocode an address on demand
Configuration reference
All routing and geocoding settings belong inappsettings.json (and environment-specific overrides):
| Setting | Default | Effect |
|---|---|---|
DeviationWarningPct | 10 | Below this threshold → OnSchedule, no Google call |
DeviationCriticalPct | 25 | Between warning and this → Behind; above → Critical |
CooldownMinutes | 30 | Minimum minutes between Google calls for the same truck |