Search in sources :

Example 1 with TimetabledPassingTime

use of org.rutebanken.netex.model.TimetabledPassingTime in project OpenTripPlanner by opentripplanner.

the class NoticeAssignmentMapper method map.

Multimap<TransitEntity<?>, Notice> map(NoticeAssignment noticeAssignment) {
    // TODO OTP2 - Idealy this should en up as one key,value pair.
    // The `StopPointInJourneyPattern` witch result in more than one key/valye pair,
    // can be replaced with a new compound key type.
    Multimap<TransitEntity<?>, Notice> noticiesByEntity = ArrayListMultimap.create();
    String noticedObjectId = noticeAssignment.getNoticedObjectRef().getRef();
    Notice otpNotice = getOrMapNotice(noticeAssignment);
    if (otpNotice == null) {
        LOG.warn("Notice in notice assignment is missing for assignment {}", noticeAssignment);
        return noticiesByEntity;
    }
    // Special case for StopPointInJourneyPattern. The OTP model do not have this element, so we
    // attach the notice to all StopTimes for the pattern at the given stop.
    Collection<TimetabledPassingTime> times = passingTimeByStopPointId.lookup(noticedObjectId);
    if (!times.isEmpty()) {
        for (TimetabledPassingTime time : times) {
            noticiesByEntity.put(lookupStopTimeKey(time.getId()), otpNotice);
        }
    } else if (stopTimesByNetexId.containsKey(noticedObjectId)) {
        noticiesByEntity.put(lookupStopTimeKey(noticedObjectId), otpNotice);
    } else {
        FeedScopedId otpId = idFactory.createId(noticedObjectId);
        if (routesById.containsKey(otpId)) {
            noticiesByEntity.put(routesById.get(otpId), otpNotice);
        } else if (tripsById.containsKey(otpId)) {
            noticiesByEntity.put(tripsById.get(otpId), otpNotice);
        } else {
            LOG.warn("Could not map noticeAssignment for element with id {}", noticedObjectId);
        }
    }
    return noticiesByEntity;
}
Also used : Notice(org.opentripplanner.model.Notice) TransitEntity(org.opentripplanner.model.TransitEntity) FeedScopedId(org.opentripplanner.model.FeedScopedId) TimetabledPassingTime(org.rutebanken.netex.model.TimetabledPassingTime)

Example 2 with TimetabledPassingTime

use of org.rutebanken.netex.model.TimetabledPassingTime in project OpenTripPlanner by opentripplanner.

the class NoticeAssignmentMapperTest method mapNoticeAssignmentOnStopPoint.

@Test
public void mapNoticeAssignmentOnStopPoint() {
    HierarchicalMultimap<String, TimetabledPassingTime> passingTimeByStopPointId = new HierarchicalMultimap<>();
    HierarchicalMapById<Notice> noticesById = new HierarchicalMapById<>();
    passingTimeByStopPointId.add(STOP_POINT_ID, new TimetabledPassingTime().withId(TIMETABLED_PASSING_TIME1));
    passingTimeByStopPointId.add(STOP_POINT_ID, new TimetabledPassingTime().withId(TIMETABLED_PASSING_TIME2));
    Trip trip = new Trip();
    trip.setId(new FeedScopedId("T", "1"));
    StopTime stopTime1 = createStopTime(1, trip);
    StopTime stopTime2 = createStopTime(2, trip);
    Map<String, StopTime> stopTimesById = new HashMap<>();
    stopTimesById.put(TIMETABLED_PASSING_TIME1, stopTime1);
    stopTimesById.put(TIMETABLED_PASSING_TIME2, stopTime2);
    noticesById.add(NOTICE);
    NoticeAssignment noticeAssignment = new NoticeAssignment().withNoticedObjectRef(new VersionOfObjectRefStructure().withRef(STOP_POINT_ID)).withNoticeRef(new NoticeRefStructure().withRef(NOTICE_ID));
    NoticeAssignmentMapper noticeAssignmentMapper = new NoticeAssignmentMapper(MappingSupport.ID_FACTORY, passingTimeByStopPointId, noticesById, new EntityById<>(), new EntityById<>(), stopTimesById);
    Multimap<TransitEntity<?>, org.opentripplanner.model.Notice> noticesByElement = noticeAssignmentMapper.map(noticeAssignment);
    org.opentripplanner.model.Notice notice2a = noticesByElement.get(stopTime1.getId()).stream().findFirst().orElseThrow(IllegalStateException::new);
    org.opentripplanner.model.Notice notice2b = noticesByElement.get(stopTime2.getId()).stream().findFirst().orElseThrow(IllegalStateException::new);
    assertEquals(NOTICE_ID, notice2a.getId().getId());
    assertEquals(NOTICE_ID, notice2b.getId().getId());
}
Also used : Trip(org.opentripplanner.model.Trip) NoticeRefStructure(org.rutebanken.netex.model.NoticeRefStructure) VersionOfObjectRefStructure(org.rutebanken.netex.model.VersionOfObjectRefStructure) HashMap(java.util.HashMap) TransitEntity(org.opentripplanner.model.TransitEntity) MultilingualString(org.rutebanken.netex.model.MultilingualString) HierarchicalMultimap(org.opentripplanner.netex.loader.util.HierarchicalMultimap) HierarchicalMapById(org.opentripplanner.netex.loader.util.HierarchicalMapById) TimetabledPassingTime(org.rutebanken.netex.model.TimetabledPassingTime) Notice(org.rutebanken.netex.model.Notice) FeedScopedId(org.opentripplanner.model.FeedScopedId) NoticeAssignment(org.rutebanken.netex.model.NoticeAssignment) StopTime(org.opentripplanner.model.StopTime) Test(org.junit.Test)

