Author: Adam <git@apiote.xyz>
change lines, stopStub, lineGraph
api/api.go | 68 +++++++++++++++++++++++------------------------ api/structs_gen.go | 15 ++++----- traffic/access.go | 2 + traffic/structs.go | 1
diff --git a/api/api.go b/api/api.go index 743e589baf09e26c0d4a62baf6f40574eb0a2911..3ea43a208d1ce0e820e460493b588ea41922933e 100644 --- a/api/api.go +++ b/api/api.go @@ -10,7 +10,6 @@ "encoding/hex" "errors" "fmt" - //"image/color" "log" "sort" "time" @@ -66,55 +65,56 @@ } return s } -func convertTrafficStopStub(stopStub traffic.StopStub) /*StopStub*/ { - /*s := StopStub{ +func convertTrafficStopStub(stopStub traffic.StopStub) StopStubV1 { + s := StopStubV1{ Code: stopStub.Code, Name: stopStub.Name, + NodeName: stopStub.NodeName, Zone: stopStub.Zone, OnDemand: stopStub.OnDemand, } - return s*/ + return s } -func convertTrafficLineGraphs(trafficLine traffic.Line, line any /*Line*/, context traffic.Context, t *traffic.Traffic) /*(Line, error)*/ { - /*for _, code := range trafficLine.GraphThere.StopCodes { - stopStub, err := traffic.GetStopStub(traffic.ID(code), line.Name, context, t) +func convertTrafficLineGraphs(trafficLine traffic.Line, line LineV1, context traffic.Context, t *traffic.Traffic) (LineV1, error) { + line.Graphs = [2]LineGraphV1{ + { + Stops: make([]StopStubV1, len(trafficLine.GraphThere.StopCodes)), + NextNodes: trafficLine.GraphThere.NextNodes, + }, + { + Stops: make([]StopStubV1, len(trafficLine.GraphBack.StopCodes)), + NextNodes: trafficLine.GraphBack.NextNodes, + }, + } + + for i, code := range trafficLine.GraphThere.StopCodes { + stopStub, err := traffic.GetStopStub(code, line.Name, context, t) if err != nil { return line, fmt.Errorf("while getting stopStub for %s: %w", code, err) } - line.GraphThere.Stops = append(line.GraphThere.Stops, - convertTrafficStopStub(stopStub)) + line.Graphs[0].Stops[i] = convertTrafficStopStub(stopStub) } - - for _, code := range trafficLine.GraphBack.StopCodes { - stopStub, err := traffic.GetStopStub(traffic.ID(code), line.Name, context, t) + for i, code := range trafficLine.GraphBack.StopCodes { + stopStub, err := traffic.GetStopStub(code, line.Name, context, t) if err != nil { return line, fmt.Errorf("while getting stopStub for %s: %w", code, err) } - line.GraphBack.Stops = append(line.GraphBack.Stops, - convertTrafficStopStub(stopStub)) + line.Graphs[0].Stops[i] = convertTrafficStopStub(stopStub) } - return line, nil*/ + + return line, nil } -func convertTrafficLine(line traffic.Line, context traffic.Context, t *traffic.Traffic) LineV1 { - return LineV1{ - Name: line.Name, - Colour: fromColor(line.Colour), - Kind: makeLineTypeV2(line), - HeadsignsThere: line.HeadsignsThere, - HeadsignsBack: line.HeadsignsBack, - GraphThere: LineGraphV1{ - Stops: []StopStubV1{}, - NextNodes: line.GraphThere.NextNodes, - PrevNodes: line.GraphThere.PrevNodes, - }, - GraphBack: LineGraphV1{ - Stops: []StopStubV1{}, - NextNodes: line.GraphBack.NextNodes, - PrevNodes: line.GraphBack.PrevNodes, - }, +func convertTrafficLine(line traffic.Line, feedID string, convertGraphs bool) LineV1 { + l := LineV1{ + Name: line.Name, + Colour: fromColor(line.Colour), + Kind: makeLineTypeV2(line), + FeedID: feedID, + Headsigns: [2][]string{line.HeadsignsThere, line.HeadsignsBack}, } + return l } func convertTrafficVehicle(vehicle traffic.VehicleStatus, context traffic.Context, t *traffic.Traffic) (VehicleV1, error) { @@ -240,9 +240,7 @@ if stop, ok := item.(traffic.Stop); ok { s := convertTrafficStopV2(stop, context.FeedName) success.Queryables = append(success.Queryables, QueryableV2(s)) } else if line, ok := item.(traffic.Line); ok { - l := convertTrafficLine(line, context, t) - l.GraphThere = LineGraphV1{} - l.GraphBack = LineGraphV1{} + l := convertTrafficLine(line, context.FeedName, false) success.Queryables = append(success.Queryables, QueryableV2(l)) } else { // todo error diff --git a/api/structs_gen.go b/api/structs_gen.go index 351076cfc5dea249724d4f3c3aa00aec7988449a..3e02d4df9cdc61f7d6b5a404d635fd3364a5b097 100644 --- a/api/structs_gen.go +++ b/api/structs_gen.go @@ -106,13 +106,12 @@ return bare.Marshal(t) } type LineV1 struct { - Name string `bare:"name"` - Colour ColourV1 `bare:"colour"` - Kind LineTypeV2 `bare:"kind"` - HeadsignsThere []string `bare:"headsignsThere"` - HeadsignsBack []string `bare:"headsignsBack"` - GraphThere LineGraphV1 `bare:"graphThere"` - GraphBack LineGraphV1 `bare:"graphBack"` + Name string `bare:"name"` + Colour ColourV1 `bare:"colour"` + Kind LineTypeV2 `bare:"kind"` + FeedID string `bare:"feedID"` + Headsigns [2][]string `bare:"headsigns"` + Graphs [2]LineGraphV1 `bare:"graphs"` } func (t *LineV1) Decode(data []byte) error { @@ -126,7 +125,6 @@ type LineGraphV1 struct { Stops []StopStubV1 `bare:"stops"` NextNodes map[int][]int `bare:"nextNodes"` - PrevNodes map[int][]int `bare:"prevNodes"` } func (t *LineGraphV1) Decode(data []byte) error { @@ -140,6 +138,7 @@ type StopStubV1 struct { Code string `bare:"code"` Name string `bare:"name"` + NodeName string `bare:"nodeName"` Zone string `bare:"zone"` OnDemand bool `bare:"onDemand"` } diff --git a/traffic/access.go b/traffic/access.go index 034ff87e56263292d2a998d73d37b7c060121b22..6c95b7ebf5ec52eb80bf233f1b95f97294f87ab7 100644 --- a/traffic/access.go +++ b/traffic/access.go @@ -807,6 +807,7 @@ stubs = append(stubs, TimedStopStub{ StopStub: StopStub{ Code: stop.Code, Name: stop.Name, + NodeName: stop.NodeName, Zone: stop.Zone, OnDemand: departure.Pickup == BY_DRIVER || departure.Dropoff == BY_DRIVER, }, @@ -945,6 +946,7 @@ stopStub := StopStub{ Code: stop.Code, Name: stop.Name, + NodeName: stop.NodeName, Zone: stop.Zone, OnDemand: trip.Departures[stopOrder].Pickup == BY_DRIVER || trip.Departures[stopOrder].Dropoff == BY_DRIVER, } diff --git a/traffic/structs.go b/traffic/structs.go index eec7e43349a5ce8857a165ed0cf8bb076d67f0c6..ad2a0d579c069defd352cc112228c789953154c1 100644 --- a/traffic/structs.go +++ b/traffic/structs.go @@ -205,6 +205,7 @@ type StopStub struct { Code string Name string + NodeName string Zone string OnDemand bool }