Search in sources :

Example 6 with StopTimeEvent

use of com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent in project onebusaway-application-modules by camsys.

the class GtfsRealtimeTripLibrary method getTimeForStopTimeUpdate.

private int getTimeForStopTimeUpdate(StopTimeUpdate stopTimeUpdate, long serviceDate) {
    long t = currentTime();
    if (stopTimeUpdate.hasArrival()) {
        StopTimeEvent arrival = stopTimeUpdate.getArrival();
        // note that we prefer time over delay if both are present
        if (arrival.hasTime()) {
            return (int) (arrival.getTime() - serviceDate / 1000);
        }
        if (arrival.hasDelay()) {
            return (int) ((t - serviceDate) / 1000 - arrival.getDelay());
        }
    }
    if (stopTimeUpdate.hasDeparture()) {
        StopTimeEvent departure = stopTimeUpdate.getDeparture();
        // again we prefer time over delay if both are present
        if (departure.hasTime())
            return (int) (departure.getTime() - serviceDate / 1000);
        if (departure.hasDelay()) {
            return (int) ((t - serviceDate) / 1000 - departure.getDelay());
        }
    }
    // instead of illegal state exception we return -1 to not corrupt the read
    _log.debug("expected at least an arrival or departure time or delay for update: " + stopTimeUpdate);
    return -1;
}
Also used : StopTimeEvent(com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent)

Aggregations

StopTimeEvent (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeEvent)6 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)5 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)3 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)3 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)2 Test (org.junit.Test)2 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)2 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)2 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)2 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 Date (java.util.Date)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 ServiceAlertLocalizedString (org.onebusaway.transit_data_federation.impl.service_alerts.ServiceAlertLocalizedString)1 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)1 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)1