Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ public VehicleLocationRecord createVehicleLocationRecordForUpdate(MonitoredResul
return record;
}

public boolean getIsTripActive(CombinedTripUpdatesAndVehiclePosition update) {
return this.isTripActive(update);
}

private boolean isTripActive(CombinedTripUpdatesAndVehiclePosition update) {
if (update.getTripUpdates().isEmpty())
return false;
Expand All @@ -615,6 +619,14 @@ private boolean isTripActive(CombinedTripUpdatesAndVehiclePosition update) {
long lastPrediction = -1;
StopTimeUpdate firstStopTime = tripUpdate.getStopTimeUpdate(0);
StopTimeUpdate lastStopTime = tripUpdate.getStopTimeUpdate(tripUpdateCount-1);

if (lastStopTime.hasArrival())
if (!lastStopTime.getArrival().hasTime()
&& lastStopTime.getArrival().hasDelay()
&& tripUpdate.getTrip().getScheduleRelationship()
.equals(TripDescriptor.ScheduleRelationship.SCHEDULED))
return true;
Comment thread
TsimurSh marked this conversation as resolved.
Outdated

if (firstStopTime.hasArrival())
firstPrediction = firstStopTime.getArrival().getTime();
else if (firstStopTime.hasDeparture())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,34 @@ public void testCombinedUpdateWithRealtimeVehicleAndAnonVehicle() {
assertEquals("tripC", c.getTripUpdates().get(2).getTrip().getTripId());
}

@Test
public void testIsTripActive_WithDelayNoTimeAndScheduledTrip() {

StopTimeEvent arrival = StopTimeEvent.newBuilder()
.setDelay(30)
.build();

StopTimeUpdate stopTimeUpdate = StopTimeUpdate.newBuilder()
.setArrival(arrival)
.build();

TripDescriptor tripDescriptor = TripDescriptor.newBuilder()
.setScheduleRelationship(TripDescriptor.ScheduleRelationship.SCHEDULED)
.build();

TripUpdate tripUpdate = TripUpdate.newBuilder()
.setTrip(tripDescriptor)
.addStopTimeUpdate(stopTimeUpdate)
.build();

CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition();
update.setTripUpdates(List.of(tripUpdate));
// Act
boolean result = _library.getIsTripActive(update);
// Assert
assertTrue("Trip should be active when StopTimeUpdate has delay and trip is SCHEDULED.", result);
}

private static FeedMessage.Builder createFeed() {
FeedMessage.Builder builder = FeedMessage.newBuilder();
FeedHeader.Builder header = FeedHeader.newBuilder();
Expand Down