Added kmb and refactored query.Parse

This commit is contained in:
2022-09-17 04:33:47 +08:00
parent 292665c49b
commit 3376d9eb96
21 changed files with 762 additions and 241 deletions

View File

@@ -1,5 +1,9 @@
package bus
import (
i18n "github.com/tgckpg/golifehk/i18n"
)
type BusStop struct {
RouteId string
Direction string
@@ -7,27 +11,39 @@ type BusStop struct {
StationId string
Latitude float64
Longtitude float64
Name_zh string
Name_en string
Name *map[string] string
// RouteStops[ StationSeq ] = BusStop
RouteStops *map[int] *BusStop
i18n.Generics
}
func ( busStop BusStop ) PrevStop() *BusStop {
if v, hasKey := (*busStop.RouteStops)[ busStop.StationSeq - 1 ]; hasKey {
func ( this *BusStop ) PrevStop() *BusStop {
if v, hasKey := (*this.RouteStops)[ this.StationSeq - 1 ]; hasKey {
return v
}
return nil
}
func ( busStop BusStop ) NextStop() *BusStop {
if v, hasKey := (*busStop.RouteStops)[ busStop.StationSeq + 1 ]; hasKey {
func ( this *BusStop ) NextStop() *BusStop {
if v, hasKey := (*this.RouteStops)[ this.StationSeq + 1 ]; hasKey {
return v
}
return nil
}
type ByRouteId []BusStop
func ( this *BusStop ) Reload() {
i18n_Name := map[string] string{}
i18n_Name["en"] = this.Name_en
i18n_Name["zh-Hant"] = this.Name_zh
func (a ByRouteId) Len() int { return len(a) }
func (a ByRouteId) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByRouteId) Less(i, j int) bool { return a[i].RouteId < a[j].RouteId }
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
}