@@ -122,50 +122,50 @@ func (api *RestAPI) BuildTripStatus(
122122 var actualDistance float64
123123 var hasActualDistance bool
124124
125- shapeRows , shapeErr := api .GtfsManager .GtfsDB .Queries .GetShapePointsByTripID (ctx , dbTripID )
126- if shapeErr != nil {
127- slog .Warn ("buildTripStatusCore: failed to get shape points" ,
128- slog .String ("trip_id" , dbTripID ),
129- slog .String ("error" , shapeErr .Error ()))
130- }
131- if shapeErr == nil && len (shapeRows ) > 1 {
125+ shapeRows , shapeErr := api .GtfsManager .GtfsDB .Queries .GetShapePointsByTripID (ctx , dbTripID )
126+ if shapeErr != nil {
127+ slog .Warn ("buildTripStatusCore: failed to get shape points" ,
128+ slog .String ("trip_id" , dbTripID ),
129+ slog .String ("error" , shapeErr .Error ()))
130+ }
131+ if shapeErr == nil && len (shapeRows ) > 1 {
132132 shapePoints = shapeRowsToPoints (shapeRows )
133133 cumulativeDistances = preCalculateCumulativeDistances (shapePoints )
134- status .TotalDistanceAlongTrip = cumulativeDistances [len (cumulativeDistances )- 1 ]
134+ status .TotalDistanceAlongTrip = cumulativeDistances [len (cumulativeDistances )- 1 ]
135135
136- if vehicle != nil && vehicle .Position != nil && vehicle .Position .Latitude != nil && vehicle .Position .Longitude != nil {
137- // Refine the raw GPS position (set by BuildVehicleStatus) by projecting
138- // it onto the route shape. Reuses the already-fetched shapePoints.
136+ if vehicle != nil && vehicle .Position != nil && vehicle .Position .Latitude != nil && vehicle .Position .Longitude != nil {
137+ // Refine the raw GPS position (set by BuildVehicleStatus) by projecting
138+ // it onto the route shape. Reuses the already-fetched shapePoints.
139139 actualDistance = api .getVehicleDistanceAlongShapeContextual (ctx , activeTripRawID , vehicle )
140- status .DistanceAlongTrip = actualDistance
140+ status .DistanceAlongTrip = actualDistance
141141 hasActualDistance = true
142142
143- if status .LastKnownLocation != nil {
144- actualPosition := * status .LastKnownLocation
143+ if status .LastKnownLocation != nil {
144+ actualPosition := * status .LastKnownLocation
145145
146- if projected := projectPositionWithShapePoints (shapePoints , actualPosition ); projected != nil {
147- status .Position = * projected
148- }
146+ if projected := projectPositionWithShapePoints (shapePoints , actualPosition ); projected != nil {
147+ status .Position = * projected
148+ }
149149
150- // If the feed does not provide a bearing, infer orientation from the
151- // heading of the closest shape segment at the vehicle's position.
152- if vehicle .Position .Bearing == nil {
153- if inferred := inferOrientationFromShape (actualPosition .Lat , actualPosition .Lon , shapePoints ); inferred >= 0 {
154- status .Orientation = inferred
155- status .LastKnownOrientation = inferred
150+ // If the feed does not provide a bearing, infer orientation from the
151+ // heading of the closest shape segment at the vehicle's position.
152+ if vehicle .Position .Bearing == nil {
153+ if inferred := inferOrientationFromShape (actualPosition .Lat , actualPosition .Lon , shapePoints ); inferred >= 0 {
154+ status .Orientation = inferred
155+ status .LastKnownOrientation = inferred
156+ }
156157 }
157158 }
158- }
159159
160- if scheduleDeviation != 0 && len (stopTimes ) > 0 {
161- scheduledDistance := api .calculateEffectiveDistanceAlongTrip (
162- ctx , actualDistance , scheduleDeviation , currentTime , serviceDate ,
163- stopTimes , shapePoints , cumulativeDistances ,
164- )
165- status .ScheduledDistanceAlongTrip = scheduledDistance
160+ if scheduleDeviation != 0 && len (stopTimes ) > 0 {
161+ scheduledDistance := api .calculateEffectiveDistanceAlongTrip (
162+ ctx , actualDistance , scheduleDeviation , currentTime , serviceDate ,
163+ stopTimes , shapePoints , cumulativeDistances ,
164+ )
165+ status .ScheduledDistanceAlongTrip = scheduledDistance
166+ }
166167 }
167168 }
168- }
169169
170170 if vehicle != nil && vehicle .Position != nil {
171171 if vehicle .StopID != nil && * vehicle .StopID != "" {
@@ -914,7 +914,7 @@ func (api *RestAPI) findStopsByDistance(
914914 }
915915
916916 var closestStop * gtfsdb.StopTime
917- var closestDistDiff float64 = math .MaxFloat64
917+ var closestDistDiff = math .MaxFloat64
918918
919919 var nextStop * gtfsdb.StopTime
920920
0 commit comments