structs.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. package traffic
  2. import (
  3. "apiote.xyz/p/szczanieckiej/gtfs_rt"
  4. //"image/color"
  5. "strings"
  6. "time"
  7. "github.com/dhconnelly/rtreego"
  8. )
  9. type DeparturesType uint8
  10. const (
  11. DEPARTURES_HYBRID DeparturesType = iota
  12. DEPARTURES_FULL
  13. )
  14. /*type Position struct {
  15. Lat float64
  16. Lon float64
  17. }*/
  18. // todo(BAF10) change IDs to type ID, string to type OLC
  19. /*type Agency struct {
  20. ID ID
  21. Name string
  22. Website string
  23. Timezone string
  24. PhoneNumber string // todo(BAF10) PhoneNumber
  25. Language string // todo(BAF10) language.Tag
  26. Email string
  27. FareWebsite string
  28. }*/
  29. /*type FeedInfo struct {
  30. Name string
  31. Website string
  32. Language string // todo(BAF10) language.Tag
  33. }*/
  34. type VehicleStatus struct { // todo(BAF10) two types of vehicles — descriptions ID-Capabilities, and an actual vehicle that runs on a trip
  35. Id string
  36. Capabilities uint16
  37. Position Position
  38. Speed float32
  39. Delay int32 // todo(BAF31)
  40. LineName string
  41. Headsign string
  42. // Status
  43. // Occupancy
  44. // Congestion
  45. }
  46. func (v VehicleStatus) Location() Position {
  47. return v.Position
  48. }
  49. func (k LineType) Value() uint {
  50. return uint(k)
  51. }
  52. func (d Direction) Value() uint {
  53. return uint(d)
  54. }
  55. /*type Departure struct {
  56. StopSeq int
  57. Time uint
  58. Pickup uint // todo(BAF10) enum
  59. Dropoff uint // todo(BAF10) enum
  60. StopOffset uint64
  61. }*/
  62. type DepartureRealtime struct {
  63. Departure Departure
  64. Headsign string
  65. LineName string
  66. Order StopOrder
  67. Update gtfs_rt.Update
  68. }
  69. /*type Trip struct {
  70. ID string
  71. Headsign string
  72. Direction uint
  73. LineName string
  74. ScheduleID string
  75. ShapeID ID // todo(BAF11)
  76. Departures []Departure
  77. }*/
  78. /*type LineGraph struct {
  79. StopCodes []string
  80. NextNodes map[int][]int
  81. PrevNodes map[int][]int
  82. }*/
  83. func (g LineGraph) LastNodes() []int {
  84. lastNodes := []int{}
  85. for i, nextNodes := range g.NextNodes {
  86. for _, node := range nextNodes {
  87. if node == -1 {
  88. lastNodes = append(lastNodes, i)
  89. break
  90. }
  91. }
  92. }
  93. return lastNodes
  94. }
  95. /*type Line struct {
  96. ID string
  97. Name string
  98. Colour color.RGBA
  99. Type uint // todo(BAF10) enum
  100. AgencyID ID
  101. GraphThere LineGraph
  102. GraphBack LineGraph
  103. }*/
  104. type LineStub struct {
  105. Name string
  106. Colour string
  107. Type string
  108. }
  109. func (l Line) DisplayName() string {
  110. return l.Name
  111. }
  112. func (l Line) IsItem() {}
  113. type Shape struct { // todo(BAF11)
  114. Points []string // OLC
  115. }
  116. /*type Schedule struct {
  117. ScheduleID string
  118. Weekdays uint8
  119. StartDate string
  120. EndDate string
  121. }*/
  122. /*type StopOrder struct {
  123. TripOffset uint
  124. Order int
  125. TripID string
  126. }*/
  127. /*type ChangeOption struct {
  128. LineName string
  129. Headsign string
  130. }*/
  131. type Item interface { // todo(BAF12) name: ‘query-able’ eg.
  132. IsItem()
  133. DisplayName() string
  134. }
  135. type Locatable interface {
  136. Location() Position
  137. }
  138. /*type Stop struct {
  139. ID string
  140. Code string
  141. Name string
  142. NodeName string
  143. ChangeOptions []ChangeOption
  144. Zone string
  145. Coordinates Position
  146. Order []StopOrder
  147. Timezone string
  148. }*/
  149. func (s Stop) DisplayName() string {
  150. return s.Name
  151. }
  152. func (s Stop) Location() Position {
  153. return s.Position
  154. }
  155. func (s Stop) Bounds() *rtreego.Rect {
  156. rect, err := rtreego.NewRectFromPoints(
  157. rtreego.Point{s.Position.Lat, s.Position.Lon},
  158. rtreego.Point{s.Position.Lat, s.Position.Lon},
  159. )
  160. if err != nil {
  161. panic(err.Error())
  162. }
  163. return rect
  164. }
  165. func (s Stop) IsItem() {}
  166. type TimedStopStub struct {
  167. StopStub
  168. Time uint
  169. }
  170. type StopStub struct {
  171. Code string
  172. Name string
  173. NodeName string
  174. Zone string
  175. OnDemand bool
  176. }
  177. type Alert struct {
  178. Header string
  179. Description string
  180. URL string
  181. Cause int32 // todo(BAF10)
  182. Effect int32 // todo(BAF10)
  183. }
  184. // type ID string
  185. type Validity string // 20060102_20060102
  186. func (v Validity) Start() string {
  187. return strings.Split(string(v), "_")[0]
  188. }
  189. func (v Validity) End() string {
  190. return strings.Split(string(v), "_")[1]
  191. }
  192. // type CodeIndex map[ID]uint
  193. type FeedCodeIndex map[Validity]CodeIndex
  194. type GlobalCodeIndex map[string]FeedCodeIndex
  195. /*type NameOffset struct {
  196. Name string
  197. Offsets []uint
  198. }*/
  199. type NameIndex []NameOffset
  200. type FeedNameIndex map[Validity]NameIndex
  201. type GlobalNameIndex map[string]FeedNameIndex
  202. func (ix NameIndex) String(i int) string {
  203. return ix[i].Name
  204. }
  205. func (ix NameIndex) Len() int {
  206. return len(ix)
  207. }
  208. type FeedCalendar map[Validity][]Schedule
  209. type GlobalCalendar map[string]FeedCalendar
  210. type Vehicles map[string]Vehicle
  211. type FeedVehicles map[Validity]Vehicles
  212. type GlobalVehicles map[string]FeedVehicles
  213. type FeedPositionIndex map[Validity]*rtreego.Rtree
  214. type GlobalPositionIndex map[string]FeedPositionIndex
  215. type Version struct {
  216. Link string
  217. ValidFrom time.Time
  218. ValidTill time.Time
  219. }
  220. func (v Version) String() string {
  221. return v.ValidFrom.Format("20060102") + "_" + v.ValidTill.Format("20060102")
  222. }
  223. type GlobalVersions map[string][]Version
  224. var DateFormat string = "2006-01-02"
  225. var ValidityFormat string = "20060102"
  226. type Traffic struct {
  227. CodeIndexes GlobalCodeIndex
  228. NameIndexes GlobalNameIndex
  229. LineIndexes GlobalNameIndex
  230. TripIndexes GlobalNameIndex
  231. PositionIndexes GlobalPositionIndex
  232. Versions GlobalVersions
  233. Calendars GlobalCalendar
  234. Vehicles GlobalVehicles
  235. Feeds map[string]Feed
  236. }
  237. type Context struct {
  238. DataHome string
  239. FeedName string
  240. Version Validity
  241. }