Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metro trips are skipped in result set handling #58

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -24,12 +24,14 @@ public abstract class PubtransTableHandler {
final TransitdataProperties.ProtobufSchema schema;
private Jedis jedis;
private final String timeZone;
private final boolean excludeMetroTrips;

public PubtransTableHandler(PulsarApplicationContext context, TransitdataProperties.ProtobufSchema handlerSchema) {
lastModifiedTimeStamp = (System.currentTimeMillis() - 5000);
jedis = context.getJedis();
producer = context.getSingleProducer();
timeZone = context.getConfig().getString("pubtrans.timezone");
excludeMetroTrips = context.getConfig().getBoolean("application.excludeMetroTrips");
schema = handlerSchema;
}

Expand Down Expand Up @@ -73,10 +75,10 @@ public Collection<TypedMessageBuilder<byte[]>> handleResultSet(ResultSet resultS
long tempTimeStamp = getLastModifiedTimeStamp();

int count = 0;
int metroTripCount = 0;
Set<String> metroRouteIds = new HashSet<>();

while (resultSet.next()) {
count++;

PubtransTableProtos.Common common = parseCommon(resultSet);
final long eventTimestampUtcMs = common.getLastModifiedUtcDateTimeMs();

Expand All @@ -92,9 +94,17 @@ public Collection<TypedMessageBuilder<byte[]>> handleResultSet(ResultSet resultS
if (maybeTripInfo.isEmpty()) {
log.warn("Could not find valid DOITripInfo from Redis for dvjId {}, timetabledJppId {}, targetedJppId {}. Ignoring this update ", dvjId, scheduledJppId, targetedJppId);
} else {
final byte[] data = createPayload(resultSet, common, maybeTripInfo.get());
TypedMessageBuilder<byte[]> msgBuilder = createMessage(key, eventTimestampUtcMs, dvjId, data, getSchema());
messageBuilderQueue.add(msgBuilder);
PubtransTableProtos.DOITripInfo tripInfo = maybeTripInfo.get();

if (excludeMetroTrips && tripInfo.getRouteId().startsWith("31M")) {
metroTripCount++;
metroRouteIds.add(tripInfo.getRouteId());
} else {
count++;
final byte[] data = createPayload(resultSet, common, tripInfo);
TypedMessageBuilder<byte[]> msgBuilder = createMessage(key, eventTimestampUtcMs, dvjId, data, getSchema());
messageBuilderQueue.add(msgBuilder);
}
}

//Update latest ts for next round
Expand All @@ -103,8 +113,11 @@ public Collection<TypedMessageBuilder<byte[]>> handleResultSet(ResultSet resultS
}
}

log.info("{} rows processed from result set", count);

log.info("{} rows processed from result set.", count);
if (metroTripCount > 0) {
log.info("Skipped {} rows with metro trips (route ids: {})", metroTripCount, metroRouteIds);
}

setLastModifiedTimeStamp(tempTimeStamp);

return messageBuilderQueue;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/arrival.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ application {
enableCacheTimestampCheck=${?ENABLE_CACHE_TIMESTAMP_CHECK}
cacheMaxAgeInMinutes=180
cacheMaxAgeInMinutes=${?CACHE_MAX_AGE_IN_MINS}
excludeMetroTrips=true
excludeMetroTrips=${?EXCLUDE_METRO_TRIPS}
}
2 changes: 2 additions & 0 deletions src/main/resources/departure.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ application {
enableCacheTimestampCheck=${?ENABLE_CACHE_TIMESTAMP_CHECK}
cacheMaxAgeInMinutes=180
cacheMaxAgeInMinutes=${?CACHE_MAX_AGE_IN_MINS}
excludeMetroTrips=true
excludeMetroTrips=${?EXCLUDE_METRO_TRIPS}
}
Loading