planner
This commit is contained in:
46
pkg/types/trip.go
Normal file
46
pkg/types/trip.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user