penguin/golifehk

@golifehk bot in Telegram

datasources/kmb/RouteStop.go

raw ยท 1381 bytes

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.Words
	query.NoGeoLocation
}

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
}

func (this *RouteStop) Reload() {

	this.Key = &this.RouteId
	this.SearchData = this.BusStop.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
}