Skip to main content

Historical Routes

RESTful API endpoints for querying historical time-series traffic data and temporal aggregations from TimescaleDB.

Base Pathโ€‹

/api/historical

Endpoints Summaryโ€‹

MethodEndpointDescription
GET/trafficHistorical traffic data
GET/weatherHistorical weather data
GET/air-qualityHistorical AQI data
GET/patternsHistorical patterns

Endpointsโ€‹

GET /api/historical/trafficโ€‹

Get historical traffic metrics.

Query Parameters:

ParameterTypeRequiredDescription
roadSegmentstringNoRoad segment ID
fromstringYesStart date (ISO 8601)
tostringYesEnd date (ISO 8601)
intervalstringNoAggregation: hour, day, week

Response:

{
"success": true,
"data": [
{
"timestamp": "2025-11-28T08:00:00.000Z",
"averageSpeed": 28.5,
"vehicleCount": 1250,
"congestionLevel": "high"
},
{
"timestamp": "2025-11-28T09:00:00.000Z",
"averageSpeed": 32.1,
"vehicleCount": 980,
"congestionLevel": "moderate"
}
],
"meta": {
"interval": "hour",
"dataPoints": 24
}
}

GET /api/historical/patternsโ€‹

Get historical traffic pattern analysis.

Query Parameters:

ParameterTypeDescription
dayOfWeeknumberDay of week (0=Sunday)
hourOfDaynumberHour (0-23)
roadSegmentstringRoad segment ID

Response:

{
"success": true,
"data": {
"averageSpeed": 28.5,
"averageVehicleCount": 1150,
"sampleCount": 52,
"standardDeviation": 5.2,
"percentiles": {
"p25": 24.0,
"p50": 28.5,
"p75": 33.0,
"p95": 42.0
}
}
}

Time Range Limitsโ€‹

PeriodMax RangeAggregation
Real-time24 hoursNone
Short-term7 daysHourly
Medium-term30 daysDaily
Long-term365 daysWeekly

Referencesโ€‹