Partially working draft
This commit is contained in:
@@ -12,19 +12,6 @@ import (
|
||||
"github.com/tgckpg/golifehk/utils"
|
||||
)
|
||||
|
||||
type BusStop struct {
|
||||
RouteId string
|
||||
Direction string
|
||||
StationSeq string
|
||||
StationId string
|
||||
Latitude float64
|
||||
Longtitude float64
|
||||
Name_zhant string
|
||||
Name_en string
|
||||
}
|
||||
|
||||
var mBusStops *map[string]BusStop
|
||||
|
||||
var CSV_BUSSTOPS string = filepath.Join( utils.WORKDIR, "mtr_bus_stops.csv" )
|
||||
|
||||
func readBusStopData( r io.Reader ) ( *map[string]BusStop, error ) {
|
||||
@@ -36,6 +23,8 @@ func readBusStopData( r io.Reader ) ( *map[string]BusStop, error ) {
|
||||
}
|
||||
|
||||
busStops := map[string]BusStop{}
|
||||
routeStops := map[string] map[string] map[int] *BusStop{}
|
||||
|
||||
var headers []string
|
||||
for i, line := range entries {
|
||||
if i == 0 {
|
||||
@@ -45,6 +34,8 @@ func readBusStopData( r io.Reader ) ( *map[string]BusStop, error ) {
|
||||
}
|
||||
|
||||
var entry BusStop
|
||||
i18n_Name := map[string] string{}
|
||||
|
||||
for j, value := range line {
|
||||
switch headers[j] {
|
||||
case "ROUTE_ID":
|
||||
@@ -52,7 +43,8 @@ func readBusStopData( r io.Reader ) ( *map[string]BusStop, error ) {
|
||||
case "DIRECTION":
|
||||
entry.Direction = value
|
||||
case "STATION_SEQNO":
|
||||
entry.StationSeq = value
|
||||
v, _ := strconv.Atoi( value )
|
||||
entry.StationSeq = v
|
||||
case "STATION_ID":
|
||||
entry.StationId = value
|
||||
case "STATION_LATITUDE":
|
||||
@@ -62,9 +54,9 @@ func readBusStopData( r io.Reader ) ( *map[string]BusStop, error ) {
|
||||
v, _ := strconv.ParseFloat( value, 64 )
|
||||
entry.Longtitude = v
|
||||
case "STATION_NAME_CHI":
|
||||
entry.Name_zhant = value
|
||||
i18n_Name["zh"] = value
|
||||
case "STATION_NAME_ENG":
|
||||
entry.Name_en = value
|
||||
i18n_Name["en"] = value
|
||||
default:
|
||||
return nil, fmt.Errorf( "Unknown header \"%s\"", headers[j] )
|
||||
}
|
||||
@@ -74,6 +66,26 @@ func readBusStopData( r io.Reader ) ( *map[string]BusStop, error ) {
|
||||
return nil, fmt.Errorf( "Duplicated entry %+v", entry )
|
||||
}
|
||||
|
||||
routeDir, hasKey := routeStops[ entry.RouteId ]
|
||||
if !hasKey {
|
||||
routeStops[ entry.RouteId ] = map[string] map[int] *BusStop{}
|
||||
routeDir = routeStops[ entry.RouteId ]
|
||||
}
|
||||
|
||||
route, hasKey := routeDir[ entry.Direction ]
|
||||
if !hasKey {
|
||||
routeDir[ entry.Direction ] = map[int] *BusStop{}
|
||||
route = routeDir[ entry.Direction ]
|
||||
}
|
||||
|
||||
_, hasKey = route[ entry.StationSeq ]
|
||||
if !hasKey {
|
||||
route[ entry.StationSeq ] = &entry
|
||||
}
|
||||
|
||||
entry.Name = &i18n_Name
|
||||
entry.RouteStops = &route
|
||||
|
||||
busStops[ entry.StationId ] = entry
|
||||
}
|
||||
return &busStops, nil
|
||||
|
||||
Reference in New Issue
Block a user