szczanieckiej.git

commit 90a29fb10412f4b2ccb2e07e386cdc90543d3ce6

Author: Adam <git@apiote.xyz>

fix problem with stop sequence while getting stopStub

 traffic/access.go | 16 +++++++++++++++-


diff --git a/traffic/access.go b/traffic/access.go
index 6c95b7ebf5ec52eb80bf233f1b95f97294f87ab7..375544ffead8855c21aaafb24ad23f84b1160c30 100644
--- a/traffic/access.go
+++ b/traffic/access.go
@@ -942,13 +942,27 @@ 			stopOrder = order.Sequence
 			break
 		}
 	}
+	if stopOrder == -1 {
+		return StopStub{}, fmt.Errorf("cannot the stop on given line")
+	}
+
+	var departure *Departure
+	for _, d := range trip.Departures {
+		if d.StopSequence == stopOrder { // todo binary search
+			departure = &d
+			break
+		}
+	}
+	if departure == nil {
+		return StopStub{}, fmt.Errorf("cannot find departure at sequence %d", stopOrder)
+	}
 
 	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,
+		OnDemand: departure.Pickup == BY_DRIVER || departure.Dropoff == BY_DRIVER,
 	}
 	return stopStub, nil
 }