Properly handle REFERENCE_ID for future changes

This commit is contained in:
2025-12-16 20:17:45 +08:00
parent 6e94adbed4
commit 36e077c910
4 changed files with 227 additions and 165 deletions

View File

@@ -4,7 +4,6 @@ import (
"encoding/csv"
"fmt"
"io"
"log"
"net/http"
"path/filepath"
"strconv"
@@ -63,21 +62,16 @@ func readBusStopData(r io.Reader) (*map[string]*BusStop, error) {
}
}
// Ignoring special route for now as getSchedule does not reflect
// which bus is a special route
if entry.ReferenceId != entry.RouteId {
log.Printf("Ignoring special Route: %s", entry.ReferenceId)
continue
}
entryId := fmt.Sprintf("%s:%s", entry.ReferenceId, entry.StationId)
if busStops[entry.StationId] != nil {
if busStops[entryId] != nil {
return nil, fmt.Errorf("Duplicated entry %+v", entry)
}
routeDir, hasKey := routeStops[entry.RouteId]
routeDir, hasKey := routeStops[entry.ReferenceId]
if !hasKey {
routeStops[entry.RouteId] = map[string]map[int]*BusStop{}
routeDir = routeStops[entry.RouteId]
routeStops[entry.ReferenceId] = map[string]map[int]*BusStop{}
routeDir = routeStops[entry.ReferenceId]
}
route, hasKey := routeDir[entry.Direction]
@@ -94,7 +88,7 @@ func readBusStopData(r io.Reader) (*map[string]*BusStop, error) {
entry.RouteStops = &route
entry.Reload()
busStops[entry.StationId] = &entry
busStops[entryId] = &entry
}
return &busStops, nil
}