timetable-extension #1

Open
fred.boniface wants to merge 154 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") log.Debug("Running background tasks")
go cif.CheckCif(cfg) go cif.CheckCif(cfg)
go corpus.CheckCorpus(cfg) go corpus.CheckCorpus(cfg)
//go stations.Check()
} }
} }
} }

View File

@ -2,6 +2,7 @@ package dbAccess
import ( import (
"context" "context"
"fmt"
"git.fjla.uk/owlboard/go-types/pkg/database" "git.fjla.uk/owlboard/go-types/pkg/database"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
@ -80,3 +81,15 @@ func CreateCorpusIndexes() error {
} }
return nil 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/helpers"
"git.fjla.uk/owlboard/timetable-mgr/log" "git.fjla.uk/owlboard/timetable-mgr/log"
"git.fjla.uk/owlboard/timetable-mgr/messaging" "git.fjla.uk/owlboard/timetable-mgr/messaging"
"git.fjla.uk/owlboard/timetable-mgr/stations"
"git.fjla.uk/owlboard/timetable-mgr/vstp" "git.fjla.uk/owlboard/timetable-mgr/vstp"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -65,6 +66,8 @@ func main() {
go cif.CheckCif(cfg) go cif.CheckCif(cfg)
go corpus.CheckCorpus(cfg) go corpus.CheckCorpus(cfg)
stations.Check()
if cfg.VstpOn { if cfg.VstpOn {
messaging.StompInit(cfg) messaging.StompInit(cfg)
vstp.Subscribe() vstp.Subscribe()

View File

@ -12,5 +12,8 @@ func run() {
fmt.Println(err) 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/database"
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi" "git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
) )
// Parses n number of XML byte arrays // Parses n number of XML byte arrays
@ -20,9 +21,16 @@ func parseData(data ...[]byte) ([]database.Station, error) {
stations = append(stations, parsedStations...) stations = append(stations, parsedStations...)
} }
fmt.Println(stations) var output []database.Station
return nil, nil for _, s := range stations {
// Transform from upstreamApi.Station to database.Station 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 // Parses XML and converts to struct
@ -38,3 +46,37 @@ func parseXML(data []byte) ([]upstreamApi.Station, error) {
return stationList.Stations, nil 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
}