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());
}
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);
}
}
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;
}
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;
}
}
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());
}
Aggregations