Search in sources :

Example 1 with StopCondition

use of org.opentripplanner.routing.alertpatch.StopCondition in project OpenTripPlanner by opentripplanner.

the class EstimatedCallType method filterSituationsByDateAndStopConditions.

private static void filterSituationsByDateAndStopConditions(Collection<TransitAlert> alertPatches, Date fromTime, Date toTime, List<StopCondition> stopConditions) {
    if (alertPatches != null) {
        // First and last period
        alertPatches.removeIf(alert -> (alert.getEffectiveStartDate() != null && alert.getEffectiveStartDate().after(toTime)) || (alert.getEffectiveEndDate() != null && alert.getEffectiveEndDate().before(fromTime)));
        // Handle repeating validityPeriods
        alertPatches.removeIf(alertPatch -> !alertPatch.displayDuring(fromTime.getTime() / 1000, toTime.getTime() / 1000));
        alertPatches.removeIf(alert -> {
            boolean removeByStopCondition = false;
            if (!alert.getStopConditions().isEmpty()) {
                removeByStopCondition = true;
                for (StopCondition stopCondition : stopConditions) {
                    if (alert.getStopConditions().contains(stopCondition)) {
                        removeByStopCondition = false;
                    }
                }
            }
            return removeByStopCondition;
        });
    }
}
Also used : StopCondition(org.opentripplanner.routing.alertpatch.StopCondition)

Example 2 with StopCondition

use of org.opentripplanner.routing.alertpatch.StopCondition in project OpenTripPlanner by opentripplanner.

the class AlertToLegMapper method addTransitAlertPatchesToLeg.

public static void addTransitAlertPatchesToLeg(Graph graph, Leg leg, boolean isFirstLeg) {
    // Alert patches are only relevant for transit legs
    if (!leg.isTransitLeg()) {
        return;
    }
    Set<StopCondition> departingStopConditions = isFirstLeg ? StopCondition.DEPARTURE : StopCondition.FIRST_DEPARTURE;
    Date legStartTime = leg.getStartTime().getTime();
    Date legEndTime = leg.getEndTime().getTime();
    StopLocation fromStop = leg.getFrom() == null ? null : leg.getFrom().stop;
    StopLocation toStop = leg.getTo() == null ? null : leg.getTo().stop;
    FeedScopedId routeId = leg.getRoute().getId();
    FeedScopedId tripId = leg.getTrip().getId();
    if (fromStop instanceof Stop) {
        Collection<TransitAlert> alerts = getAlertsForStopAndRoute(graph, (Stop) fromStop, routeId);
        alerts.addAll(getAlertsForStopAndTrip(graph, (Stop) fromStop, tripId, leg.getServiceDate()));
        alerts.addAll(getAlertsForStop(graph, (Stop) fromStop));
        addTransitAlertPatchesToLeg(leg, departingStopConditions, alerts, legStartTime, legEndTime);
    }
    if (toStop instanceof Stop) {
        Collection<TransitAlert> alerts = getAlertsForStopAndRoute(graph, (Stop) toStop, routeId);
        alerts.addAll(getAlertsForStopAndTrip(graph, (Stop) toStop, tripId, leg.getServiceDate()));
        alerts.addAll(getAlertsForStop(graph, (Stop) toStop));
        addTransitAlertPatchesToLeg(leg, StopCondition.ARRIVING, alerts, legStartTime, legEndTime);
    }
    if (leg.getIntermediateStops() != null) {
        for (StopArrival visit : leg.getIntermediateStops()) {
            if (visit.place.stop instanceof Stop) {
                Stop stop = (Stop) visit.place.stop;
                Collection<TransitAlert> alerts = getAlertsForStopAndRoute(graph, stop, routeId);
                alerts.addAll(getAlertsForStopAndTrip(graph, stop, tripId, leg.getServiceDate()));
                alerts.addAll(getAlertsForStop(graph, stop));
                Date stopArrival = visit.arrival.getTime();
                Date stopDepature = visit.departure.getTime();
                addTransitAlertPatchesToLeg(leg, StopCondition.PASSING, alerts, stopArrival, stopDepature);
            }
        }
    }
    Collection<TransitAlert> patches;
    // trips - alerts tagged on ServiceDate
    patches = alertPatchService(graph).getTripAlerts(leg.getTrip().getId(), leg.getServiceDate());
    addTransitAlertPatchesToLeg(leg, patches, legStartTime, legEndTime);
    // trips - alerts tagged on any date
    patches = alertPatchService(graph).getTripAlerts(leg.getTrip().getId(), null);
    addTransitAlertPatchesToLeg(leg, patches, legStartTime, legEndTime);
    // route
    patches = alertPatchService(graph).getRouteAlerts(leg.getRoute().getId());
    addTransitAlertPatchesToLeg(leg, patches, legStartTime, legEndTime);
    // agency
    patches = alertPatchService(graph).getAgencyAlerts(leg.getAgency().getId());
    addTransitAlertPatchesToLeg(leg, patches, legStartTime, legEndTime);
    // Filter alerts when there are multiple timePeriods for each alert
    leg.getTransitAlerts().removeIf(alertPatch -> !alertPatch.displayDuring(leg.getStartTime().getTimeInMillis() / 1000, leg.getEndTime().getTimeInMillis() / 1000));
}
Also used : TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) Stop(org.opentripplanner.model.Stop) StopArrival(org.opentripplanner.model.plan.StopArrival) StopCondition(org.opentripplanner.routing.alertpatch.StopCondition) FeedScopedId(org.opentripplanner.model.FeedScopedId) StopLocation(org.opentripplanner.model.StopLocation) Date(java.util.Date) ServiceDate(org.opentripplanner.model.calendar.ServiceDate)

