Skip to content

Commit

Permalink
Align names with GTFS-RT spec
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jun 6, 2024
1 parent 67505c8 commit 95d5bc1
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.TRIP_NOT_FOUND;
import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.TRIP_NOT_FOUND_IN_PATTERN;
import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.UNKNOWN;
import static org.opentripplanner.updater.trip.UpdateSemantics.FULL;
import static org.opentripplanner.updater.trip.UpdateIncrementality.FULL_DATASET;

import java.time.LocalDate;
import java.util.ArrayList;
Expand All @@ -30,7 +30,7 @@
import org.opentripplanner.updater.spi.UpdateResult;
import org.opentripplanner.updater.spi.UpdateSuccess;
import org.opentripplanner.updater.trip.AbstractTimetableSnapshotSource;
import org.opentripplanner.updater.trip.UpdateSemantics;
import org.opentripplanner.updater.trip.UpdateIncrementality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.org.siri.siri20.EstimatedTimetableDeliveryStructure;
Expand Down Expand Up @@ -81,15 +81,16 @@ public SiriTimetableSnapshotSource(
* FIXME RT_AB: TripUpdate is the GTFS term, and these SIRI ETs are never converted into that
* same internal model.
*
* @param semantics the semantics of the update, for example list with updates represent all
* updates that are active right now, i.e. all previous updates should be disregarded
* @param incrementality the incrementality of the update, for example if updates represent all
* updates that are active right now, i.e. all previous updates should be
* disregarded
* @param updates SIRI EstimatedTimetable deliveries that should be applied atomically.
*/
public UpdateResult applyEstimatedTimetable(
@Nullable SiriFuzzyTripMatcher fuzzyTripMatcher,
EntityResolver entityResolver,
String feedId,
UpdateSemantics semantics,
UpdateIncrementality incrementality,
List<EstimatedTimetableDeliveryStructure> updates
) {
if (updates == null) {
Expand All @@ -100,7 +101,7 @@ public UpdateResult applyEstimatedTimetable(
List<Result<UpdateSuccess, UpdateError>> results = new ArrayList<>();

withLock(() -> {
if (semantics == FULL) {
if (incrementality == FULL_DATASET) {
// Remove all updates from the buffer
buffer.clear(feedId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opentripplanner.ext.siri.updater;

import java.util.Optional;
import org.opentripplanner.updater.trip.UpdateSemantics;
import org.opentripplanner.updater.trip.UpdateIncrementality;
import uk.org.siri.siri20.Siri;

/**
Expand All @@ -20,9 +20,9 @@ public interface EstimatedTimetableSource {

/**
* @return The update semantics of the last collection of updates.
* {@link UpdateSemantics}
* {@link UpdateIncrementality}
*/
UpdateSemantics updateSemanticsOfLastUpdates();
UpdateIncrementality incrementalityOfLastUpdates();

String getFeedId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.opentripplanner.updater.spi.GraphUpdater;
import org.opentripplanner.updater.spi.UpdateResult;
import org.opentripplanner.updater.spi.WriteToGraphCallback;
import org.opentripplanner.updater.trip.UpdateSemantics;
import org.opentripplanner.updater.trip.UpdateIncrementality;
import org.opentripplanner.updater.trip.metrics.TripUpdateMetrics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -373,7 +373,7 @@ private void processSiriData(ByteString data) {
fuzzyTripMatcher,
entityResolver,
feedId,
UpdateSemantics.INCREMENTAL,
UpdateIncrementality.DIFFERENTIAL,
estimatedTimetableDeliveries
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opentripplanner.ext.siri.updater;

import static org.opentripplanner.updater.trip.UpdateSemantics.FULL;
import static org.opentripplanner.updater.trip.UpdateSemantics.INCREMENTAL;
import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL;
import static org.opentripplanner.updater.trip.UpdateIncrementality.FULL_DATASET;

import java.time.Duration;
import java.time.ZonedDateTime;
Expand All @@ -10,7 +10,7 @@
import javax.annotation.Nullable;
import org.opentripplanner.framework.io.OtpHttpClientException;
import org.opentripplanner.updater.spi.HttpHeaders;
import org.opentripplanner.updater.trip.UpdateSemantics;
import org.opentripplanner.updater.trip.UpdateIncrementality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.org.siri.siri20.Siri;
Expand All @@ -32,7 +32,7 @@ public class SiriETHttpTripUpdateSource implements EstimatedTimetableSource {
/**
* The update semantics of the last received collection of updates.
*/
private UpdateSemantics updateSemantics = FULL;
private UpdateIncrementality updateIncrementality = FULL_DATASET;
private ZonedDateTime lastTimestamp = ZonedDateTime.now().minusMonths(1);

public SiriETHttpTripUpdateSource(Parameters parameters) {
Expand Down Expand Up @@ -64,7 +64,7 @@ public Optional<Siri> getUpdates() {
lastTimestamp = serviceDelivery.getResponseTimestamp();

//All subsequent requests will return changes since last request
updateSemantics = INCREMENTAL;
updateIncrementality = DIFFERENTIAL;
return siri;
} catch (OtpHttpClientException e) {
LOG.info("Failed after {} ms", (System.currentTimeMillis() - t1));
Expand All @@ -77,8 +77,8 @@ public Optional<Siri> getUpdates() {
}

@Override
public UpdateSemantics updateSemanticsOfLastUpdates() {
return updateSemantics;
public UpdateIncrementality incrementalityOfLastUpdates() {
return updateIncrementality;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void runPolling() {
do {
var updates = updateSource.getUpdates();
if (updates.isPresent()) {
var updateSemantics = updateSource.updateSemanticsOfLastUpdates();
var incrementality = updateSource.incrementalityOfLastUpdates();
ServiceDelivery serviceDelivery = updates.get().getServiceDelivery();
moreData = Boolean.TRUE.equals(serviceDelivery.isMoreData());
// Mark this updater as primed after last page of updates. Copy moreData into a final
Expand All @@ -104,7 +104,7 @@ public void runPolling() {
fuzzyTripMatcher,
entityResolver,
feedId,
updateSemantics,
incrementality,
etds
);
ResultLogger.logUpdateResult(feedId, "siri-et", result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.opentripplanner.transit.service.TransitModel;
import org.opentripplanner.updater.spi.ResultLogger;
import org.opentripplanner.updater.spi.UpdateResult;
import org.opentripplanner.updater.trip.UpdateSemantics;
import org.opentripplanner.updater.trip.UpdateIncrementality;
import org.opentripplanner.updater.trip.metrics.TripUpdateMetrics;
import org.rutebanken.siri20.util.SiriXml;
import org.slf4j.Logger;
Expand Down Expand Up @@ -103,7 +103,7 @@ private Future<?> processMessage(List<EstimatedTimetableDeliveryStructure> updat
fuzzyTripMatcher(),
entityResolver(),
feedId,
UpdateSemantics.INCREMENTAL,
UpdateIncrementality.DIFFERENTIAL,
updates
);
ResultLogger.logUpdateResultErrors(feedId, "siri-et", result);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opentripplanner.updater.trip;

import static org.opentripplanner.updater.trip.UpdateSemantics.FULL;
import static org.opentripplanner.updater.trip.UpdateSemantics.INCREMENTAL;
import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL;
import static org.opentripplanner.updater.trip.UpdateIncrementality.FULL_DATASET;

import com.google.protobuf.ExtensionRegistry;
import com.google.transit.realtime.GtfsRealtime;
Expand All @@ -28,7 +28,7 @@ public class GtfsRealtimeTripUpdateSource {
private final String feedId;
private final String url;
private final HttpHeaders headers;
private UpdateSemantics updateSemantics = FULL;
private UpdateIncrementality updateIncrementality = FULL_DATASET;
private final ExtensionRegistry registry = ExtensionRegistry.newInstance();
private final OtpHttpClient otpHttpClient;

Expand All @@ -44,7 +44,7 @@ public List<TripUpdate> getUpdates() {
FeedMessage feedMessage;
List<FeedEntity> feedEntityList;
List<TripUpdate> updates = null;
updateSemantics = FULL;
updateIncrementality = FULL_DATASET;
try {
// Decode message
feedMessage =
Expand All @@ -64,7 +64,7 @@ public List<TripUpdate> getUpdates() {
.getIncrementality()
.equals(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL)
) {
updateSemantics = INCREMENTAL;
updateIncrementality = DIFFERENTIAL;
}

// Create List of TripUpdates
Expand All @@ -91,7 +91,7 @@ public String toString() {
* @return the semantics of the last list with updates, i.e. if all previous updates
* should be disregarded
*/
public UpdateSemantics updateSemanticsOfLastUpdates() {
return updateSemantics;
public UpdateIncrementality incrementalityOfLastUpdates() {
return updateIncrementality;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opentripplanner.updater.trip;

import static org.opentripplanner.updater.trip.UpdateSemantics.FULL;
import static org.opentripplanner.updater.trip.UpdateSemantics.INCREMENTAL;
import static org.opentripplanner.updater.trip.UpdateIncrementality.DIFFERENTIAL;
import static org.opentripplanner.updater.trip.UpdateIncrementality.FULL_DATASET;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.transit.realtime.GtfsRealtime;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void connectionLost(Throwable cause) {
@Override
public void messageArrived(String topic, MqttMessage message) {
List<GtfsRealtime.TripUpdate> updates = null;
UpdateSemantics updateSemantics = FULL;
UpdateIncrementality updateIncrementality = FULL_DATASET;
try {
// Decode message
GtfsRealtime.FeedMessage feedMessage = GtfsRealtime.FeedMessage.PARSER.parseFrom(
Expand All @@ -159,7 +159,7 @@ public void messageArrived(String topic, MqttMessage message) {
.getIncrementality()
.equals(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL)
) {
updateSemantics = INCREMENTAL;
updateIncrementality = DIFFERENTIAL;
}

// Create List of TripUpdates
Expand All @@ -180,7 +180,7 @@ public void messageArrived(String topic, MqttMessage message) {
snapshotSource,
fuzzyTripMatcher,
backwardsDelayPropagationType,
updateSemantics,
updateIncrementality,
updates,
feedId,
recordMetrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ public void setup(WriteToGraphCallback writeToGraphCallback) {
public void runPolling() {
// Get update lists from update source
List<TripUpdate> updates = updateSource.getUpdates();
var updateSemantics = updateSource.updateSemanticsOfLastUpdates();
var incrementality = updateSource.incrementalityOfLastUpdates();

if (updates != null) {
// Handle trip updates via graph writer runnable
TripUpdateGraphWriterRunnable runnable = new TripUpdateGraphWriterRunnable(
snapshotSource,
fuzzyTripMatcher,
backwardsDelayPropagationType,
updateSemantics,
incrementality,
updates,
feedId,
recordMetrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.TOO_FEW_STOPS;
import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.TRIP_ALREADY_EXISTS;
import static org.opentripplanner.updater.spi.UpdateError.UpdateErrorType.TRIP_NOT_FOUND;
import static org.opentripplanner.updater.trip.UpdateSemantics.FULL;
import static org.opentripplanner.updater.trip.UpdateIncrementality.FULL_DATASET;

import com.google.common.base.Preconditions;
import com.google.common.collect.Multimaps;
Expand Down Expand Up @@ -126,14 +126,14 @@ public TimetableSnapshotSource(
*
* @param backwardsDelayPropagationType Defines when delays are propagated to previous stops and
* if these stops are given the NO_DATA flag.
* @param updateSemantics Determines the semantics of the updates. FULL updates clear the buffer
* @param updateIncrementality Determines the semantics of the updates. FULL updates clear the buffer
* of all previous updates for the given feed id.
* @param updates GTFS-RT TripUpdate's that should be applied atomically
*/
public UpdateResult applyTripUpdates(
GtfsRealtimeFuzzyTripMatcher fuzzyTripMatcher,
BackwardsDelayPropagationType backwardsDelayPropagationType,
UpdateSemantics updateSemantics,
UpdateIncrementality updateIncrementality,
List<TripUpdate> updates,
String feedId
) {
Expand All @@ -146,7 +146,7 @@ public UpdateResult applyTripUpdates(
List<Result<UpdateSuccess, UpdateError>> results = new ArrayList<>();

withLock(() -> {
if (updateSemantics == FULL) {
if (updateIncrementality == FULL_DATASET) {
// Remove all updates from the buffer
buffer.clear(feedId);
}
Expand Down Expand Up @@ -249,7 +249,7 @@ public UpdateResult applyTripUpdates(

var updateResult = UpdateResult.ofResults(results);

if (updateSemantics == FULL) {
if (updateIncrementality == FULL_DATASET) {
logUpdateResult(feedId, failuresByRelationship, updateResult);
}
return updateResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class TripUpdateGraphWriterRunnable implements GraphWriterRunnable {

private final UpdateSemantics updateSemantics;
private final UpdateIncrementality updateIncrementality;

/**
* The list with updates to apply to the graph
Expand All @@ -31,15 +31,15 @@ class TripUpdateGraphWriterRunnable implements GraphWriterRunnable {
TimetableSnapshotSource snapshotSource,
GtfsRealtimeFuzzyTripMatcher fuzzyTripMatcher,
BackwardsDelayPropagationType backwardsDelayPropagationType,
UpdateSemantics updateSemantics,
UpdateIncrementality updateIncrementality,
List<TripUpdate> updates,
String feedId,
Consumer<UpdateResult> sendMetrics
) {
this.snapshotSource = snapshotSource;
this.fuzzyTripMatcher = fuzzyTripMatcher;
this.backwardsDelayPropagationType = backwardsDelayPropagationType;
this.updateSemantics = updateSemantics;
this.updateIncrementality = updateIncrementality;
this.updates = Objects.requireNonNull(updates);
this.feedId = Objects.requireNonNull(feedId);
this.sendMetrics = sendMetrics;
Expand All @@ -50,7 +50,7 @@ public void run(Graph graph, TransitModel transitModel) {
var result = snapshotSource.applyTripUpdates(
fuzzyTripMatcher,
backwardsDelayPropagationType,
updateSemantics,
updateIncrementality,
updates,
feedId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
* Describes the semantics of a collection of realtime updates and how they are related to previous
* ones.
*/
public enum UpdateSemantics {
public enum UpdateIncrementality {
/**
* The update contains all available realtime information for all trips in a given feed. The
* previously stored updates must be deleted and replaced with the information from this one.
*/
FULL,
FULL_DATASET,
/**
* The update contains only information for a subset of all trips. If there is information stored
* from a previous realtime update it must be kept in order to have a complete picture of all
* trips.
*/
INCREMENTAL,
DIFFERENTIAL,
}
4 changes: 2 additions & 2 deletions src/test/java/org/opentripplanner/GtfsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.opentripplanner.updater.TimetableSnapshotSourceParameters;
import org.opentripplanner.updater.alert.AlertsUpdateHandler;
import org.opentripplanner.updater.trip.TimetableSnapshotSource;
import org.opentripplanner.updater.trip.UpdateSemantics;
import org.opentripplanner.updater.trip.UpdateIncrementality;

/** Common base class for many test classes which need to load a GTFS feed in preparation for tests. */
public abstract class GtfsTest {
Expand Down Expand Up @@ -229,7 +229,7 @@ protected void setUp() throws Exception {
timetableSnapshotSource.applyTripUpdates(
null,
REQUIRED_NO_DATA,
UpdateSemantics.INCREMENTAL,
UpdateIncrementality.DIFFERENTIAL,
updates,
feedId.getId()
);
Expand Down
Loading

0 comments on commit 95d5bc1

Please sign in to comment.