travelHistory = d3.csv(DATA_URL, d => {
const RID = d.Route in ROUTE_IDS ? ROUTE_IDS[d.Route] : d.Route
const stationA = mileMarkers.find(s => s.RID === RID && s.CODE === d.Origin)
const stationB = mileMarkers.find(s => s.RID === RID && s.CODE === d.Destination)
let distance
if (!stationA || !stationB) {
console.log(`Station data missing for trip from ${d.Origin} to ${d.Destination} on ${d.Route}`)
distance = 0
} else {
distance = Math.abs(stationA.km - stationB.km) * 0.621371
}
return {
Distance: distance,
...d,
'Departure Time': d3.utcParse("%Y-%m-%dT%H:%M:%S")(d['Departure Time']),
'Arrival Time': d3.utcParse("%Y-%m-%dT%H:%M:%S")(d['Arrival Time'])
}
})