Documentation
¶
Index ¶
- func GetDateInterval(dayCount uint, startDateTime time.Time) (Date, Date)
- type Agency
- type Bearing
- type Calendar
- type CalendarDate
- type Date
- type ExceptionType
- type Feed
- type FeededService
- type Fetcher
- func (f Fetcher) GetAllAgencies() ([]Agency, error)
- func (f Fetcher) GetAllStops() ([]Stop, error)
- func (f Fetcher) GetAllTrips() ([]Trip, error)
- func (f Fetcher) GetFeed(feedId string) (Feed, error)
- func (f Fetcher) GetFeededServiceIdTrips(feededService FeededService) ([]Trip, error)
- func (f Fetcher) GetFeeds() ([]Feed, error)
- func (f Fetcher) GetRealTrainSights(obsPoint Point, startDate Date, endDate Date) ([]RealTrainSight, error)
- func (f Fetcher) GetRoute(feedId string, routeId string) (Route, error)
- func (f Fetcher) GetServicesBetweenDates(startDate time.Time, endDate time.Time) ([]ServiceDay, error)
- func (f Fetcher) GetServicesOnDate(date time.Time) ([]ServiceDay, error)
- func (f *Fetcher) GetSightsFromTrip(trip Trip, date Date, lateTime time.Duration) ([]RealMovingTrainSight, Trip, error)
- func (f *Fetcher) GetSightsFromTripKey(feedId string, tripId string, date Date, lateTime time.Duration) ([]RealMovingTrainSight, Trip, error)
- func (f Fetcher) GetStop(feedId string, stopId string) (Stop, error)
- func (f Fetcher) GetStopTimesAtStop(feedId string, stopId string) ([]StopTime, error)
- func (f Fetcher) GetStopsLike(name string) ([]Stop, error)
- func (f Fetcher) GetTrip(feedId string, tripId string) (Trip, error)
- func (f Fetcher) GetTripsContaining(pt Point) ([]Trip, error)
- func (f Fetcher) GetTripsInsidePointInterval(pt1 Point, pt2 Point) ([]Trip, error)
- func (f Fetcher) GetTripsWithIntersection(minLat float64, maxLat float64, minLon float64, maxLon float64) ([]Trip, error)
- func (f Fetcher) LoadDatabase(config LoaderConfig) error
- type FetcherConfig
- type InterpolationPoint
- type LoaderConfig
- type LoaderConfigEntry
- type LocationType
- type MovingTrainSight
- type Point
- type RealMovingTrainSight
- type RealTrainSight
- type Route
- type RouteType
- type ServiceDay
- type ServiceType
- type Stop
- type StopTime
- type TrainSight
- type Trip
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Agency ¶
type Agency struct {
FeedId string `csv:"-" gorm:"primaryKey;uniqueIndex:pk_agency" json:"feed_id"`
AgencyId string `gorm:"primaryKey;uniqueIndex:pk_agency" csv:"agency_id" json:"agency_id"`
AgencyName string `csv:"agency_name" json:"name"`
AgencyUrl string `csv:"agency_url"`
AgencyTimezone string `csv:"agency_timezone"`
AgencyLang string `csv:"agency_lang"`
}
type Calendar ¶
type Calendar struct {
FeedId string `gorm:"primaryKey;uniqueIndex:pk_calendar" json:"feed_id"`
ServiceId string `gorm:"primaryKey;uniqueIndex:pk_calendar" csv:"service_id" json:"service_id"`
Monday bool `csv:"monday" json:"monday"`
Tuesday bool `csv:"tuesday" json:"tuesday"`
Wednesday bool `csv:"wednesday" json:"wednesday"`
Thursday bool `csv:"thursday" json:"thursday"`
Friday bool `csv:"friday" json:"friday"`
Saturday bool `csv:"saturday" json:"saturday"`
Sunday bool `csv:"sunday" json:"sunday"`
CsvStartDate string `gorm:"-:all" csv:"start_date" json:"-"` //YYYYmmdd
CsvEndDate string `gorm:"-:all" csv:"end_date" json:"-"` //YYYYmmdd
StartDate time.Time `json:"start_date"`
EndDate time.Time `json:"end_date"`
CalendarDates []CalendarDate `gorm:"foreignKey:FeedId,ServiceId;references:FeedId,ServiceId"`
}
type CalendarDate ¶
type CalendarDate struct {
FeedId string `csv:"-" gorm:"primaryKey;uniqueIndex:pk_calendardate" json:"feed_id"`
ServiceId string `gorm:"primaryKey;uniqueIndex:pk_calendardate" csv:"service_id" json:"service_id"`
Date time.Time `csv:"-" gorm:"primaryKey;uniqueIndex:pk_calendardate" json:"date"`
CsvDate string `csv:"date" gorm:"-:all" json:"-"` //YYYYmmdd
ExceptionType ExceptionType `csv:"exception_type" json:"exception_type"` //1=added, 2=removed
}
type ExceptionType ¶
type ExceptionType uint
const ( ExceptionTypeServiceAdded ExceptionType = 1 ExceptionTypeServiceRemoved ExceptionType = 2 )
type Feed ¶
type Feed struct {
DisplayName string `csv:"-" json:"display_name"` //added by us
FeedId string `csv:"-" gorm:"primaryKey;uniqueIndex:pk_feed" json:"feed_id"`
PublisherName string `csv:"feed_publisher_name" json:"publisher_name"`
PublisherUrl string `csv:"feed_publisher_url" json:"publisher_url"`
FeedLang string `csv:"feed_lang" json:"feed_lang"`
DefaultLang string `csv:"default_lang" json:"default_lang"`
Version string `csv:"feed_version" json:"version"`
ContactEmail string `csv:"feed_contact_email" json:"contact_email"`
ContactUrl string `csv:"feed_contact_url" json:"contact_url"`
}
type FeededService ¶
A FeededService represents a combined feed ID and service ID.
type Fetcher ¶
type Fetcher struct {
Config FetcherConfig
// contains filtered or unexported fields
}
A Fetcher is a wrapper around a DB connection.
func NewFetcher ¶
func (Fetcher) GetAllAgencies ¶
func (Fetcher) GetAllStops ¶
GetAllStops returns all the stops in the DB.
func (Fetcher) GetAllTrips ¶
GetAllTrips fetches all the trips in the DB by batches and returns them.
func (Fetcher) GetFeededServiceIdTrips ¶
func (f Fetcher) GetFeededServiceIdTrips(feededService FeededService) ([]Trip, error)
GetFeededServiceIdTrips returns all trips that run on the given service
func (Fetcher) GetRealTrainSights ¶
func (f Fetcher) GetRealTrainSights(obsPoint Point, startDate Date, endDate Date) ([]RealTrainSight, error)
Fetches train sights at an observation point between starting at startDate's services and endDate (including endDate's GTFS services)
func (Fetcher) GetServicesBetweenDates ¶
func (f Fetcher) GetServicesBetweenDates(startDate time.Time, endDate time.Time) ([]ServiceDay, error)
GetServicesBetweenDates retuns all services that are active between the given dates.
func (Fetcher) GetServicesOnDate ¶
func (f Fetcher) GetServicesOnDate(date time.Time) ([]ServiceDay, error)
GetServicesOnDate returns all services that are active on a given date.
func (*Fetcher) GetSightsFromTrip ¶
func (f *Fetcher) GetSightsFromTrip(trip Trip, date Date, lateTime time.Duration) ([]RealMovingTrainSight, Trip, error)
GetSightsFromTrip gets the sights that are visible while riding the given trip on a given date NOTE: does not check if the trip is actually running on that day
func (*Fetcher) GetSightsFromTripKey ¶
func (f *Fetcher) GetSightsFromTripKey(feedId string, tripId string, date Date, lateTime time.Duration) ([]RealMovingTrainSight, Trip, error)
GetSightsFromTripKey gets the sights that are visible while riding the given trip on a given date NOTE: does not check if the trip is actually running on that day
func (Fetcher) GetStopTimesAtStop ¶
GetStopTimesAtStop returns all the StopTimes related to the given Stop.
func (Fetcher) GetTripsContaining ¶
GetTripsContaining returns all trips whose bounding box contains the given point
func (Fetcher) GetTripsInsidePointInterval ¶
GetTripsInsidePointInterval returns all trips whose bounding box intersects with the bounding box formed by the 2 given points.
func (Fetcher) GetTripsWithIntersection ¶
func (f Fetcher) GetTripsWithIntersection(minLat float64, maxLat float64, minLon float64, maxLon float64) ([]Trip, error)
GetTripsWithIntersection returns all trips whose bounding box intersects with the given bounding box.
func (Fetcher) LoadDatabase ¶
func (f Fetcher) LoadDatabase(config LoaderConfig) error
LoadDatabase builds a database from the given LoaderConfig into the given file.
type FetcherConfig ¶
type FetcherConfig struct {
TimeZone string //https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
OutOfBoundsGraceAbsolute float64
OutOfBoundsGracePercentage float64
BearingMinThreshold Bearing //anything below this will be not be considered as much
BearingMaxThreshold Bearing //anything above this will be more favorably considered
DatabaseOutOfBoundsGraceDegrees float64
CloseHeavyRailStationThreshold float64 //kilometers
CloseTramStationThreshold float64 //kilometers
}
A FetcherConfig represents the parameters used for a fetcher.
func NewDefaultConfig ¶
func NewDefaultConfig() FetcherConfig
type InterpolationPoint ¶
an InterpolationPoint is a point+time combination.
type LoaderConfig ¶
type LoaderConfig struct {
DatabasePath string `json:"db_path"`
Contents []LoaderConfigEntry `json:"contents"`
}
a LoaderConfig represents a config used to load GTFS feeds into a DB.
type LoaderConfigEntry ¶
type LoaderConfigEntry struct {
Active bool `json:"active"`
FeedURL string `json:"feed_url"`
FetchIntervalHours *uint `json:"fetch_interval_hours"` //0 = always fetch, null = always rely on local file
DatabaseFileName string `json:"db_filename"`
DisplayName string `json:"display_name"`
}
a LoaderConfigEntry contains info about a specific GTFS feed and how it should be loaded.
type LocationType ¶
type LocationType int
const ( LocationTypePlatform LocationType = iota LocationTypeStation LocationTypeEntranceExit LocationTypeGeneric LocationTypeBoardingArea )
type MovingTrainSight ¶
type MovingTrainSight struct {
ServiceId string `json:"service_id"`
TripId string `json:"trip_id"`
FeedId string `json:"feed_id"`
Feed *Feed `json:"feed"`
FirstSt StopTime `json:"first_st"`
LastSt StopTime `json:"last_st"`
Trip Trip `json:"trip"`
RouteName string `json:"route_name"`
PassingInterPoint InterpolationPoint `json:"passing_interpolation_point"`
Distance float64 `json:"distance_km"` //distance in kilometers
}
a MovingTrainSight represents a train sight while aboard a given train, but does NOT contain date/time information.
type Point ¶
func (Point) GetBearingFrom ¶
type RealMovingTrainSight ¶
type RealMovingTrainSight struct {
MovingTrainSight MovingTrainSight `json:"sight"`
Timestamp time.Time `json:"timestamp"`
Date time.Time `json:"date"`
}
a RealMovingTrainSight contains a MovingTrainSight as well as date/time information.
type RealTrainSight ¶
type RealTrainSight struct {
TrainSight TrainSight `json:"sight"`
Timestamp time.Time `json:"timestamp"`
Date time.Time `json:"date"`
}
type Route ¶
type Route struct {
Feed Feed `csv:"-" gorm:"foreignKey:FeedId" json:"feed"`
FeedId string `csv:"-" gorm:"primaryKey;uniqueIndex:pk_route" json:"feed_id"`
RouteId string `gorm:"primaryKey;uniqueIndex:pk_route" csv:"route_id" json:"route_id"`
RouteShortName string `csv:"route_short_name" json:"short_name"`
RouteLongName string `csv:"route_long_name" json:"long_name"`
RouteDesc string `csv:"route_desc" json:"description"`
RouteType RouteType `csv:"route_type" json:"type"` //Basically: 0=tram,1=subway,2=heavy rail, 3=Bus, other=not rail (see docs for more info)
RouteColor string `csv:"route_color" json:"color"`
RouteTextColor string `csv:"route_text_color" json:"text_color"`
Trips []Trip `csv:"-" gorm:"foreignKey:RefRouteId,FeedId;references:RouteId,FeedId" json:"trips"`
AgencyId string `csv:"agency_id" json:"agency_id"`
Agency Agency `csv:"-" gorm:"foreignKey:FeedId,AgencyId;references:FeedId,AgencyId" json:"agency"`
}
type ServiceDay ¶
type ServiceDay struct {
Date time.Time `gorm:"primaryKey;uniqueIndex:pk_servicedays"`
FeedId string `gorm:"primaryKey;uniqueIndex:pk_servicedays"`
ServiceId string `gorm:"primaryKey;uniqueIndex:pk_servicedays"`
}
func (ServiceDay) GetFeededService ¶
func (s ServiceDay) GetFeededService() FeededService
type ServiceType ¶
type ServiceType uint
const ( ServiceTypeScheduled ServiceType = iota ServiceTypeNotPossible ServiceTypeMustPhone ServiceTypeMustCoordinateWithDriver )
type Stop ¶
type Stop struct {
// Feed Feed `csv:"-" gorm:"foreignKey:FeedId;references:FeedId" json:"feed"`
Feed Feed `csv:"-" gorm:"foreignKey:FeedId" json:"feed"`
FeedId string `csv:"-" gorm:"primaryKey;uniqueIndex:pk_stop" json:"feed_id"`
StopId string `csv:"stop_id" gorm:"primaryKey;uniqueIndex:pk_stop" json:"stop_id"`
StopCode string `csv:"stop_code" json:"stop_code"`
StopName string `csv:"stop_name" json:"stop_name"`
TtsStopName string `csv:"tts_stop_name" json:"tts_stop_name"`
StopDesc string `csv:"stop_desc" json:"stop_desc"`
StopUrl string `csv:"stop_url" json:"stop_url"`
StopLat float64 `csv:"-" json:"lat"`
StopLon float64 `csv:"-" json:"lon"`
StopLatString string `csv:"stop_lat" json:"-"`
StopLonString string `csv:"stop_lon" json:"-"`
LocationType *LocationType `csv:"location_type" json:"location_type"` // 0=Stop/platform, 1=Station, 2=Entrance/exit, 3=Generic, 4=Boarding area
CsvParentStationId string `gorm:"-:all" csv:"parent_station" json:"-"`
ParentStationId *string `csv:"-" json:"-"`
//station hierarchy removed because FK constraint isn't required by the spec, TODO check for breaking changes
ParentStation *Stop `csv:"-" gorm:"foreignKey:ParentStationId,FeedId;references:StopId,FeedId" json:"parent_station"`
ChildStations []Stop `csv:"-" gorm:"foreignKey:ParentStationId,FeedId;references:StopId,FeedId" json:"child_stations"`
StopTimes []StopTime `csv:"-" gorm:"foreignKey:FeedId,StopId;references:FeedId,StopId" json:"stop_times"`
}
type StopTime ¶
type StopTime struct {
FeedId string `csv:"-" gorm:"primaryKey;uniqueIndex:pk_stoptime" json:"feed_id"`
TripId string `gorm:"primaryKey;uniqueIndex:pk_stoptime" csv:"trip_id" json:"trip_id"`
CsvArrivalTime string `gorm:"-:all" csv:"arrival_time" json:"-"` //hh:mm:ss
CsvDepartureTime string `gorm:"-:all" csv:"departure_time" json:"-"` //hh:mm:ss
ArrivalTime time.Time `csv:"-" json:"arrival_time"`
DepartureTime time.Time `csv:"-" json:"departure_time"`
StopId string `csv:"stop_id" json:"stop_id"`
Stop *Stop `csv:"-" gorm:"foreignKey:FeedId,StopId" json:"stop"`
Trip *Trip `csv:"-" gorm:"foreignKey:FeedId,TripId" json:"trip"`
StopSequence uint `gorm:"primaryKey;uniqueIndex:pk_stoptime" csv:"stop_sequence" json:"stop_sequence"`
StopHeadsign string `csv:"stop_headsign" json:"stop_headsign"`
PickupType ServiceType `csv:"pickup_type" json:"pickup_type"`
DropOffType ServiceType `csv:"pickup_type" json:"dorp_off_type"`
}
type TrainSight ¶
type TrainSight struct {
ServiceId string `json:"service_id"`
TripId string `json:"trip_id"`
FeedId string `json:"feed_id"`
Feed *Feed `json:"feed"`
StBefore StopTime `json:"st_before"`
StAfter StopTime `json:"st_after"`
FirstSt StopTime `json:"first_st"`
LastSt StopTime `json:"last_st"`
Trip Trip `json:"trip"`
RouteName string `json:"route_name"`
// contains filtered or unexported fields
}
copying the types from previous implementation
type Trip ¶
type Trip struct {
FeedId string `csv:"-" gorm:"primaryKey;uniqueIndex:pk_trip" json:"feed_id"`
TripId string `gorm:"primaryKey;uniqueIndex:pk_trip" csv:"trip_id" json:"trip_id"`
Feed *Feed `csv:"-" gorm:"foreignKey:FeedId" json:"feed"`
RefRouteId string `csv:"route_id" json:"-"`
Route *Route `csv:"-" gorm:"foreignKey:RefRouteId,FeedId;references:RouteId,FeedId" json:"route"`
RefServiceId string `csv:"service_id" json:"service_id"`
Calendar Calendar `csv:"-" json:"calendar" gorm:"foreignKey:FeedId,RefServiceId;references:FeedId,ServiceId"`
// Calendar Calendar `csv:"-" json:"calendar" gorm:"foreignKey:FeedId,ServiceId"`
//REMOVING THAT ONE CAUSE NOT PART OF STRICT ORM, TODO check if this breaks anything
CalendarDates []CalendarDate `csv:"-" json:"calendar_dates" gorm:"foreignKey:FeedId,ServiceId;references:FeedId,RefServiceId"`
// trying out the many to many aspect (it's fucked up afaik)
// CalendarDates []CalendarDate `csv:"-" json:"calendar_dates" gorm:"many2many:calendar;foreignKey:FeedId,ServiceId;references:FeedId,ServiceId"`
Headsign string `csv:"trip_headsign" json:"headsign"`
TripShortName string `csv:"trip_short_name" json:"short_name"`
StopTimes []StopTime `gorm:"foreignKey:FeedId,TripId;references:FeedId,TripId" json:"stop_times" csv:"-"`
//NOTE: no LongName is speicified in the spec
//Additional feeds (not part of the gtfs spec but used by our implementation)
MinLat float64 `gorm:"index:geo_index" json:"-" csv:"-"`
MaxLat float64 `gorm:"index:geo_index" json:"-" csv:"-"`
MinLon float64 `gorm:"index:geo_index" json:"-" csv:"-"`
MaxLon float64 `gorm:"index:geo_index" json:"-" csv:"-"`
}