Example 3 with TimetabledPassingTime

use of org.rutebanken.netex.model.TimetabledPassingTime in project OpenTripPlanner by opentripplanner.

the class StopTimesMapper method mapToStopTimes.

/**
 * @return a map of stop-times indexed by the TimetabledPassingTime id.
 */
MappedStopTimes mapToStopTimes(JourneyPattern journeyPattern, Trip trip, List<TimetabledPassingTime> passingTimes) {
    MappedStopTimes result = new MappedStopTimes();
    for (int i = 0; i < passingTimes.size(); i++) {
        TimetabledPassingTime currentPassingTime = passingTimes.get(i);
        String pointInJourneyPattern = currentPassingTime.getPointInJourneyPatternRef().getValue().getRef();
        StopPointInJourneyPattern stopPoint = findStopPoint(pointInJourneyPattern, journeyPattern);
        Stop stop = lookupStop(stopPoint, quayIdByStopPointRef, stopsById);
        if (stop == null) {
            LOG.warn("Stop with id {} not found for StopPoint {} in JourneyPattern {}. " + "Trip {} will not be mapped.", stopPoint != null && stopPoint.getScheduledStopPointRef() != null ? stopPoint.getScheduledStopPointRef().getValue().getRef() : "null", stopPoint != null ? stopPoint.getId() : "null", journeyPattern.getId(), trip.getId());
            return null;
        }
        StopTime stopTime = mapToStopTime(trip, stopPoint, stop, currentPassingTime, i);
        result.add(currentPassingTime.getId(), stopTime);
    }
    return result;
}
Also used : Stop(org.opentripplanner.model.Stop) StopPointInJourneyPattern(org.rutebanken.netex.model.StopPointInJourneyPattern) TimetabledPassingTime(org.rutebanken.netex.model.TimetabledPassingTime) StopTime(org.opentripplanner.model.StopTime)

Example 4 with TimetabledPassingTime

use of org.rutebanken.netex.model.TimetabledPassingTime in project OpenTripPlanner by opentripplanner.

the class TimeTableFrameParser method parseServiceJourney.

private void parseServiceJourney(ServiceJourney sj) {
    DayTypeRefsToServiceIdAdapter serviceAdapter = DayTypeRefsToServiceIdAdapter.create(sj.getDayTypes());
    if (serviceAdapter == null) {
        LOG.warn("Skipping ServiceJourney with empty dayTypes. Service Journey id : {}", sj.getId());
        return;
    }
    dayTypeRefs.add(serviceAdapter);
    String journeyPatternId = sj.getJourneyPatternRef().getValue().getRef();
    JourneyPattern journeyPattern = journeyPatternById.lookup(journeyPatternId);
    if (journeyPattern != null) {
        int nStopPointsInJourneyPattern = journeyPattern.getPointsInSequence().getPointInJourneyPatternOrStopPointInJourneyPatternOrTimingPointInJourneyPattern().size();
        int nTimetablePassingTimes = sj.getPassingTimes().getTimetabledPassingTime().size();
        // - is know at this point.
        if (nStopPointsInJourneyPattern == nTimetablePassingTimes) {
            serviceJourneyByPatternId.put(journeyPatternId, sj);
            for (TimetabledPassingTime it : sj.getPassingTimes().getTimetabledPassingTime()) {
                passingTimeByStopPointId.put(it.getPointInJourneyPatternRef().getValue().getRef(), it);
            }
        } else {
            LOG.warn("Mismatch between ServiceJourney and JourneyPattern. " + "ServiceJourney will be skipped. - " + sj.getId());
        }
    } else {
        LOG.warn("JourneyPattern not found. " + journeyPatternId);
    }
}
Also used : JourneyPattern(org.rutebanken.netex.model.JourneyPattern) DayTypeRefsToServiceIdAdapter(org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter) TimetabledPassingTime(org.rutebanken.netex.model.TimetabledPassingTime)

Aggregations

TimetabledPassingTime (org.rutebanken.netex.model.TimetabledPassingTime)4 FeedScopedId (org.opentripplanner.model.FeedScopedId)2 StopTime (org.opentripplanner.model.StopTime)2 TransitEntity (org.opentripplanner.model.TransitEntity)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Notice (org.opentripplanner.model.Notice)1 Stop (org.opentripplanner.model.Stop)1 Trip (org.opentripplanner.model.Trip)1 HierarchicalMapById (org.opentripplanner.netex.loader.util.HierarchicalMapById)1 HierarchicalMultimap (org.opentripplanner.netex.loader.util.HierarchicalMultimap)1 DayTypeRefsToServiceIdAdapter (org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter)1 JourneyPattern (org.rutebanken.netex.model.JourneyPattern)1 MultilingualString (org.rutebanken.netex.model.MultilingualString)1 Notice (org.rutebanken.netex.model.Notice)1 NoticeAssignment (org.rutebanken.netex.model.NoticeAssignment)1 NoticeRefStructure (org.rutebanken.netex.model.NoticeRefStructure)1 StopPointInJourneyPattern (org.rutebanken.netex.model.StopPointInJourneyPattern)1 VersionOfObjectRefStructure (org.rutebanken.netex.model.VersionOfObjectRefStructure)1