Documentation ¶
Index ¶
- func Create(api VehicleAPI, brigadeMap map[string][]*brigadeEntry, ...) (map[string]*Vehicle, error)
- func Loop(client *http.Client, jsonResource util.Resource, sleepTime time.Duration, ...) (err error)
- func Main(client *http.Client, opts Options) (err error)
- type APIVehicleEntry
- type Options
- type Vehicle
- func (v *Vehicle) AsProto() *gtfsrt.FeedEntity
- func (v *Vehicle) CalculateBearing(pv *Vehicle)
- func (v *Vehicle) MatchTrip(pv *Vehicle, cst compareTime, be []*brigadeEntry) error
- func (v *Vehicle) MatchTripNoPV(cst compareTime, be []*brigadeEntry) error
- func (v *Vehicle) MatchTripWithPV(pv *Vehicle, cst compareTime, be []*brigadeEntry) error
- type VehicleAPI
- type VehicleContainer
- func (vc *VehicleContainer) AsProto() *gtfsrt.FeedMessage
- func (vc *VehicleContainer) MarshalJSON() ([]byte, error)
- func (vc *VehicleContainer) MatchAll(brigadeMap map[string][]*brigadeEntry, prevVehicles map[string]*Vehicle) error
- func (vc *VehicleContainer) Prepare(apiEntries []*APIVehicleEntry) error
- func (vc *VehicleContainer) SaveJSON(target string) (err error)
- func (vc *VehicleContainer) SavePB(target string, humanReadable bool) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
func Create(api VehicleAPI, brigadeMap map[string][]*brigadeEntry, prevVehicles map[string]*Vehicle, opts Options) (map[string]*Vehicle, error)
Create auto-magically creates realtime feeds with position data. Create is designed to run a loop, hence it doesn't contain logic to load brigades JSON
Types ¶
type APIVehicleEntry ¶
APIVehicleEntry represents a single object from the API
type Options ¶
type Options struct { GtfsRtTarget string JSONTarget string HumanReadable bool Apikey string Brigades string }
Options represent options for creating positions GTFS-Realtime
type Vehicle ¶
type Vehicle struct { // Basic fields ID string `json:"id"` Time string `json:"timestamp"` Lat float64 `json:"lat"` Lon float64 `json:"lon"` SideNumber string `json:"side_number"` // Fields not filled by NewVehicle method Trip string `json:"trip_id"` Bearing float64 `json:"bearing,omitempty"` // Private fields, not meant to be exported Line string `json:"-"` Brigade string `json:"-"` TimeObj time.Time `json:"-"` }
Vehicle is an object for representing a single vehicle position
func NewVehicle ¶
func NewVehicle(av *APIVehicleEntry, timezone *time.Location) (v *Vehicle, err error)
NewVehicle creates a Vehicle object from an apiVehicle object
func (*Vehicle) AsProto ¶
func (v *Vehicle) AsProto() *gtfsrt.FeedEntity
AsProto returns the Vehicle marshalled into a gtfs.FeedEntity
func (*Vehicle) CalculateBearing ¶
CalculateBearing updates the bearing for a Vehicle
func (*Vehicle) MatchTripNoPV ¶
MatchTripNoPV tries to guess which trip this vehicle is on, without knowing the previous trip
func (*Vehicle) MatchTripWithPV ¶
MatchTripWithPV tries to guess which trip this vehicle is on
type VehicleAPI ¶
VehicleAPI is an object for communicating with the vehicle position api at api.um.warszawa.pl
func (*VehicleAPI) Get ¶
func (api *VehicleAPI) Get(apiVehType string) ([]*APIVehicleEntry, error)
Get tries to get vehicle positions from the API. apiVehType can be "1" to get bus positions or "2" to get tram positions.
func (*VehicleAPI) GetAll ¶
func (api *VehicleAPI) GetAll() (s []*APIVehicleEntry, err error)
GetAll will automatically call the api to retrieve a list of all tram and bus positions
type VehicleContainer ¶
type VehicleContainer struct { SyncTime time.Time CompareSyncTime compareTime Vehicles map[string]*Vehicle }
VehicleContainer is a container for multiple Vehicle objects
func (*VehicleContainer) AsProto ¶
func (vc *VehicleContainer) AsProto() *gtfsrt.FeedMessage
AsProto returns this VehicleContainer marshalled into a GTFS-RT FeedMessage
func (*VehicleContainer) MarshalJSON ¶
func (vc *VehicleContainer) MarshalJSON() ([]byte, error)
MarshalJSON returns this VehicleContainer marshalled into JSON
func (*VehicleContainer) MatchAll ¶
func (vc *VehicleContainer) MatchAll(brigadeMap map[string][]*brigadeEntry, prevVehicles map[string]*Vehicle) error
MatchAll tries to calculate the bearing and to match a vehicle to a particular trip for all its Vehicles. If a Vehicle still has an empty Trip field after calling its Match function such vehicle is removed for the container.
func (*VehicleContainer) Prepare ¶
func (vc *VehicleContainer) Prepare(apiEntries []*APIVehicleEntry) error
Prepare initializes the vehiclecontainer.Vehicles map with vehicle objects created from a sequence of apiVehicleEntry
func (*VehicleContainer) SaveJSON ¶
func (vc *VehicleContainer) SaveJSON(target string) (err error)
SaveJSON marshalls the container into a json file at a given location