-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathbusStop.ts
41 lines (39 loc) · 1.15 KB
/
busStop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {
GtfsRideStopPydanticModel,
GtfsStopPydanticModel,
} from 'open-bus-stride-client/openapi/models'
import { GtfsRideWithRelatedPydanticModel } from 'open-bus-stride-client'
import moment from 'moment'
import { Coordinates } from 'src/model/location'
export type BusStop = {
date: Date
key: string
stopId: number
routeId: number
stopSequence: number
name: string
code: string
location: Coordinates
minutesFromRouteStartTime: number
}
export function fromGtfsStop(
gtfsRideStop: GtfsRideStopPydanticModel,
gtfsStop: GtfsStopPydanticModel,
ride: GtfsRideWithRelatedPydanticModel,
): BusStop {
const { arrivalTime } = gtfsRideStop
const minutesFromRouteStartTime = arrivalTime
? moment(arrivalTime).diff(ride.startTime, 'minutes')
: 0
return {
date: gtfsStop.date,
key: gtfsRideStop.id.toString(),
stopId: gtfsRideStop.gtfsStopId,
routeId: ride.gtfsRouteId || 0,
stopSequence: gtfsRideStop.stopSequence || 0,
name: `${gtfsStop.name} (${gtfsStop.city})`,
code: gtfsStop.code.toString(),
location: { latitude: gtfsStop.lat || 0, longitude: gtfsStop.lon || 0 },
minutesFromRouteStartTime,
}
}