Search in sources :

Example 6 with MonitoredCallStructure

use of uk.org.siri.siri.MonitoredCallStructure in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImpl method getPresentableTime.

private String getPresentableTime(MonitoredVehicleJourneyStructure journey, long updateTime, boolean isStopContext) {
    NaturalLanguageStringStructure progressStatus = journey.getProgressStatus();
    MonitoredCallStructure monitoredCall = journey.getMonitoredCall();
    if (!isStopContext) {
        return null;
    }
    int staleTimeout = _configurationService.getConfigurationValueAsInteger("display.staleTimeout", 120);
    long age = (SystemTime.currentTimeMillis() - updateTime) / 1000;
    if (age > staleTimeout) {
        return null;
    }
    if (monitoredCall.getExpectedArrivalTime() != null) {
        long predictedArrival = monitoredCall.getExpectedArrivalTime().getTime();
        SiriExtensionWrapper wrapper = (SiriExtensionWrapper) monitoredCall.getExtensions().getAny();
        SiriDistanceExtension distanceExtension = wrapper.getDistances();
        String distance = distanceExtension.getPresentableDistance();
        double minutes = Math.floor((predictedArrival - updateTime) / 60 / 1000);
        String timeString = Math.round(minutes) + " minute" + ((Math.abs(minutes) != 1) ? "s" : "");
        if (progressStatus != null && progressStatus.getValue().contains("prevTrip")) {
            return timeString;
        } else {
            return "<strong>" + timeString + "</strong>" + ", " + distance;
        }
    }
    return null;
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri.NaturalLanguageStringStructure) SiriExtensionWrapper(org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper) SiriDistanceExtension(org.onebusaway.transit_data_federation.siri.SiriDistanceExtension) MonitoredCallStructure(uk.org.siri.siri.MonitoredCallStructure)

Aggregations

MonitoredCallStructure (uk.org.siri.siri.MonitoredCallStructure)6 SiriDistanceExtension (org.onebusaway.transit_data_federation.siri.SiriDistanceExtension)4 SiriExtensionWrapper (org.onebusaway.transit_data_federation.siri.SiriExtensionWrapper)4 NaturalLanguageStringStructure (uk.org.siri.siri.NaturalLanguageStringStructure)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 StopOnRoute (org.onebusaway.enterprise.webapp.actions.m.model.StopOnRoute)2 NameBean (org.onebusaway.transit_data.model.NameBean)2 StopBean (org.onebusaway.transit_data.model.StopBean)2 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)2 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)2 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)2 ExtensionsStructure (uk.org.siri.siri.ExtensionsStructure)2 MonitoredStopVisitStructure (uk.org.siri.siri.MonitoredStopVisitStructure)2 DateFormat (java.text.DateFormat)1 DecimalFormat (java.text.DecimalFormat)1 Matchers.anyString (org.mockito.Matchers.anyString)1