use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class VerifyBusService method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
String feed = CloudContextService.getLikelyFeedName(dao);
CalendarService refCalendarService = CalendarServiceDataFactoryImpl.createService(reference);
AgencyAndId refAgencyAndId = reference.getAllTrips().iterator().next().getId();
int curSerRoute = 0;
int alarmingRoutes = 0;
Date today = removeTime(new Date());
// list of all routes in ATIS
Set<String> ATISrouteIds = new HashSet<>();
// check for route specific current service
for (Route route : dao.getAllRoutes()) {
ATISrouteIds.add(route.getId().getId());
_log.info("Adding route: {}", route.getId().getId());
curSerRoute = 0;
triploop: for (Trip trip1 : dao.getTripsForRoute(route)) {
for (ServiceCalendarDate calDate : dao.getCalendarDatesForServiceId(trip1.getServiceId())) {
Date date = constructDate(calDate.getDate());
if (calDate.getExceptionType() == 1 && date.equals(today)) {
_log.info("ATIS has current service for route: {}", route.getId().getId());
curSerRoute++;
break triploop;
}
}
}
if (curSerRoute == 0) {
_log.error("No current service for {}", route.getId().getId());
// if there is no current service, check that it should have service
// there are certain routes that don't run on the weekend or won't have service in reference
ServiceDate sToday = createServiceDate(today);
Route refRoute = reference.getRouteForId(new AgencyAndId(refAgencyAndId.getAgencyId(), route.getId().getId()));
reftriploop: for (Trip refTrip : reference.getTripsForRoute(refRoute)) {
Set<ServiceDate> activeDates = refCalendarService.getServiceDatesForServiceId(refTrip.getServiceId());
if (activeDates.contains(sToday)) {
_log.info("Reference has service for this bus route today but ATIS does not: {}", route.getId());
// This would be the site to add to a bulk metric, missingBus:
alarmingRoutes++;
}
}
}
}
es.publishMetric(CloudContextService.getNamespace(), "RoutesMissingTripsFromAtisButInRefToday", "feed", feed, alarmingRoutes);
es.publishMetric(CloudContextService.getNamespace(), "RoutesContainingTripsToday", "feed", feed, curSerRoute);
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class LocalVsExpressUpdateStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
_log.info("running");
for (Route route : dao.getAllRoutes()) {
List<Trip> trips = dao.getTripsForRoute(route);
if (trips.isEmpty())
continue;
int localCount = 0;
int expressCount = 0;
for (Trip trip : trips) {
if (trip.getTripShortName() != null) {
boolean isExpress = trip.getTripShortName().equals("EXPRESS");
if (isExpress)
expressCount++;
else
localCount++;
} else {
localCount++;
}
}
/**
* We only add local vs express to the trip headsign if there are a
* combination of locals and expresses for a given route. We add the route
* short name either way
*/
boolean addLocalVsExpressToTripName = localCount > 0 && expressCount > 0;
for (Trip trip : trips) {
if (trip == null || trip.getTripShortName() == null)
continue;
boolean isExpress = trip.getTripShortName().equals("EXPRESS");
if (isExpress) {
_log.info("route(" + route.getShortName() + ") gets an E for trip " + trip.getId());
trip.setRouteShortName(trip.getRoute().getShortName() + "E");
if (addLocalVsExpressToTripName) {
String tripHeadsign = trip.getTripHeadsign();
if (tripHeadsign != null)
trip.setTripHeadsign(tripHeadsign + " - Express");
}
}
}
}
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsDaoImplTest method testBart.
@Test
public void testBart() throws IOException {
GtfsDaoImpl dao = new GtfsDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getBartGtfs(), "BART");
Collection<Agency> agencies = dao.getAllAgencies();
assertEquals(2, agencies.size());
Agency agency = dao.getAgencyForId("BART");
assertEquals("BART", agency.getId());
Collection<ServiceCalendarDate> calendarDates = dao.getAllCalendarDates();
assertEquals(32, calendarDates.size());
ServiceCalendarDate calendarDate = dao.getCalendarDateForId(1);
assertEquals(new AgencyAndId("BART", "SUN"), calendarDate.getServiceId());
assertEquals(new ServiceDate(2009, 1, 1), calendarDate.getDate());
assertEquals(1, calendarDate.getExceptionType());
Collection<ServiceCalendar> calendars = dao.getAllCalendars();
assertEquals(5, calendars.size());
ServiceCalendar calendar = dao.getCalendarForId(1);
assertEquals(new AgencyAndId("BART", "WKDY"), calendar.getServiceId());
assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
assertEquals(new ServiceDate(2010, 12, 31), calendar.getEndDate());
assertEquals(1, calendar.getMonday());
assertEquals(1, calendar.getTuesday());
assertEquals(1, calendar.getWednesday());
assertEquals(1, calendar.getThursday());
assertEquals(1, calendar.getFriday());
assertEquals(0, calendar.getSaturday());
assertEquals(0, calendar.getSunday());
Collection<FareAttribute> fareAttributes = dao.getAllFareAttributes();
assertEquals(106, fareAttributes.size());
FareAttribute fareAttribute = dao.getFareAttributeForId(new AgencyAndId("BART", "30"));
assertEquals(new AgencyAndId("BART", "30"), fareAttribute.getId());
Collection<FareRule> fareRules = dao.getAllFareRules();
assertEquals(1849, fareRules.size());
FareRule fareRule = dao.getFareRuleForId(1);
assertEquals(new AgencyAndId("BART", "98"), fareRule.getFare().getId());
Collection<Frequency> frequencies = dao.getAllFrequencies();
assertEquals(6, frequencies.size());
Frequency frequency = dao.getFrequencyForId(1);
assertEquals(new AgencyAndId("AirBART", "M-FSAT1DN"), frequency.getTrip().getId());
Collection<Route> routes = dao.getAllRoutes();
assertEquals(11, routes.size());
Route route = dao.getRouteForId(new AgencyAndId("BART", "01"));
assertEquals(new AgencyAndId("BART", "01"), route.getId());
Collection<ShapePoint> shapePoints = dao.getAllShapePoints();
assertEquals(105, shapePoints.size());
ShapePoint shapePoint = dao.getShapePointForId(1);
assertEquals(new AgencyAndId("BART", "airbart-dn.csv"), shapePoint.getShapeId());
Collection<Stop> stops = dao.getAllStops();
assertEquals(46, stops.size());
Stop stop = dao.getStopForId(new AgencyAndId("BART", "DBRK"));
assertEquals("Downtown Berkeley BART", stop.getName());
Collection<StopTime> stopTimes = dao.getAllStopTimes();
assertEquals(33270, stopTimes.size());
StopTime stopTime = stopTimes.iterator().next();
assertEquals(18000, stopTime.getArrivalTime());
Collection<Transfer> transfers = dao.getAllTransfers();
assertEquals(4, transfers.size());
Transfer transfer = dao.getTransferForId(1);
assertEquals(1, transfer.getTransferType());
Collection<Trip> trips = dao.getAllTrips();
assertEquals(1620, trips.size());
Trip trip = dao.getTripForId(new AgencyAndId("BART", "15PB1"));
assertEquals(new AgencyAndId("BART", "WKDY"), trip.getServiceId());
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class TranslationServiceImplTest method testTranslations.
@Test
public void testTranslations() throws IOException {
String agencyId = "agency";
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getTestAgencyGtfs(), agencyId);
TranslationServiceImpl ts = new TranslationServiceImpl();
ts.setData(TranslationServiceDataFactoryImpl.createData(dao));
Agency agency = dao.getAgencyForId(agencyId);
assertEquals("Fake Agency Spanish", ts.getTranslatedEntity("es", Agency.class, agency).getName());
assertEquals("Fake Agency French", ts.getTranslatedEntity("fr", Agency.class, agency).getName());
Stop stop = dao.getStopForId(aid("A"));
assertEquals("A Spanish", ts.getTranslatedEntity("es", Stop.class, stop).getName());
assertEquals("A French", ts.getTranslatedEntity("fr", Stop.class, stop).getName());
Route route = dao.getRouteForId(aid("3"));
assertEquals("3 Spanish", ts.getTranslatedEntity("es", Route.class, route).getLongName());
assertEquals("3 French", ts.getTranslatedEntity("fr", Route.class, route).getLongName());
Trip trip3 = dao.getTripForId(aid("3.1"));
assertEquals("headsign Spanish", ts.getTranslatedEntity("es", Trip.class, trip3).getTripHeadsign());
assertEquals("headsign French", ts.getTranslatedEntity("fr", Trip.class, trip3).getTripHeadsign());
Trip trip4 = dao.getTripForId(aid("4.3"));
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip4);
StopTime st1 = stopTimes.get(0);
StopTime st2 = stopTimes.get(1);
assertEquals("to G Spanish", ts.getTranslatedEntity("es", StopTime.class, st1).getStopHeadsign());
assertEquals("to H Spanish", ts.getTranslatedEntity("es", StopTime.class, st2).getStopHeadsign());
assertEquals("to G French", ts.getTranslatedEntity("fr", StopTime.class, st1).getStopHeadsign());
assertEquals("to H French", ts.getTranslatedEntity("fr", StopTime.class, st2).getStopHeadsign());
FeedInfo feedInfo = dao.getAllFeedInfos().iterator().next();
assertEquals("Fake Feed Publisher Spanish", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.es", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherUrl());
assertEquals("Fake Feed Publisher French", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.fr", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherUrl());
// Check default translations
assertEquals("Fake Agency", ts.getTranslatedEntity("en", Agency.class, agency).getName());
assertEquals("A", ts.getTranslatedEntity("en", Stop.class, stop).getName());
assertEquals("3", ts.getTranslatedEntity("en", Route.class, route).getLongName());
assertEquals("headsign", ts.getTranslatedEntity("en", Trip.class, trip3).getTripHeadsign());
assertEquals("to G", ts.getTranslatedEntity("en", StopTime.class, st1).getStopHeadsign());
assertEquals("to H", ts.getTranslatedEntity("en", StopTime.class, st2).getStopHeadsign());
assertEquals("Fake Feed Publisher", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.com", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherUrl());
}
use of org.onebusaway.gtfs.model.Route in project onebusaway-gtfs-modules by OneBusAway.
the class RouteValidator method validateEntity.
public void validateEntity(CsvEntityContext context, Map<String, Object> csvValues, BeanWrapper object) {
Route route = object.getWrappedInstance(Route.class);
String shortName = route.getShortName();
String longName = route.getLongName();
if ((shortName == null || shortName.length() == 0) && (longName == null || longName.length() == 0))
throw new RouteNameException(route.getId());
}
Aggregations