123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- package traffic
- import (
- "apiote.xyz/p/szczanieckiej/gtfs_rt"
- "image/color"
- "strings"
- "time"
- "github.com/dhconnelly/rtreego"
- )
- type DeparturesType uint8
- const (
- DEPARTURES_HYBRID DeparturesType = iota
- DEPARTURES_FULL
- )
- type Position struct {
- Lat float64
- Lon float64
- }
- type Agency struct {
- ID ID
- Name string
- Website string
- Timezone string
- PhoneNumber string
- Language string
- Email string
- FareWebsite string
- }
- type FeedInfo struct {
- Name string
- Website string
- Language string
- }
- type Vehicle struct {
- Id ID
- Capabilities uint16
- Coordinates Position
- Speed float32
- Delay int32
- LineName string
- Headsign string
-
-
-
- }
- func (v Vehicle) Location() Position {
- return v.Coordinates
- }
- type Departure struct {
- StopSeq int
- Time uint
- Pickup uint
- Dropoff uint
- StopOffset uint64
- }
- type DepartureRealtime struct {
- Departure Departure
- Headsign string
- LineName string
- Order StopOrder
- Update gtfs_rt.Update
- }
- type Trip struct {
- ID string
- Headsign string
- Direction uint
- LineName string
- ScheduleID string
- ShapeID ID
- Departures []Departure
- }
- type LineGraph struct {
- StopCodes []string
- NextNodes map[int][]int
- PrevNodes map[int][]int
- }
- func (g LineGraph) LastNodes() []int {
- lastNodes := []int{}
- for i, nextNodes := range g.NextNodes {
- for _, node := range nextNodes {
- if node == -1 {
- lastNodes = append(lastNodes, i)
- break
- }
- }
- }
- return lastNodes
- }
- type Line struct {
- ID string
- Name string
- Colour color.RGBA
- Type uint
- AgencyID ID
- GraphThere LineGraph
- GraphBack LineGraph
- }
- type LineStub struct {
- Name string
- Colour string
- Type string
- }
- func (l Line) IsItem() {}
- type Shape struct {
- Points []string
- }
- type Schedule struct {
- ScheduleID string
- Weekdays uint8
- StartDate string
- EndDate string
- }
- type StopOrder struct {
- TripID string `bare:"-"`
- TripOffset uint
- Order int
- }
- type ChangeOption struct {
- LineID string `bare:"-"`
- LineName string
- Headsign string
- }
- type Item interface {
- IsItem()
- }
- type Locatable interface {
- Location() Position
- }
- type Stop struct {
- ID string
- Code string
- Name string
- ChangeOptions []ChangeOption
- Zone string
- Coordinates Position
- Order []StopOrder
- Timezone string
- }
- func (s Stop) Location() Position {
- return s.Coordinates
- }
- func (s Stop) Bounds() *rtreego.Rect {
- rect, err := rtreego.NewRectFromPoints(
- rtreego.Point{s.Coordinates.Lat, s.Coordinates.Lon},
- rtreego.Point{s.Coordinates.Lat, s.Coordinates.Lon},
- )
- if err != nil {
- panic(err.Error())
- }
- return rect
- }
- func (s Stop) IsItem() {}
- type TimedStopStub struct {
- StopStub
- Time uint
- }
- type StopStub struct {
- Code string
- Name string
- Zone string
- OnDemand bool
- }
- type Alert struct {
- Header string
- Description string
- URL string
- Cause int32
- Effect int32
- }
- type ID string
- type Validity string
- func (v Validity) Start() string {
- return strings.Split(string(v), "_")[0]
- }
- func (v Validity) End() string {
- return strings.Split(string(v), "_")[1]
- }
- type CodeIndex map[ID]uint
- type FeedCodeIndex map[Validity]CodeIndex
- type GlobalCodeIndex map[string]FeedCodeIndex
- type NameOffset struct {
- Name string
- Offsets []uint
- }
- type NameIndex []NameOffset
- type FeedNameIndex map[Validity]NameIndex
- type GlobalNameIndex map[string]FeedNameIndex
- func (ix NameIndex) String(i int) string {
- return ix[i].Name
- }
- func (ix NameIndex) Len() int {
- return len(ix)
- }
- type FeedCalendar map[Validity][]Schedule
- type GlobalCalendar map[string]FeedCalendar
- type Vehicles map[ID]Vehicle
- type FeedVehicles map[Validity]Vehicles
- type GlobalVehicles map[string]FeedVehicles
- type FeedPositionIndex map[Validity]*rtreego.Rtree
- type GlobalPositionIndex map[string]FeedPositionIndex
- type Version struct {
- Link string
- ValidFrom time.Time
- ValidTill time.Time
- }
- func (v Version) String() string {
- return v.ValidFrom.Format("20060102") + "_" + v.ValidTill.Format("20060102")
- }
- type GlobalVersions map[string][]Version
- var DateFormat string = "2006-01-02"
- var ValidityFormat string = "20060102"
- type Traffic struct {
- CodeIndexes GlobalCodeIndex
- NameIndexes GlobalNameIndex
- LineIndexes GlobalNameIndex
- TripIndexes GlobalNameIndex
- PositionIndexes GlobalPositionIndex
- Versions GlobalVersions
- Calendars GlobalCalendar
- Vehicles GlobalVehicles
- Feeds map[string]Feed
- }
- type Context struct {
- DataHome string
- FeedName string
- Version Validity
- }
|