golifehk/datasources/mtr/bus/BusStop.go

63 lines
1.4 KiB
Go
Raw Permalink Normal View History

2022-09-14 13:21:39 +00:00
package bus
2022-09-16 20:33:47 +00:00
import (
i18n "github.com/tgckpg/golifehk/i18n"
)
2022-09-14 13:21:39 +00:00
type BusStop struct {
RouteId string
Direction string
StationSeq int
StationId string
Latitude float64
Longtitude float64
2022-09-16 20:33:47 +00:00
Name_zh string
Name_en string
2022-09-14 13:21:39 +00:00
2022-09-16 20:33:47 +00:00
// RouteStops[ StationSeq ] = BusStop
2022-09-14 13:21:39 +00:00
RouteStops *map[int] *BusStop
2022-09-16 20:33:47 +00:00
i18n.Generics
2022-09-14 13:21:39 +00:00
}
2022-09-16 20:33:47 +00:00
func ( this *BusStop ) PrevStop() *BusStop {
if v, hasKey := (*this.RouteStops)[ this.StationSeq - 1 ]; hasKey {
2022-09-14 13:21:39 +00:00
return v
}
return nil
}
2022-09-16 20:33:47 +00:00
func ( this *BusStop ) NextStop() *BusStop {
if v, hasKey := (*this.RouteStops)[ this.StationSeq + 1 ]; hasKey {
2022-09-14 13:21:39 +00:00
return v
}
return nil
}
2022-09-15 13:38:04 +00:00
2022-09-16 20:33:47 +00:00
func ( this *BusStop ) Reload() {
i18n_Name := map[string] string{}
i18n_Name["en"] = this.Name_en
i18n_Name["zh-Hant"] = this.Name_zh
2022-09-15 13:38:04 +00:00
2022-09-16 20:33:47 +00:00
searchData := [] *string{}
searchData = append( searchData, &this.Name_en )
searchData = append( searchData, &this.Name_zh )
this.Name = &i18n_Name
this.Key = &this.RouteId
this.SearchData = &searchData
}
2022-11-14 16:22:39 +00:00
type ByRoute [] *BusStop
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 {
return _a.Direction < _b.Direction
}
return _a.RouteId < _b.RouteId
}