Full processing pipeline minus coordinate gathering
This commit is contained in:
parent
3f38224d1e
commit
5e3d39c62d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
output
|
57
main.go
57
main.go
@ -96,6 +96,10 @@ type CombiLine struct {
|
||||
Color string `json:"color"`
|
||||
}
|
||||
|
||||
type CombiRouteContainer struct {
|
||||
Routes []CombiRoute
|
||||
}
|
||||
|
||||
type CombiRoute struct {
|
||||
Name string `json:"name"`
|
||||
Departure []float64 `json:"departure"`
|
||||
@ -151,6 +155,8 @@ func main() {
|
||||
|
||||
// Create a map from string to CombiLine
|
||||
combiLineMap := make(map[string]*CombiLine)
|
||||
// Create a map for CombiRoute, grouped by CombiLine.Id
|
||||
combiRoutesMap := make(map[int]*CombiRouteContainer)
|
||||
|
||||
// Populate the map
|
||||
for _, combi := range combis {
|
||||
@ -164,21 +170,66 @@ func main() {
|
||||
Color: combi.Color,
|
||||
}
|
||||
combiLineMap[combi.Company] = &combiLine
|
||||
|
||||
// create the route container
|
||||
combiRoutesMap[combi.Id] = &CombiRouteContainer{
|
||||
Routes: make([]CombiRoute, 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert each CombiData into a CombiRoute and store it
|
||||
for _, combi := range combis {
|
||||
combiRoute := CombiRoute{
|
||||
Name: combi.Ref,
|
||||
Departure: make([]float64, 0),
|
||||
Return: make([]float64, 0),
|
||||
}
|
||||
combiLineSlice := combiRoutesMap[combi.Id]
|
||||
combiLineSlice.Routes = append(combiLineSlice.Routes, combiRoute)
|
||||
}
|
||||
|
||||
writeOutput(combiLineMap, combiRoutesMap)
|
||||
}
|
||||
|
||||
func writeOutput(lines map[string]*CombiLine, routes map[int]*CombiRouteContainer) {
|
||||
// Create output folder
|
||||
os.MkdirAll("output", os.ModePerm)
|
||||
|
||||
//
|
||||
// Write the lines JSON file
|
||||
//
|
||||
|
||||
// convert the map into an array
|
||||
combiLineSlice := make([]*CombiLine, 0)
|
||||
for _, combiLine := range combiLineMap {
|
||||
for _, combiLine := range lines {
|
||||
combiLineSlice = append(combiLineSlice, combiLine)
|
||||
}
|
||||
|
||||
// print JSON
|
||||
jsonStr, err := json.Marshal(combiLineSlice)
|
||||
jsonBytes, err := json.Marshal(combiLineSlice)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Print(string(jsonStr[:]))
|
||||
os.WriteFile("output/lines.json", jsonBytes, 0644)
|
||||
|
||||
//
|
||||
// Write each JSON file for the routes
|
||||
//
|
||||
for lineId, routeContainer := range routes {
|
||||
outFilename := fmt.Sprintf("output/routes_%d.json", lineId)
|
||||
jsonBytes, err := json.Marshal(routeContainer.Routes)
|
||||
if err != nil {
|
||||
panic(nil)
|
||||
}
|
||||
// write
|
||||
err = os.WriteFile(outFilename, jsonBytes, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
log.Print("JSON files written to output/")
|
||||
}
|
||||
|
||||
func parseCombiData(member OsmRelation) CombiData {
|
||||
|
Loading…
Reference in New Issue
Block a user