positions

package
v0.0.0-...-70af2fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

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

func Loop

func Loop(client *http.Client, jsonResource util.Resource, sleepTime time.Duration, opts Options) (err error)

Loop automatically updates the GTFS-RT Positions files

func Main

func Main(client *http.Client, opts Options) (err error)

Main auto-magically creates vehicle position data

Types

type APIVehicleEntry

type APIVehicleEntry struct {
	Lat, Lon                            float64
	Time, Lines, Brigade, VehicleNumber string
}

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

func (v *Vehicle) CalculateBearing(pv *Vehicle)

CalculateBearing updates the bearing for a Vehicle

func (*Vehicle) MatchTrip

func (v *Vehicle) MatchTrip(pv *Vehicle, cst compareTime, be []*brigadeEntry) error

MatchTrip tries to guess which trip this vehicle is on

func (*Vehicle) MatchTripNoPV

func (v *Vehicle) MatchTripNoPV(cst compareTime, be []*brigadeEntry) error

MatchTripNoPV tries to guess which trip this vehicle is on, without knowing the previous trip

func (*Vehicle) MatchTripWithPV

func (v *Vehicle) MatchTripWithPV(pv *Vehicle, cst compareTime, be []*brigadeEntry) error

MatchTripWithPV tries to guess which trip this vehicle is on

type VehicleAPI

type VehicleAPI struct {
	Key    string
	Client *http.Client
}

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

func (*VehicleContainer) SavePB

func (vc *VehicleContainer) SavePB(target string, humanReadable bool) (err error)

SavePB marshalls the container into a GTFS-Realtime protocol buffer file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL