UNPKG

smarteta

Version:

Smart urban ETA estimator based on time, distance, vehicle type and real-world corrections

163 lines (125 loc) β€’ 3.94 kB
# 🧠 smart-eta **Smart ETA Estimator for Urban and Intercity Deliveries** Estimate average travel times in minutes between two GPS coordinates based on: - πŸš— Vehicle type (car / scooter) - πŸ•’ Time of day - πŸ“… Day of the week - πŸ“ Distance impact - πŸš₯ Urban delays (traffic lights, parking) - πŸ“Š Optional real-world data for calibration - πŸ”„ Smart urban/intercity classification --- ## ✨ Features - βœ… Works entirely offline – no API calls! - πŸš΄β€β™‚οΈ Optimized for delivery use cases inside cities - πŸ“‰ Learns from historical data and self-calibrates - 🧠 Understands how real-world urban traffic behaves - πŸ“¦ Lightweight and easy to integrate --- ## πŸ“¦ Installation ```bash npm install smart-eta # or pnpm add smart-eta # or yarn add smart-eta ``` --- ## πŸš€ Quick Start ```ts import { estimateSmartETA } from 'smart-eta'; const result = estimateSmartETA({ startLat: 31.25181, startLng: 34.7913, endLat: 31.2452, endLng: 34.7928, vehicleType: 'scooter' }); console.log(result); // { min: 2.5, avg: 3.1, max: 3.8 } ``` --- ## πŸ“˜ API Reference ### `estimateSmartETA(input: EstimateInput): EstimateResult` #### EstimateInput | Field | Type | Description | |----------------|----------------------------------|--------------------------------------------------| | `startLat` | `number` | Start point latitude | | `startLng` | `number` | Start point longitude | | `endLat` | `number` | End point latitude | | `endLng` | `number` | End point longitude | | `vehicleType` | `'car'` \| `'scooter'` | Type of vehicle used | | `now?` | `Date` | Optional. Defaults to current system time | | `urban?` | `boolean` | Optional override for urban/intercity logic | | `historicalData?` | `HistoricalEntry[]` | Optional array of real-world ETA samples | #### EstimateResult ```ts { min: number; // Lower bound (90% of avg or at least 2 min) avg: number; // Average estimated travel time max: number; // Upper bound (110% of avg or at least 2.1 min) } ``` #### HistoricalEntry ```ts { fromLat: number; fromLng: number; toLat: number; toLng: number; actualMinutes: number; } ``` --- ## πŸ“ˆ How Accuracy Works Internally, the ETA is affected by: 1. **Base speed** (by hour + vehicle type) 2. **Day of week** (Wednesday–Thursday are slower) 3. **Short-distance penalty** (under 2km) 4. **Parking & traffic light buffer** (car vs scooter) 5. **Minimum enforced time** (2 min floor) 6. **Historical data regression** (optional) 7. **Urban/intercity auto-detection** by effective speed 8. **Urban = Γ—2 / Intercity = Γ—0.8 correction factor** 9. **Β±10% margin of uncertainty** --- ## πŸ”¬ Example with Historical Data ```ts const eta = estimateSmartETA({ startLat: 31.25, startLng: 34.79, endLat: 31.24, endLng: 34.80, vehicleType: 'car', historicalData: [ { fromLat: 31.25, fromLng: 34.79, toLat: 31.24, toLng: 34.80, actualMinutes: 5.2 }, { fromLat: 31.26, fromLng: 34.81, toLat: 31.23, toLng: 34.77, actualMinutes: 6.0 } ] }); ``` --- ## πŸ›  Use Cases - Logistics & delivery apps - Courier ETA prediction - Route simulations - Driver performance analysis --- ## πŸ§ͺ Future Ideas - πŸ“‘ Integration with real-time traffic APIs (optional) - πŸ“ Auto-detect urban zones from OSM boundaries - πŸ” Learning-based adaptive weighting from live data --- ## βš– License MIT – use freely, improve openly, attribute respectfully ❀️