56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package types
|
|
|
|
import (
|
|
"iter"
|
|
"time"
|
|
)
|
|
|
|
type Trip struct {
|
|
*Route
|
|
Stops []*StopTime `json:"stops" csv:"stops"`
|
|
RouteId string `json:"route_id" csv:"route_id"`
|
|
ServiceId string `json:"service_id" csv:"service_id"`
|
|
TripId string `json:"trip_id" csv:"trip_id"`
|
|
TripHeadsign string `json:"trip_headsign" csv:"trip_headsign"`
|
|
TripShortName string `json:"trip_short_name" csv:"trip_short_name"`
|
|
}
|
|
|
|
func (t *Trip) GetDirectPossibleDestinations(stop *Stop, when time.Time) iter.Seq[*StopTime] {
|
|
return func(yield func(*StopTime) bool) {
|
|
started := false
|
|
for _, st := range t.Stops {
|
|
if !started {
|
|
if st.StopId == stop.StopId && st.PickupType == 0 {
|
|
started = true
|
|
}
|
|
continue
|
|
}
|
|
if started && st.DropOffType == 0 && st.DepartsAfter(when) {
|
|
if !yield(st) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (t *Trip) SetRoute(route *Route) {
|
|
t.Route = route
|
|
}
|
|
|
|
func (t *Trip) AddStopTime(stopTime *StopTime) {
|
|
if t.Stops == nil {
|
|
t.Stops = make([]*StopTime, 0)
|
|
}
|
|
t.Stops = append(t.Stops, stopTime)
|
|
}
|
|
|
|
func (t *Trip) Has(stop *Stop) (*StopTime, bool) {
|
|
for _, st := range t.Stops {
|
|
if st.StopId == stop.StopId {
|
|
return st, true
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|