Example 3 with StopCondition

use of org.opentripplanner.routing.alertpatch.StopCondition in project OpenTripPlanner by opentripplanner.

the class AlertToLegMapper method addAlertPatchesToLeg.

public static void addAlertPatchesToLeg(Graph graph, Leg leg, boolean isFirstLeg, Locale requestedLocale) {
    Set<StopCondition> departingStopConditions = isFirstLeg ? StopCondition.DEPARTURE : StopCondition.FIRST_DEPARTURE;
    Date legStartTime = leg.startTime.getTime();
    Date legEndTime = leg.endTime.getTime();
    FeedScopedId fromStopId = leg.from == null ? null : leg.from.stopId;
    FeedScopedId toStopId = leg.to == null ? null : leg.to.stopId;
    if (leg.isTransitLeg()) {
        FeedScopedId routeId = leg.getRoute().getId();
        if (fromStopId != null) {
            Collection<TransitAlert> alerts = getAlertsForStopAndRoute(graph, fromStopId, routeId);
            addAlertPatchesToLeg(leg, departingStopConditions, alerts, requestedLocale, legStartTime, legEndTime);
        }
        if (toStopId != null) {
            Collection<TransitAlert> alerts = getAlertsForStopAndRoute(graph, toStopId, routeId);
            addAlertPatchesToLeg(leg, StopCondition.ARRIVING, alerts, requestedLocale, legStartTime, legEndTime);
        }
        FeedScopedId tripId = leg.getTrip().getId();
        if (fromStopId != null) {
            Collection<TransitAlert> alerts = getAlertsForStopAndTrip(graph, fromStopId, tripId);
            addAlertPatchesToLeg(leg, departingStopConditions, alerts, requestedLocale, legStartTime, legEndTime);
        }
        if (toStopId != null) {
            Collection<TransitAlert> alerts = getAlertsForStopAndTrip(graph, toStopId, tripId);
            addAlertPatchesToLeg(leg, StopCondition.ARRIVING, alerts, requestedLocale, legStartTime, legEndTime);
        }
        if (leg.intermediateStops != null) {
            for (StopArrival visit : leg.intermediateStops) {
                Place place = visit.place;
                if (place.stopId != null) {
                    Collection<TransitAlert> alerts = getAlertsForStopAndTrip(graph, place.stopId, tripId);
                    Date stopArrival = visit.arrival.getTime();
                    Date stopDepature = visit.departure.getTime();
                    addAlertPatchesToLeg(leg, StopCondition.PASSING, alerts, requestedLocale, stopArrival, stopDepature);
                }
            }
        }
    }
    if (leg.intermediateStops != null) {
        for (StopArrival visit : leg.intermediateStops) {
            Place place = visit.place;
            if (place.stopId != null) {
                Collection<TransitAlert> alerts = getAlertsForStop(graph, place.stopId);
                Date stopArrival = visit.arrival.getTime();
                Date stopDepature = visit.departure.getTime();
                addAlertPatchesToLeg(leg, StopCondition.PASSING, alerts, requestedLocale, stopArrival, stopDepature);
            }
        }
    }
    if (leg.from != null && fromStopId != null) {
        Collection<TransitAlert> alerts = getAlertsForStop(graph, fromStopId);
        addAlertPatchesToLeg(leg, departingStopConditions, alerts, requestedLocale, legStartTime, legEndTime);
    }
    if (leg.to != null && toStopId != null) {
        Collection<TransitAlert> alerts = getAlertsForStop(graph, toStopId);
        addAlertPatchesToLeg(leg, StopCondition.ARRIVING, alerts, requestedLocale, legStartTime, legEndTime);
    }
    if (leg.isTransitLeg()) {
        Collection<TransitAlert> patches;
        // trips
        patches = alertPatchService(graph).getTripAlerts(leg.getTrip().getId());
        addAlertPatchesToLeg(leg, patches, requestedLocale, legStartTime, legEndTime);
        // route
        patches = alertPatchService(graph).getRouteAlerts(leg.getRoute().getId());
        addAlertPatchesToLeg(leg, patches, requestedLocale, legStartTime, legEndTime);
        // agency
        patches = alertPatchService(graph).getAgencyAlerts(leg.getAgency().getId());
        addAlertPatchesToLeg(leg, patches, requestedLocale, legStartTime, legEndTime);
    }
    // Filter alerts when there are multiple timePeriods for each alert
    leg.transitAlerts.removeIf(alertPatch -> !alertPatch.displayDuring(leg.startTime.getTimeInMillis() / 1000, leg.endTime.getTimeInMillis() / 1000));
}
Also used : TransitAlert(org.opentripplanner.routing.alertpatch.TransitAlert) StopArrival(org.opentripplanner.model.plan.StopArrival) StopCondition(org.opentripplanner.routing.alertpatch.StopCondition) FeedScopedId(org.opentripplanner.model.FeedScopedId) Date(java.util.Date) Place(org.opentripplanner.model.plan.Place)

Example 4 with StopCondition

use of org.opentripplanner.routing.alertpatch.StopCondition in project OpenTripPlanner by opentripplanner.

the class SiriAlertsUpdateHandler method updateStopConditions.

private void updateStopConditions(TransitAlert alertPatch, List<RoutePointTypeEnumeration> stopConditions) {
    Set<StopCondition> alertStopConditions = new HashSet<>();
    if (stopConditions != null) {
        for (RoutePointTypeEnumeration stopCondition : stopConditions) {
            switch(stopCondition) {
                case EXCEPTIONAL_STOP:
                    alertStopConditions.add(StopCondition.EXCEPTIONAL_STOP);
                    break;
                case DESTINATION:
                    alertStopConditions.add(StopCondition.DESTINATION);
                    break;
                case NOT_STOPPING:
                    alertStopConditions.add(StopCondition.NOT_STOPPING);
                    break;
                case REQUEST_STOP:
                    alertStopConditions.add(StopCondition.REQUEST_STOP);
                    break;
                case START_POINT:
                    alertStopConditions.add(StopCondition.START_POINT);
                    break;
            }
        }
    }
    if (alertStopConditions.isEmpty()) {
        // No StopConditions are set - set default
        alertStopConditions.add(StopCondition.START_POINT);
        alertStopConditions.add(StopCondition.DESTINATION);
    }
    alertPatch.getStopConditions().addAll(alertStopConditions);
}
Also used : RoutePointTypeEnumeration(uk.org.siri.siri20.RoutePointTypeEnumeration) StopCondition(org.opentripplanner.routing.alertpatch.StopCondition) HashSet(java.util.HashSet)

Aggregations

StopCondition (org.opentripplanner.routing.alertpatch.StopCondition)4 Date (java.util.Date)2 FeedScopedId (org.opentripplanner.model.FeedScopedId)2 StopArrival (org.opentripplanner.model.plan.StopArrival)2 TransitAlert (org.opentripplanner.routing.alertpatch.TransitAlert)2 HashSet (java.util.HashSet)1 Stop (org.opentripplanner.model.Stop)1 StopLocation (org.opentripplanner.model.StopLocation)1 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)1 Place (org.opentripplanner.model.plan.Place)1 RoutePointTypeEnumeration (uk.org.siri.siri20.RoutePointTypeEnumeration)1