123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- 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
- }*/
- // todo(BAF10) change IDs to type ID, string to type OLC
- /*type Agency struct {
- ID ID
- Name string
- Website string
- Timezone string
- PhoneNumber string // todo(BAF10) PhoneNumber
- Language string // todo(BAF10) language.Tag
- Email string
- FareWebsite string
- }*/
- /*type FeedInfo struct {
- Name string
- Website string
- Language string // todo(BAF10) language.Tag
- }*/
- type VehicleStatus struct { // todo(BAF10) two types of vehicles — descriptions ID-Capabilities, and an actual vehicle that runs on a trip
- Id string
- Capabilities uint16
- Position Position
- Speed float32
- Delay int32 // todo(BAF31)
- LineName string
- Headsign string
- // Status
- // Occupancy
- // Congestion
- }
- func (v VehicleStatus) Location() Position {
- return v.Position
- }
- func (k LineType) Value() uint {
- return uint(k)
- }
- func (d Direction) Value() uint {
- return uint(d)
- }
- /*type Departure struct {
- StopSeq int
- Time uint
- Pickup uint // todo(BAF10) enum
- Dropoff uint // todo(BAF10) enum
- 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 // todo(BAF11)
- 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 // todo(BAF10) enum
- AgencyID ID
- GraphThere LineGraph
- GraphBack LineGraph
- }*/
- type LineStub struct {
- Name string
- Colour string
- Type string
- }
- func (l Line) DisplayName() string {
- return l.Name
- }
- func (l Line) IsItem() {}
- type Shape struct { // todo(BAF11)
- Points []string // OLC
- }
- /*type Schedule struct {
- ScheduleID string
- Weekdays uint8
- StartDate string
- EndDate string
- }*/
- /*type StopOrder struct {
- TripOffset uint
- Order int
- TripID string
- }*/
- /*type ChangeOption struct {
- LineName string
- Headsign string
- }*/
- type Item interface { // todo(BAF12) name: ‘query-able’ eg.
- IsItem()
- DisplayName() string
- }
- type Locatable interface {
- Location() Position
- }
- /*type Stop struct {
- ID string
- Code string
- Name string
- NodeName string
- ChangeOptions []ChangeOption
- Zone string
- Coordinates Position
- Order []StopOrder
- Timezone string
- }*/
- func (s Stop) DisplayName() string {
- return s.Name
- }
- func (s Stop) Location() Position {
- return s.Position
- }
- func (s Stop) Bounds() *rtreego.Rect {
- rect, err := rtreego.NewRectFromPoints(
- rtreego.Point{s.Position.Lat, s.Position.Lon},
- rtreego.Point{s.Position.Lat, s.Position.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
- NodeName string
- Zone string
- OnDemand bool
- }
- type Alert struct {
- Header string
- Description string
- URL string
- Cause int32 // todo(BAF10)
- Effect int32 // todo(BAF10)
- }
- // type ID string
- type Validity string // 20060102_20060102
- 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[string]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
- }
|