use of org.opentripplanner.model.calendar.ServiceCalendar in project OpenTripPlanner by opentripplanner.
the class OtpTransitServiceBuilder method limitServiceDays.
/**
* Limit the transit service to a time period removing calendar dates and services
* outside the period. If a service is start before and/or ends after the period
* then the service is modified to match the period.
*/
public void limitServiceDays(ServiceDateInterval periodLimit) {
if (periodLimit.isUnbounded()) {
LOG.info("Limiting transit service is skipped, the period is unbounded.");
return;
}
LOG.warn("Limiting transit service days to time period: {}", periodLimit);
int orgSize = calendarDates.size();
calendarDates.removeIf(c -> !periodLimit.include(c.getDate()));
logRemove("ServiceCalendarDate", orgSize, calendarDates.size(), "Outside time period.");
List<ServiceCalendar> keepCal = new ArrayList<>();
for (ServiceCalendar calendar : calendars) {
if (calendar.getPeriod().overlap(periodLimit)) {
calendar.setPeriod(calendar.getPeriod().intersection(periodLimit));
keepCal.add(calendar);
}
}
orgSize = calendars.size();
if (orgSize != keepCal.size()) {
calendars.clear();
calendars.addAll(keepCal);
logRemove("ServiceCalendar", orgSize, calendars.size(), "Outside time period.");
}
removeEntitiesWithInvalidReferences();
LOG.info("Limiting transit service days to time period complete.");
}
use of org.opentripplanner.model.calendar.ServiceCalendar 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.ServiceCalendar 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());
}
use of org.opentripplanner.model.calendar.ServiceCalendar in project OpenTripPlanner by opentripplanner.
the class OtpTransitServiceBuilderLimitPeriodTest method createServiceCalendar.
private static ServiceCalendar createServiceCalendar(FeedScopedId serviceId, ServiceDate start, ServiceDate end) {
ServiceCalendar calendar = new ServiceCalendar();
calendar.setPeriod(new ServiceDateInterval(start, end));
calendar.setAllDays(1);
calendar.setServiceId(serviceId);
return calendar;
}
use of org.opentripplanner.model.calendar.ServiceCalendar in project OpenTripPlanner by opentripplanner.
the class ServiceCalendarMapper method doMap.
private ServiceCalendar doMap(org.onebusaway.gtfs.model.ServiceCalendar rhs) {
ServiceCalendar lhs = new ServiceCalendar();
lhs.setServiceId(mapAgencyAndId(rhs.getServiceId()));
lhs.setMonday(rhs.getMonday());
lhs.setTuesday(rhs.getTuesday());
lhs.setWednesday(rhs.getWednesday());
lhs.setThursday(rhs.getThursday());
lhs.setFriday(rhs.getFriday());
lhs.setSaturday(rhs.getSaturday());
lhs.setSunday(rhs.getSunday());
lhs.setPeriod(ServiceDateMapper.mapServiceDateInterval(rhs.getStartDate(), rhs.getEndDate()));
return lhs;
}
Aggregations