Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteFakeShapes(db sqlx.Ext) error
- func DeleteRouteShapes(db sqlx.Ext) error
- func GetAgencyServiceIDs(db sqlx.Ext, agencyIDs []string, day string, now time.Time) (serviceIDs []string, err error)
- func GetPartialTripIDMatch(db sqlx.Ext, agencyID, routeID, partialTripID string) (tripID string, err error)
- type Departure
- type FakeShape
- type HereQuery
- type HereResult
- type Route
- func GetAllRoutes(db sqlx.Ext, agencyID string) (routes []*Route, err error)
- func GetPreloadRoutes(db sqlx.Ext, agencyIDs []string) (routes []*Route, err error)
- func GetRoute(db sqlx.Ext, agencyID, routeID string) (r *Route, err error)
- func NewRoute(id string, rtype int, color, textColor, agencyID, shortName, longName string) (r *Route, err error)
- type RouteShape
- type ScheduledStopTime
- type Service
- type ServiceRouteDay
- type ServiceRouteException
- type Shape
- type SortableDepartures
- type Stop
- type Trip
- func GetTrip(db sqlx.Ext, agencyID, routeID, tripID string, includeShape bool) (t Trip, err error)
- func NewTrip(id, routeID, agencyID, serviceID, shapeID, headsign string, direction int) (t *Trip, err error)
- func ReallyGetTrip(db sqlx.Ext, agencyID, routeID, tripID, firstTripID string, includeShape bool) (*Trip, error)
- type Vehicle
Constants ¶
const ( Tram int = iota Subway Rail Bus Ferry CableCar Gondola Funicular )
const ( // Possible values for exception_type ServiceAdded = 1 ServiceRemoved = 2 )
const (
// maximum departures to return in a result
MaxDepartures = 6
)
Variables ¶
var ( // ErrNoID is returned by model constructors when no ID is provided ErrNoID = errors.New("no ID provided") // ErrInvalidRouteType is returned by NewRoute when the route_type // cannot be found ErrInvalidRouteType = errors.New("invalid route_type") // ErrNotFound is returned when something can't be found in a // Get call ErrNotFound = errors.New("not found") )
Functions ¶
func DeleteFakeShapes ¶
DeleteFakeShapes removes all existing fake shapes. Typically this should be used in a transaction in conjuction with to rebuild the data via GetFakeShapes
func DeleteRouteShapes ¶
DeleteRouteShapes removes all existing route / fake shapes. Typically this should be used in a transaction in conjuction with GetRouteShapes to rebuild the data
func GetAgencyServiceIDs ¶
func GetAgencyServiceIDs(db sqlx.Ext, agencyIDs []string, day string, now time.Time) (serviceIDs []string, err error)
GetAgencyServiceIDs returns all possible serviceIDs for this day / time / agency for the initial query. However, these values may be later filtered by getRouteServiceIDs
func GetPartialTripIDMatch ¶
func GetPartialTripIDMatch(db sqlx.Ext, agencyID, routeID, partialTripID string) (tripID string, err error)
GetPartialTripIDMatch returns the first trip_id that is "like" the partialTripID sent in Hack for MTA NYCT train API: https://github.com/brnstz/bus/issues/63
Types ¶
type Departure ¶
type Departure struct { Time time.Time `json:"time" db:"-"` DepartureSec int `json:"-" db:"departure_sec"` TripID string `json:"trip_id" db:"trip_id"` ServiceID string `json:"service_id" db:"service_id"` Live bool `json:"live" db:"-" upsert:"omit"` // CompassDir is the direction to the next stop CompassDir float64 `json:"compass_dir" db:"-" upsert:"omit"` // contains filtered or unexported fields }
func (*Departure) Initialize ¶
type FakeShape ¶
type FakeShape struct { AgencyID string `json:"-" db:"agency_id" upsert:"key"` RouteID string `json:"-" db:"route_id" upsert:"key"` DirectionID int `json:"-" db:"direction_id" upsert:"key"` Headsign string `json:"-" db:"headsign" upsert:"key"` Seq int `json:"-" db:"seq" upsert:"key"` Lat null.Float `json:"lat" db:"lat"` Lon null.Float `json:"lon" db:"lon"` // Location is PostGIS field value that combines lat and lon into a single // field. Location interface{} `json:"-" db:"location" upsert_value:"ST_SetSRID(ST_MakePoint(:lat, :lon),4326)"` TripID string `json:"-" db:"trip_id" upsert:"omit"` ShapeID string `json:"-" db:"shape_id" upsert:"omit"` }
func GetFakeRouteShapes ¶
GetFakeRouteShapes returns fake shapes for agency/route/headsign/direction combos that don't have a shape
type HereQuery ¶
type HereQuery struct { // The southwest and northeast bounding points of the box we are // searching SWLat float64 `db:"sw_lat"` SWLon float64 `db:"sw_lon"` NELat float64 `db:"ne_lat"` NELon float64 `db:"ne_lon"` // The midpoint of our search box MidLat float64 `db:"mid_lat"` MidLon float64 `db:"mid_lon"` LineString string `db:"line_string"` PointString string `db:"point_string"` YesterdayDepartureMin int YesterdayDepartureMax int YesterdaySecDiff int YesterdayDepartureBase time.Time YesterdayServiceIDs []string YesterdayRelevantIDs map[string]bool TodayDepartureMin int TodayDepartureMax int TodayDepartureBase time.Time TodayServiceIDs []string TodayRelevantIDs map[string]bool TomorrowDepartureMin int TomorrowDepartureMax int TomorrowSecDiff int TomorrowDepartureBase time.Time TomorrowServiceIDs []string TomorrowRelevantIDs map[string]bool Limit int `db:"limit"` Query string }
type HereResult ¶
type HereResult struct { AgencyID string `db:"agency_id"` RouteID string `db:"route_id"` StopID string `db:"stop_id"` ServiceID string `db:"service_id"` TripIDs string `db:"trip_ids"` ArrivalSecs string `db:"arrival_secs"` DepartureSecs string `db:"departure_secs"` StopSequences string `db:"stop_sequences"` NextStopLats string `db:"next_stop_lats"` NextStopLons string `db:"next_stop_lons"` TripHeadsign string `db:"trip_headsign"` StopName string `db:"stop_name"` StopHeadsign string `db:"stop_headsign"` DirectionID int `db:"direction_id"` Lat float64 `db:"lat"` Lon float64 `db:"lon"` Dist float64 `db:"dist"` RouteType int `db:"route_type"` RouteColor string `db:"route_color"` RouteTextColor string `db:"route_text_color"` RouteShortName string `db:"route_short_name"` RouteLongName string `db:"route_long_name"` HQ *HereQuery Stop *Stop Route *Route Departures []*Departure }
func (*HereResult) Initialize ¶
func (h *HereResult) Initialize() error
type Route ¶
type Route struct { RouteID string `json:"route_id" db:"route_id" upsert:"key"` AgencyID string `json:"agency_id" db:"agency_id" upsert:"key"` Type int `json:"route_type" db:"route_type"` TypeName string `json:"route_type_name" db:"-" upsert:"omit"` Color string `json:"route_color" db:"route_color"` TextColor string `json:"route_text_color" db:"route_text_color"` ShortName string `json:"route_short_name" db:"route_short_name"` LongName string `json:"route_long_name" db:"route_long_name"` UniqueID string `json:"unique_id" db:"-" upsert:"omit"` RouteShapes []*RouteShape `json:"route_shapes" upsert:"omit"` }
Route is https://developers.google.com/transit/gtfs/reference#routestxt
func GetPreloadRoutes ¶
test func for static json file
func NewRoute ¶
func NewRoute(id string, rtype int, color, textColor, agencyID, shortName, longName string) (r *Route, err error)
NewRoute creates a Route given incoming data, typically from a routes.txt file
func (*Route) Initialize ¶
init ensures any derived values are correct after creating/loading an object
type RouteShape ¶
type RouteShape struct { AgencyID string `json:"agency_id" db:"agency_id" upsert:"key"` RouteID string `json:"route_id" db:"route_id" upsert:"key"` Headsign string `json:"headsign" db:"headsign" upsert:"key"` DirectionID int `json:"direction_id" db:"direction_id" upsert:"key"` ShapeID string `json:"shape_id" db:"shape_id"` Count int `json:"-" db:"count" upsert:"omit"` TripID string `json:"-" db:"trip_id" upsert:"omit"` Shapes []*Shape `json:"shapes" db:"-" upsert:"omit"` }
RouteShape is a one-to-many mapping between routes and shapes. The loader should identify which shapes represent the typical / full route and create/save these objects
func GetRouteShapes ¶
func GetRouteShapes(db sqlx.Ext) ([]*RouteShape, error)
GetRouteShapes returns distinct shapes for every route ordered by the "size" (number of points) of the route from least to most for each given combination of agency/route/headsign/direction. Given the ordering, you can Save() each value in a tx and end up with the "best" value live in the db
func GetSavedRouteShapes ¶
func GetSavedRouteShapes(db sqlx.Ext, agencyID, routeID string) ([]*RouteShape, error)
GetSavedRouteShapes returns all shapes for this combination of agencyID and routeID
func (*RouteShape) Save ¶
func (rs *RouteShape) Save(db sqlx.Ext) error
Save saves the route_shape to the db
func (*RouteShape) Table ¶
func (rs *RouteShape) Table() string
Table returns the name of the RouteShape table, implementing the upsert.Upserter interface
type ScheduledStopTime ¶
type ScheduledStopTime struct { AgencyID string `db:"agency_id" upsert:"key"` RouteID string `db:"route_id" upsert:"key"` StopID string `db:"stop_id" upsert:"key"` ServiceID string `db:"service_id" upsert:"key"` TripID string `db:"trip_id" upsert:"key"` ArrivalSec int `db:"arrival_sec"` DepartureSec int `db:"departure_sec"` StopSequence int `db:"stop_sequence"` LastStop sql.NullBool `db:"last_stop"` NextStopID sql.NullString `db:"next_stop_id"` NextStopLat null.Float `json:"next_stop_lat" db:"next_stop_lat"` NextStopLon null.Float `json:"next_stop_lon" db:"next_stop_lon"` // Location is PostGIS field value that combines lat and lon into a single // field. NextStopLocation interface{} `json:"-" db:"next_stop_location" upsert_value:"ST_SetSRID(ST_MakePoint(:next_stop_lat, :next_stop_lon),4326)"` }
func NewScheduledStopTime ¶
func NewScheduledStopTime(routeID, stopID, serviceID, arrivalStr, depatureStr, agencyID, tripID string, sequence int, lastStop bool) (sst *ScheduledStopTime, err error)
func (*ScheduledStopTime) Save ¶
func (sst *ScheduledStopTime) Save() error
Save saves a scheduled_stop_time to the database
func (*ScheduledStopTime) String ¶
func (s *ScheduledStopTime) String() string
func (*ScheduledStopTime) Table ¶
func (sst *ScheduledStopTime) Table() string
type ServiceRouteDay ¶
type ServiceRouteDay struct { ServiceID string `db:"service_id" upsert:"key"` RouteID string `db:"route_id" upsert:"key"` AgencyID string `db:"agency_id" upsert:"key"` Day string `db:"day" upsert:"key"` StartDate time.Time `db:"start_date" upsert:"key"` EndDate time.Time `db:"end_date" upsert:"key"` }
ServiceRouteDay defines what service ID is valid for this route ID on this Day of the week. Service IDs are valid for a period of time which is indicated by StartDate and EndDate. All fields in this object form a unique key.
func (*ServiceRouteDay) Save ¶
func (s *ServiceRouteDay) Save() error
Save saves a ServiceRouteDay to the database
func (ServiceRouteDay) String ¶
func (s ServiceRouteDay) String() string
String returns a text representation of the ServiceRouteDay
func (*ServiceRouteDay) Table ¶
func (s *ServiceRouteDay) Table() string
Table implements the upsert.Upserter interface by defining the table we're saving to
type ServiceRouteException ¶
type ServiceRouteException struct { AgencyID string `db:"agency_id" upsert:"key"` RouteID string `db:"route_id" upsert:"key"` ServiceID string `db:"service_id" upsert:"key"` ExceptionDate time.Time `db:"exception_date" upsert:"key"` ExceptionType int `db:"exception_type"` }
func (*ServiceRouteException) Save ¶
func (s *ServiceRouteException) Save() error
Save saves a ServiceRouteDay to the database
func (*ServiceRouteException) Table ¶
func (s *ServiceRouteException) Table() string
type Shape ¶
type Shape struct { ID string `json:"-" db:"shape_id" upsert:"key"` AgencyID string `json:"-" db:"agency_id" upsert:"key"` Seq int `json:"-" db:"seq" upsert:"key"` Lat null.Float `json:"lat" db:"lat"` Lon null.Float `json:"lon" db:"lon"` // Location is PostGIS field value that combines lat and lon into a single // field. Location interface{} `json:"-" db:"location" upsert_value:"ST_SetSRID(ST_MakePoint(:lat, :lon),4326)"` }
func GetFakeShapePoints ¶
type SortableDepartures ¶
type SortableDepartures []*Departure
func (SortableDepartures) Len ¶
func (d SortableDepartures) Len() int
func (SortableDepartures) Less ¶
func (d SortableDepartures) Less(i, j int) bool
func (SortableDepartures) Swap ¶
func (d SortableDepartures) Swap(i, j int)
type Stop ¶
type Stop struct { StopID string `json:"stop_id" db:"stop_id" upsert:"key"` RouteID string `json:"route_id" db:"route_id" upsert:"key"` AgencyID string `json:"agency_id" db:"agency_id" upsert:"key"` DirectionID int `json:"direction_id" db:"direction_id" upsert:"key"` Name string `json:"stop_name" db:"stop_name"` UniqueID string `json:"unique_id" db:"-" upsert:"omit"` Headsign string `json:"headsign" db:"headsign"` Lat null.Float `json:"lat" db:"lat"` Lon null.Float `json:"lon" db:"lon"` // Location is PostGIS field value that combines lat and lon into a single // field. Location interface{} `json:"-" db:"location" upsert_value:"ST_SetSRID(ST_MakePoint(:lat, :lon),4326)"` // info we steal from route when doing a here query RouteType int `json:"route_type" db:"-" upsert:"omit"` RouteTypeName string `json:"route_type_name" db:"-" upsert:"omit"` RouteColor string `json:"route_color" db:"-" upsert:"omit"` RouteTextColor string `json:"route_text_color" db:"-" upsert:"omit"` RouteShortName string `json:"route_short_name" db:"-" upsert:"omit"` RouteLongName string `json:"route_long_name" db:"-" upsert:"omit"` DisplayName string `json:"display_name" db:"-" upsert:"omit"` RouteAndHeadsign string `json:"route_and_headsign" db:"-" upsert:"omit"` JustHeadsign string `json:"just_headsign" db:"-" upsert:"omit"` GroupExtraKey string `json:"group_extra_key" db:"-" upsert:"omit"` TripHeadsign string `json:"trip_headsign" db:"-" upsert:"omit"` Seq int `json:"seq" db:"stop_sequence" upsert:"omit"` FallbackTripID string `json:"fallback_trip_id" db:"-" upsert:"omit"` Dist float64 `json:"dist,omitempty" db:"-" upsert:"omit"` Departures []*Departure `json:"departures,omitempty" db:"-" upsert:"omit"` Vehicles []Vehicle `json:"vehicles,omitempty" db:"-" upsert:"omit"` }
Stop is a single transit stop for a particular route. If a stop serves more than one route, there are multiple distinct entries for that stop.
func GetHereResults ¶
func (*Stop) Initialize ¶
func (Stop) Key ¶
Key() returns the unique string for this stop, so we can identify unique stops in the loader.
type Trip ¶
type Trip struct { AgencyID string `json:"agency_id" db:"agency_id" upsert:"key"` RouteID string `json:"route_id" db:"route_id" upsert:"key"` TripID string `json:"trip_id" db:"trip_id" upsert:"key"` UniqueID string `json:"unique_id" db:"-" upsert:"omit"` ServiceID string `json:"service_id" db:"service_id"` ShapeID string `json:"shape_id" db:"shape_id"` Headsign string `json:"headsign" db:"headsign"` DirectionID int `json:"direction_id" db:"direction_id"` ShapePoints []*Shape `json:"shape_points" db:"-" upsert:"omit"` Stops []*Stop `json:"stops" db:"-" upsert:"omit"` }
func ReallyGetTrip ¶
func ReallyGetTrip(db sqlx.Ext, agencyID, routeID, tripID, firstTripID string, includeShape bool) (*Trip, error)
ReallyGetTrip tries all possible methods for getting a trip
func (*Trip) Initialize ¶
Initialize ensures any derived values are correct after creating/loading an object