Search in sources :

Example 1 with ServiceCalendarDate

use of org.opentripplanner.model.calendar.ServiceCalendarDate in project OpenTripPlanner by opentripplanner.

the class CalendarMapper method mapToCalendarDates.

Collection<ServiceCalendarDate> mapToCalendarDates(DayTypeRefsToServiceIdAdapter dayTypeRefs) {
    String serviceId = dayTypeRefs.getServiceId();
    // The mapper store intermediate results and need to be initialized every time
    DayTypeAssignmentMapper dayTypeAssignmentMapper = new DayTypeAssignmentMapper(dayTypeById, operatingPeriodById);
    for (String dayTypeId : dayTypeRefs.getDayTypeRefs()) {
        dayTypeAssignmentMapper.mapAll(dayTypeId, dayTypeAssignments(dayTypeId));
    }
    Set<LocalDateTime> dates = dayTypeAssignmentMapper.mergeDates();
    if (dates.isEmpty()) {
        addDataImportIssue(new ServiceCodeDoesNotContainServiceDates(serviceId));
        // Add one date exception when list is empty to ensure serviceId is not lost
        LocalDateTime today = LocalDate.now().atStartOfDay();
        return Collections.singleton(newServiceCalendarDate(today, serviceId, EXCEPTION_TYPE_REMOVE));
    }
    return dates.stream().map(it -> newServiceCalendarDate(it, serviceId, EXCEPTION_TYPE_ADD)).collect(Collectors.toList());
}
Also used : LocalDateTime(java.time.LocalDateTime) EXCEPTION_TYPE_REMOVE(org.opentripplanner.model.calendar.ServiceCalendarDate.EXCEPTION_TYPE_REMOVE) Collection(java.util.Collection) LocalDateTime(java.time.LocalDateTime) Set(java.util.Set) ReadOnlyHierarchicalMapById(org.opentripplanner.netex.loader.util.ReadOnlyHierarchicalMapById) Collectors(java.util.stream.Collectors) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) DayTypeAssignment(org.rutebanken.netex.model.DayTypeAssignment) DataImportIssue(org.opentripplanner.graph_builder.DataImportIssue) ReadOnlyHierarchicalMap(org.opentripplanner.netex.loader.util.ReadOnlyHierarchicalMap) DayTypeRefsToServiceIdAdapter(org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter) OperatingPeriod(org.rutebanken.netex.model.OperatingPeriod) ServiceCodeDoesNotContainServiceDates(org.opentripplanner.graph_builder.issues.ServiceCodeDoesNotContainServiceDates) LocalDate(java.time.LocalDate) EXCEPTION_TYPE_ADD(org.opentripplanner.model.calendar.ServiceCalendarDate.EXCEPTION_TYPE_ADD) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) Collections(java.util.Collections) DayType(org.rutebanken.netex.model.DayType) ServiceCodeDoesNotContainServiceDates(org.opentripplanner.graph_builder.issues.ServiceCodeDoesNotContainServiceDates)

Example 2 with ServiceCalendarDate

use of org.opentripplanner.model.calendar.ServiceCalendarDate in project OpenTripPlanner by opentripplanner.

the class NetexMapper method mapCalendarDayTypes.

private void mapCalendarDayTypes(NetexImportDataIndexReadOnlyView netexIndex) {
    CalendarMapper calMapper = new CalendarMapper(idFactory, netexIndex.getDayTypeAssignmentByDayTypeId(), netexIndex.getOperatingPeriodById(), netexIndex.getDayTypeById(), issueStore);
    for (DayTypeRefsToServiceIdAdapter dayTypeRefs : netexIndex.getDayTypeRefs()) {
        Collection<ServiceCalendarDate> dates = calMapper.mapToCalendarDates(dayTypeRefs);
        transitBuilder.getCalendarDates().addAll(dates);
    }
}
Also used : ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) DayTypeRefsToServiceIdAdapter(org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter)

Example 3 with ServiceCalendarDate

use of org.opentripplanner.model.calendar.ServiceCalendarDate in project OpenTripPlanner by opentripplanner.

the class CalendarServiceDataFactoryImpl method getServiceDatesForServiceId.

private Set<ServiceDate> getServiceDatesForServiceId(FeedScopedId serviceId, TimeZone serviceIdTimeZone) {
    Set<ServiceDate> activeDates = new HashSet<>();
    ServiceCalendar c = findCalendarForServiceId(serviceId);
    if (c != null) {
        addDatesFromCalendar(c, serviceIdTimeZone, activeDates);
    }
    List<ServiceCalendarDate> dates = calendarDatesByServiceId.get(serviceId);
    if (dates != null) {
        for (ServiceCalendarDate cd : dates) {
            addAndRemoveDatesFromCalendarDate(cd, activeDates);
        }
    }
    return activeDates;
}
Also used : ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) HashSet(java.util.HashSet) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar)

Example 4 with ServiceCalendarDate

use of org.opentripplanner.model.calendar.ServiceCalendarDate in project OpenTripPlanner by opentripplanner.

