Commit 8cf9a6b0 authored by Michael Zilske's avatar Michael Zilske

Works. Inserts trip at the validity day of feed timestamp so far.

parent 6667b7b0
......@@ -20,6 +20,7 @@ package com.graphhopper.reader.gtfs;
import com.carrotsearch.hppc.IntHashSet;
import com.carrotsearch.hppc.IntIntHashMap;
import com.conveyal.gtfs.GTFSFeed;
import com.conveyal.gtfs.model.StopTime;
import com.conveyal.gtfs.model.Trip;
import com.google.transit.realtime.GtfsRealtime;
......@@ -60,6 +61,8 @@ public class RealtimeFeed {
}
public static RealtimeFeed fromProtobuf(Graph graph, GtfsStorage staticGtfs, PtFlagEncoder encoder, GtfsRealtime.FeedMessage feedMessage) {
String feedKey = "gtfs_0"; //FIXME
GTFSFeed feed = staticGtfs.getGtfsFeeds().get(feedKey);
final IntHashSet blockedEdges = new IntHashSet();
feedMessage.getEntityList().stream()
.filter(GtfsRealtime.FeedEntity::hasTripUpdate)
......@@ -78,7 +81,7 @@ public class RealtimeFeed {
final List<VirtualEdgeIteratorState> additionalEdges = new ArrayList<>();
final Graph overlayGraph = new Graph() {
int nNodes = 0;
int firstEdge = 999999;
int firstEdge = 999999; //FIXME
final NodeAccess nodeAccess = new NodeAccess() {
IntIntHashMap additionalNodeFields = new IntIntHashMap();
......@@ -183,11 +186,7 @@ public class RealtimeFeed {
newEdge.setReverseEdge(reverseNewEdge);
reverseNewEdge.setReverseEdge(newEdge);
additionalEdges.add(newEdge);
// additionalEdges.add(reverseNewEdge);
if (a== 2589 && b == 2579) {
System.out.println("Wust");
}
// additionalEdges.add(reverseNewEdge); //FIXME
return newEdge;
}
......@@ -221,7 +220,10 @@ public class RealtimeFeed {
return staticGtfs;
}
};
final GtfsReader gtfsReader = new GtfsReader("gtfs_0", overlayGraph, encoder, null);
final GtfsReader gtfsReader = new GtfsReader(feedKey, overlayGraph, encoder, null);
Instant timestamp = Instant.ofEpochSecond(feedMessage.getHeader().getTimestamp());
LocalDate dateToChange = timestamp.atZone(ZoneId.of(feed.agency.values().iterator().next().agency_timezone)).toLocalDate(); //FIXME
feedMessage.getEntityList().stream()
.filter(GtfsRealtime.FeedEntity::hasTripUpdate)
.map(GtfsRealtime.FeedEntity::getTripUpdate)
......@@ -239,14 +241,13 @@ public class RealtimeFeed {
final ZonedDateTime arrival_time = Instant.ofEpochSecond(stopTimeUpdate.getArrival().getTime()).atZone(ZoneId.of("America/Los_Angeles"));
stopTime.arrival_time = (int) Duration.between(arrival_time.truncatedTo(ChronoUnit.DAYS), arrival_time).getSeconds();
final ZonedDateTime departure_time = Instant.ofEpochSecond(stopTimeUpdate.getArrival().getTime()).atZone(ZoneId.of("America/Los_Angeles"));
stopTime.departure_time = (int) Duration.between(departure_time.truncatedTo(ChronoUnit.DAYS), departure_time).getSeconds();
return stopTime;
})
.collect(Collectors.toList());
BitSet validOnDay = new BitSet();
LocalDate startDate = staticGtfs.getGtfsFeeds().get("gtfs_0").calculateStats().getStartDate();
validOnDay.set((int) DAYS.between(startDate, LocalDate.of(2007,1,1)));
LocalDate startDate = feed.calculateStats().getStartDate();
validOnDay.set((int) DAYS.between(startDate, dateToChange));
return new GtfsReader.TripWithStopTimes(trip, stopTimes, validOnDay);
})
.forEach(trip -> gtfsReader.addTrips(ZoneId.systemDefault(), Collections.singletonList(trip), 0));
......
......@@ -34,8 +34,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.*;
import java.util.Arrays;
import java.util.Collections;
......@@ -86,7 +85,7 @@ public class RealtimeIT {
// But the 6:00 departure of my line is going to skip my departure stop :-(
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("wurst"));
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("1"));
feedMessageBuilder.addEntityBuilder()
.setId("pups")
.getTripUpdateBuilder()
......@@ -117,7 +116,7 @@ public class RealtimeIT {
// But the 6:00 departure of my line is going to skip my arrival stop :-(
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("wurst"));
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("1"));
feedMessageBuilder.addEntityBuilder()
.setId("pups")
.getTripUpdateBuilder()
......@@ -148,7 +147,7 @@ public class RealtimeIT {
// But the 6:00 departure of my line is going to skip my transfer stop :-(
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("wurst"));
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("1"));
feedMessageBuilder.addEntityBuilder()
.setId("pups")
.getTripUpdateBuilder()
......@@ -179,7 +178,9 @@ public class RealtimeIT {
// But the 6:00 departure of my line is going to skip my transfer stop :-(
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("wurst"));
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder()
.setGtfsRealtimeVersion("1")
.setTimestamp(ZonedDateTime.of(LocalDate.of(2007,1,1), LocalTime.of(0,0), zoneId).toEpochSecond()));
feedMessageBuilder.addEntityBuilder()
......@@ -229,7 +230,7 @@ public class RealtimeIT {
// My line does not stop at Bullfrog today. If this was a real transfer, I would not be
// able to change lines there. But it is not a real transfer, so I can go on as planned.
final GtfsRealtime.FeedMessage.Builder feedMessageBuilder = GtfsRealtime.FeedMessage.newBuilder();
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("wurst"));
feedMessageBuilder.setHeader(GtfsRealtime.FeedHeader.newBuilder().setGtfsRealtimeVersion("1"));
feedMessageBuilder.addEntityBuilder()
.setId("pups")
.getTripUpdateBuilder()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment