Documentation ¶
Overview ¶
Package gtfs provides gtfs related CRUD functionality, including DataSet and related operations
Index ¶
- Constants
- func Get12AmTime(date time.Time) time.Time
- func GetActiveServiceIds(db *sqlx.DB, dataSet *DataSet, serviceDate time.Time) ([]string, error)
- func GetScheduledTripIds(db *sqlx.DB, at time.Time, relevantFrom time.Time, relevantTo time.Time) (map[string]bool, error)
- func GetShapes(db *sqlx.DB, dataSetId int64, shapeIds []string) (map[string][]*Shape, []string, error)
- func GetStopTimeInstances(db *sqlx.DB, scheduleSlices []ScheduleSlice, dataSetId int64, tripIds []string) (map[string][]*StopTimeInstance, []string, []string, error)
- func MakeScheduleTime(timeAt12 time.Time, scheduleSeconds int) time.Time
- func RecordCalendar(calendar *Calendar, dsTx *DataSetTransaction) error
- func RecordCalendarDate(calendarDate *CalendarDate, dsTx *DataSetTransaction) error
- func RecordObservedStopTime(observation *ObservedStopTime, db *sqlx.DB) error
- func RecordShapes(shapes []*Shape, dsTx *DataSetTransaction) error
- func RecordStopTimes(stopTimes []*StopTime, dsTx *DataSetTransaction) error
- func RecordTripDeviation(tripDeviations []*TripDeviation, db *sqlx.DB) error
- func RecordTrips(trips []*Trip, dsTx *DataSetTransaction) error
- func SaveAndTerminateReplacedDataSet(tx *sqlx.Tx, ds *DataSet, now time.Time) error
- func SaveDataSet(tx *sqlx.Tx, ds *DataSet) error
- type Calendar
- type CalendarDate
- type DataSet
- type DataSetOperation
- type DataSetTransaction
- type ObservedStopTime
- type ScheduleSlice
- type Shape
- type StopTime
- type StopTimeInstance
- type Trip
- type TripDeviation
- type TripInstance
- type TripInstanceBatchQueryResults
Constants ¶
const (
MaximumScheduleSeconds int = 60 * 60 * 30
)
Variables ¶
This section is empty.
Functions ¶
func GetActiveServiceIds ¶ added in v0.1.3
GetActiveServiceIds retrieves the active serviceIds on provided serviceDate. both calendar and calendar_date are used
func GetScheduledTripIds ¶ added in v0.1.3
func GetScheduledTripIds(db *sqlx.DB, at time.Time, relevantFrom time.Time, relevantTo time.Time) (map[string]bool, error)
GetScheduledTripIds returns all map of trip_ids that are scheduled between relevantFrom and relevantTo at is used to retrieve the active dataSet
func GetShapes ¶
func GetShapes(db *sqlx.DB, dataSetId int64, shapeIds []string) (map[string][]*Shape, []string, error)
GetShapes collects Shape collections and returns results in ShapePtSequence order inside a map returns:
map with results keyed by shapeIds, slice of missing shapeIds (where no Shape records could be found)
func GetStopTimeInstances ¶
func GetStopTimeInstances(db *sqlx.DB, scheduleSlices []ScheduleSlice, dataSetId int64, tripIds []string) (map[string][]*StopTimeInstance, []string, []string, error)
GetStopTimeInstances collects StopTimeInstances and returns in order by tripID inside a map ArrivalDateTime and DepartureDateTime are populated from the best ScheduleSlice match from the trips first arrival time. If a ScheduleSlice match can't be found the StopTimeInstances are not included in the map result returns:
map with results keyed by tripId, slice of missing trip ids (where no StopTimeInstances could be found) slice of trip ids where no matching ScheduleSlice could be found for the trip
func MakeScheduleTime ¶
MakeScheduleTime produces a time from by adding seconds to a 12am date. Takes into account day light saving time
func RecordCalendar ¶
func RecordCalendar(calendar *Calendar, dsTx *DataSetTransaction) error
func RecordCalendarDate ¶
func RecordCalendarDate(calendarDate *CalendarDate, dsTx *DataSetTransaction) error
func RecordObservedStopTime ¶
func RecordObservedStopTime(observation *ObservedStopTime, db *sqlx.DB) error
RecordObservedStopTime saves ObservedStopTime into database
func RecordShapes ¶
func RecordShapes(shapes []*Shape, dsTx *DataSetTransaction) error
RecordShapes saves shapes to database in a batch
func RecordStopTimes ¶
func RecordStopTimes(stopTimes []*StopTime, dsTx *DataSetTransaction) error
RecordStopTimes saves stopTimes to database in batch
func RecordTripDeviation ¶ added in v0.1.3
func RecordTripDeviation(tripDeviations []*TripDeviation, db *sqlx.DB) error
RecordTripDeviation saves slice of TripDeviations into database in batch
func RecordTrips ¶
func RecordTrips(trips []*Trip, dsTx *DataSetTransaction) error
RecordTrips saves trips to database in batch
func SaveAndTerminateReplacedDataSet ¶
SaveAndTerminateReplacedDataSet updates all DataSet where now is between DataSet.SavedAt and DataSet.ReplacedAt and sets DataSet.ReplacedAt to one microsecond before now. ds is then saved with now as DataSet.SavedAt and the default DataSet.ReplacedAt date of 9999-12-31
Types ¶
type Calendar ¶
type Calendar struct { DataSetId int64 `db:"data_set_id"` ServiceId string `db:"service_id"` Monday int Tuesday int Wednesday int Thursday int Friday int Saturday int Sunday int StartDate *time.Time `db:"start_date"` EndDate *time.Time `db:"end_date"` }
Calendar contains data from a record in a gtfs calendar.txt file
type CalendarDate ¶
type CalendarDate struct { DataSetId int64 `db:"data_set_id"` ServiceId string `db:"service_id"` Date time.Time ExceptionType int `db:"exception_type"` }
CalendarDate contains data from a record in a gtfs calendar_dates.txt file
type DataSet ¶
type DataSet struct { Id int64 URL string // ETag is the ETag header if available from the source web site for the gtfs file. Is empty if not available ETag string `db:"e_tag"` // LastModifiedTimestamp is the unix epoch seconds the source web site provided for the last time the gtfs file was modified // is 0 if not available LastModifiedTimestamp int64 `db:"last_modified_timestamp"` DownloadedAt time.Time `db:"downloaded_at"` SavedAt *time.Time `db:"saved_at"` ReplacedAt *time.Time `db:"replaced_at"` }
DataSet encompasses a gtfs schedule available from a source at a point in time. The same source will be loaded over time. Each record from a gtfs file shares the DataSet.Id value as part of the primary key.
func GetAllDataSets ¶
GetAllDataSets retrieves all DataSets currently loaded
func GetDataSet ¶
GetDataSet retrieves DataSet with dataSetId
func GetDataSetAt ¶
GetDataSetAt retrieves the DataSet that was active at a time
func GetLatestDataSet ¶
GetLatestDataSet retrieves the latest DataSet that is active
type DataSetOperation ¶
DataSetOperation contains required data for operating on gtfs records owned by a DataSet
type DataSetTransaction ¶
DataSetTransaction contains required data for recording new gtfs records owned by a DataSet
type ObservedStopTime ¶
type ObservedStopTime struct { //ObservedTime is the time the vehicle movement was seen ObservedTime time.Time `db:"observed_time"` //StopId is the stopId the vehicle moved from StopId string `db:"stop_id"` //NextStopId is the stopId the vehicle moved to NextStopId string `db:"next_stop_id"` VehicleId string `db:"vehicle_id"` RouteId string `db:"route_id"` //ObservedAtStop is true when a gtfs-rt vehicle record indicated the vehicle was located at the stop the vehicle moved from ObservedAtStop bool `db:"observed_at_stop"` //ObservedAtNextStop is true when a gtfs-rt vehicle record indicated the vehicle was located at the stop the vehicle moved to ObservedAtNextStop bool `db:"observed_at_next_stop"` //TravelSeconds is the number of seconds the vehicle is assumed to have taken to move between the stops TravelSeconds int `db:"travel_seconds"` ScheduledSeconds *int `db:"scheduled_seconds"` //DataSetId identifies the DataSet used during this ObservedStopTime DataSetId int64 `db:"data_set_id" json:"data_set_id"` TripId string `db:"trip_id"` CreatedAt time.Time `db:"created_at"` }
ObservedStopTime contains details when a vehicle is observed to have transitioned between two stops, or assumed to have passed a two stops based on the subsequent vehicle positions indicating it passed two or more stops on a trip, in which case the travel time is interpolated primary key consists of ObservedTime, StopId, NextStopId, VehicleId
func (*ObservedStopTime) AssumedDepartTime ¶
func (ost *ObservedStopTime) AssumedDepartTime() int
AssumedDepartTime returns the time the vehicle is assumed to have departed the from stopId, this is calculated based on the last time the vehicle was observed at or before the from stopId
type ScheduleSlice ¶
ScheduleSlice contains a service date and a section of service time
func GetScheduleSlices ¶
func GetScheduleSlices(start time.Time, end time.Time) []ScheduleSlice
GetScheduleSlices produces array of schedule slices based on start and end times
type Shape ¶
type Shape struct { DataSetId int64 `db:"data_set_id" json:"data_set_id"` ShapeId string `db:"shape_id" json:"shape_id"` ShapePtLat float64 `db:"shape_pt_lat" json:"shape_pt_lat"` ShapePtLng float64 `db:"shape_pt_lon" json:"shape_pt_lon"` ShapePtSequence int `db:"shape_pt_sequence" json:"shape_pt_sequence"` ShapeDistTraveled *float64 `db:"shape_dist_traveled" json:"shape_dist_traveled"` }
Shape contains rows from the GTFS shapes.txt file
type StopTime ¶
type StopTime struct { DataSetId int64 `db:"data_set_id" json:"data_set_id"` TripId string `db:"trip_id" json:"trip_id"` StopSequence uint32 `db:"stop_sequence" json:"stop_sequence"` StopId string `db:"stop_id" json:"stop_id"` ArrivalTime int `db:"arrival_time" json:"arrival_time"` DepartureTime int `db:"departure_time" json:"departure_time"` ShapeDistTraveled float64 `db:"shape_dist_traveled" json:"shape_dist_traveled"` Timepoint int `db:"timepoint" json:"timepoint"` }
StopTime contains a record from a gtfs stop_times.txt file represents a scheduled arrival and departure at a stop.
type StopTimeInstance ¶
type Trip ¶
type Trip struct { DataSetId int64 `db:"data_set_id" json:"data_set_id"` TripId string `db:"trip_id" json:"trip_id"` RouteId string `db:"route_id" json:"route_id"` ServiceId string `db:"service_id" json:"service_id"` TripHeadsign *string `db:"trip_headsign" json:"trip_headsign"` TripShortName *string `db:"trip_short_name" json:"trip_short_name"` BlockId string `db:"block_id" json:"block_id"` ShapeId string `db:"shape_id" json:"shape_id"` StartTime int `db:"start_time" json:"start_time"` EndTime int `db:"end_time" json:"end_time"` TripDistance float64 `db:"trip_distance" json:"trip_distance"` }
Trip contains data from a gtfs trip definition in a trips.txt file
type TripDeviation ¶ added in v0.1.3
type TripDeviation struct { Id int64 CreatedAt time.Time `db:"created_at" json:"created_at"` DeviationTimestamp time.Time `db:"deviation_timestamp" json:"deviation_timestamp"` //TripProgress is the distance of the trip that has been traversed. //a negative number indicates a position on a prior trip to this one TripProgress float64 `db:"trip_progress" json:"trip_progress"` //DataSetId identifies the DataSet used when this TripDeviation was calculated DataSetId int64 `db:"data_set_id" json:"data_set_id"` TripId string `db:"trip_id" json:"trip_id"` VehicleId string `db:"vehicle_id" json:"vehicle_id"` AtStop bool `db:"at_stop" json:"at_stop"` Delay int `db:"delay"` }
type TripInstance ¶
type TripInstance struct { Trip StopTimeInstances []*StopTimeInstance `json:"stop_time_instances"` Shapes []*Shape `json:"shapes"` }
func (*TripInstance) ShapesBetweenDistances ¶
func (t *TripInstance) ShapesBetweenDistances(start float64, end float64) []*Shape
ShapesBetweenDistances returns slice of Shapes where Shape.ShapeDistTraveled is between start and end
type TripInstanceBatchQueryResults ¶
type TripInstanceBatchQueryResults struct { TripInstancesByTripId map[string]*TripInstance MissingTripIds []string ScheduleSliceOutOfRange []string MissingShapeIds []string }
TripInstanceBatchQueryResults provides results from batch querying trips tripIds that were not found (MissingTripIds) or where the schedule time was outside of date range (ScheduleSliceOutOfRange) can be logged
func GetTripInstances ¶
func GetTripInstances(db *sqlx.DB, at time.Time, relevantFrom time.Time, relevantTo time.Time, tripIds []string) (*TripInstanceBatchQueryResults, error)
GetTripInstances loads trip instances with tripIds. Appropriate scheduleDates are selected where trip start and end times are within range of relevantFrom and relevantTo