timetable-extension #1

Open
fred.boniface wants to merge 163 commits from timetable-extension into main
5 changed files with 66 additions and 4 deletions
Showing only changes of commit 358e69bec7 - Show all commits

View File

@ -40,6 +40,7 @@ func runTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
log.Debug("Running background tasks")
go cif.CheckCif(cfg)
go corpus.CheckCorpus(cfg)
//go stations.Check()
}
}
}

View File

@ -2,6 +2,7 @@ package dbAccess
import (
"context"
"fmt"
"git.fjla.uk/owlboard/go-types/pkg/database"
"go.mongodb.org/mongo-driver/bson"
@ -80,3 +81,15 @@ func CreateCorpusIndexes() error {
}
return nil
}
func GetTiplocFromCrs(crs string) (tiploc string, err error) {
// Return TIPLOC from CRS code
err = fmt.Errorf("not yet written")
return "", err
}
func GetStanoxFromCrs(crs string) (stanox string, err error) {
// Return STANOX from CRS code
err = fmt.Errorf("not yet written")
return "", err
}

View File

@ -16,6 +16,7 @@ import (
"git.fjla.uk/owlboard/timetable-mgr/helpers"
"git.fjla.uk/owlboard/timetable-mgr/log"
"git.fjla.uk/owlboard/timetable-mgr/messaging"
"git.fjla.uk/owlboard/timetable-mgr/stations"
"git.fjla.uk/owlboard/timetable-mgr/vstp"
"go.uber.org/zap"
)
@ -65,6 +66,8 @@ func main() {
go cif.CheckCif(cfg)
go corpus.CheckCorpus(cfg)
stations.Check()
if cfg.VstpOn {
messaging.StompInit(cfg)
vstp.Subscribe()

View File

@ -12,5 +12,8 @@ func run() {
fmt.Println(err)
}
parseData(data, data2)
_, err = parseData(data, data2)
if err != nil {
fmt.Println(err)
}
}

View File

@ -7,6 +7,7 @@ import (
"git.fjla.uk/owlboard/go-types/pkg/database"
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
)
// Parses n number of XML byte arrays
@ -20,9 +21,16 @@ func parseData(data ...[]byte) ([]database.Station, error) {
stations = append(stations, parsedStations...)
}
fmt.Println(stations)
return nil, nil
// Transform from upstreamApi.Station to database.Station
var output []database.Station
for _, s := range stations {
outputStation, err := convertApiToDatabase(s)
if err != nil {
return nil, err
}
output = append(output, outputStation)
}
fmt.Println(output)
return output, nil
}
// Parses XML and converts to struct
@ -38,3 +46,37 @@ func parseXML(data []byte) ([]upstreamApi.Station, error) {
return stationList.Stations, nil
}
// Convert API type to Database type ready for insertion
func convertApiToDatabase(data upstreamApi.Station) (database.Station, error) {
if data.CrsCode == "" {
return database.Station{}, fmt.Errorf("CRS code is required but missing")
}
tiploc, err := dbAccess.GetTiplocFromCrs(data.CrsCode)
if err != nil {
return database.Station{}, err
}
stanox, err := dbAccess.GetStanoxFromCrs(data.CrsCode)
if err != nil {
return database.Station{}, err
}
output := database.Station{
CRS: data.CrsCode,
TIPLOC: tiploc,
STANOX: stanox,
NLCDESC: data.Name,
Location: database.GeoJson{
Type: "Point",
Coordinates: []float64{
data.Longitude,
data.Latitude,
},
},
Operator: data.StationOperator,
}
return output, nil
}