golifehk/datasources/kmb/RouteStop.go

66 lines
1.6 KiB
Go
Raw Permalink Normal View History

2022-09-16 20:33:47 +00:00
package kmb
import (
query "github.com/tgckpg/golifehk/query"
)
type RouteStop struct {
BusStop *BusStop
RouteId string `json:"route"`
ServiceType string `json:"service_type"`
Direction string `json:"bound"`
StationSeq int `json:"seq,string"`
StationId string `json:"stop"`
RouteStops *map[int] *RouteStop
query.Searchable
}
type RouteStops struct {
Type string `json:"type"`
Version string `json:"version"`
DateCreated string `json:"generated_timestamp"`
RouteStops [] *RouteStop `json:"data"`
}
func ( routeStop RouteStop ) PrevStop() *RouteStop {
if v, hasKey := (*routeStop.RouteStops)[ routeStop.StationSeq - 1 ]; hasKey {
return v
}
return nil
}
func ( routeStop RouteStop ) NextStop() *RouteStop {
if v, hasKey := (*routeStop.RouteStops)[ routeStop.StationSeq + 1 ]; hasKey {
return v
}
return nil
}
2022-09-25 10:48:22 +00:00
func ( this *RouteStop ) Reload() {
2022-09-16 20:33:47 +00:00
2022-09-25 10:48:22 +00:00
searchData := [] *string{}
busStop := *this.BusStop
searchData = append( searchData, &busStop.Name_en )
searchData = append( searchData, &busStop.Name_tc )
this.Key = &this.RouteId
this.SearchData = &searchData
}
type ByRoute [] *RouteStop
func (a ByRoute) Len() int { return len(a) }
func (a ByRoute) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByRoute) Less(i, j int) bool {
_a := *a[i]
_b := *a[j]
if _a.RouteId == _b.RouteId {
if _a.Direction == _b.Direction {
return _a.ServiceType < _b.ServiceType
}
return _a.Direction < _b.Direction
}
return _a.RouteId < _b.RouteId
}