the class CalendarServiceDataFactoryImpl method addAndRemoveDatesFromCalendarDate.

private void addAndRemoveDatesFromCalendarDate(ServiceCalendarDate calendarDate, Set<ServiceDate> activeDates) {
    ServiceDate serviceDate = calendarDate.getDate();
    Date targetDate = calendarDate.getDate().getAsDate();
    Calendar c = Calendar.getInstance();
    c.setTime(targetDate);
    switch(calendarDate.getExceptionType()) {
        case ServiceCalendarDate.EXCEPTION_TYPE_ADD:
            addServiceDate(activeDates, serviceDate);
            break;
        case ServiceCalendarDate.EXCEPTION_TYPE_REMOVE:
            activeDates.remove(serviceDate);
            break;
        default:
            LOG.warn("unknown CalendarDate exception type: " + calendarDate.getExceptionType());
            break;
    }
}
Also used : ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar) Calendar(java.util.Calendar) Date(java.util.Date) ServiceDate(org.opentripplanner.model.calendar.ServiceDate) ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate)

Example 5 with ServiceCalendarDate

use of org.opentripplanner.model.calendar.ServiceCalendarDate in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceBuilderLimitPeriodTest method testLimitPeriod.

@Test
public void testLimitPeriod() {
    // Assert the test is set up as expected
    assertEquals(2, subject.getCalendars().size());
    assertEquals(2, subject.getCalendarDates().size());
    assertEquals(4, subject.getTripsById().size());
    assertEquals(3, subject.getTripPatterns().get(STOP_PATTERN).size());
    assertEquals(2, patternInT1.getTrips().size());
    assertEquals(2, patternInT1.scheduledTimetable.tripTimes.size());
    assertEquals(1, patternInT2.getTrips().size());
    assertEquals(1, patternInT2.scheduledTimetable.tripTimes.size());
    // Limit service to last half of month
    subject.limitServiceDays(new ServiceDateInterval(D2, D3));
    // Verify calendar
    List<ServiceCalendar> calendars = subject.getCalendars();
    assertEquals(calendars.toString(), 1, calendars.size());
    assertEquals(calendars.toString(), SERVICE_C_IN, calendars.get(0).getServiceId());
    // Verify calendar dates
    List<ServiceCalendarDate> dates = subject.getCalendarDates();
    assertEquals(dates.toString(), 1, dates.size());
    assertEquals(dates.toString(), SERVICE_D_IN, dates.get(0).getServiceId());
    // Verify trips
    EntityById<FeedScopedId, Trip> trips = subject.getTripsById();
    assertEquals(trips.toString(), 2, trips.size());
    assertTrue(trips.toString(), trips.containsKey(tripCSIn.getId()));
    assertTrue(trips.toString(), trips.containsKey(tripCSDIn.getId()));
    // Verify patterns
    Collection<TripPattern> patterns = subject.getTripPatterns().get(STOP_PATTERN);
    assertEquals(2, patterns.size());
    assertTrue(patterns.toString(), patterns.contains(patternInT1));
    assertTrue(patterns.toString(), patterns.contains(patternInT2));
    // Verify trips in pattern (one trip is removed from patternInT1)
    assertEquals(1, patternInT1.getTrips().size());
    assertEquals(tripCSIn, patternInT1.getTrips().get(0));
    // Verify trips in pattern is unchanged (one trip)
    assertEquals(1, patternInT2.getTrips().size());
    // Verify scheduledTimetable trips (one trip is removed from patternInT1)
    assertEquals(1, patternInT1.scheduledTimetable.tripTimes.size());
    assertEquals(tripCSIn, patternInT1.scheduledTimetable.tripTimes.get(0).trip);
    // Verify scheduledTimetable trips in pattern is unchanged (one trip)
    assertEquals(1, patternInT2.scheduledTimetable.tripTimes.size());
}
Also used : ServiceCalendarDate(org.opentripplanner.model.calendar.ServiceCalendarDate) Trip(org.opentripplanner.model.Trip) ServiceDateInterval(org.opentripplanner.model.calendar.ServiceDateInterval) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripPattern(org.opentripplanner.model.TripPattern) ServiceCalendar(org.opentripplanner.model.calendar.ServiceCalendar) Test(org.junit.Test)

Aggregations

ServiceCalendarDate (org.opentripplanner.model.calendar.ServiceCalendarDate)6 ServiceCalendar (org.opentripplanner.model.calendar.ServiceCalendar)3 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)3 TripPattern (org.opentripplanner.model.TripPattern)2 DayTypeRefsToServiceIdAdapter (org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 Test (org.junit.Test)1 DataImportIssue (org.opentripplanner.graph_builder.DataImportIssue)1 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)1 ServiceCodeDoesNotContainServiceDates (org.opentripplanner.graph_builder.issues.ServiceCodeDoesNotContainServiceDates)1 FeedScopedId (org.opentripplanner.model.FeedScopedId)1