smarteta
Version:
Smart urban ETA estimator based on time, distance, vehicle type and real-world corrections
163 lines (125 loc) β’ 3.94 kB
Markdown
# π§ 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 β€οΈ