use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.
the class StopTimeEntriesFactoryTest method test.
@Test
public void test() {
TransitGraphImpl graph = new TransitGraphImpl();
Stop stopA = new Stop();
stopA.setId(aid("stopA"));
graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
Stop stopB = new Stop();
stopB.setId(aid("stopB"));
graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
Stop stopC = new Stop();
stopC.setId(aid("stopC"));
graph.putStopEntry(stop("stopC", 47.66847942216854, -122.37545336180114));
graph.refreshStopMapping();
Agency agency = new Agency();
agency.setId("1");
agency.setTimezone("America/Los_Angeles");
Route route = new Route();
route.setAgency(agency);
Trip trip = new Trip();
trip.setRoute(route);
trip.setServiceId(aid("serviceId"));
TripEntryImpl tripEntry = trip("trip");
StopTime stA = new StopTime();
stA.setId(100);
stA.setArrivalTime(time(9, 00));
stA.setDepartureTime(time(9, 05));
stA.setStopSequence(100);
stA.setStop(stopA);
stA.setTrip(trip);
StopTime stB = new StopTime();
stB.setId(101);
stB.setStopSequence(101);
stB.setStop(stopB);
stB.setTrip(trip);
StopTime stC = new StopTime();
stC.setId(102);
stC.setArrivalTime(time(10, 00));
stC.setDepartureTime(time(10, 05));
stC.setStopSequence(102);
stC.setStop(stopC);
stC.setTrip(trip);
StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
List<StopTime> stopTimes = Arrays.asList(stA, stB, stC);
ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
ShapePoints shapePoints = shapePointsFactory.create();
List<StopTimeEntryImpl> entries = factory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
assertEquals(stopTimes.size(), entries.size());
StopTimeEntryImpl entry = entries.get(0);
assertEquals(0, entry.getAccumulatedSlackTime());
assertEquals(time(9, 00), entry.getArrivalTime());
assertEquals(time(9, 05), entry.getDepartureTime());
assertEquals(0, entry.getSequence());
assertEquals(181.5, entry.getShapeDistTraveled(), 0.1);
assertEquals(5 * 60, entry.getSlackTime());
entry = entries.get(1);
assertEquals(5 * 60, entry.getAccumulatedSlackTime());
assertEquals(time(9, 28, 31), entry.getArrivalTime());
assertEquals(time(9, 28, 31), entry.getDepartureTime());
assertEquals(1, entry.getSequence());
assertEquals(738.7, entry.getShapeDistTraveled(), 0.1);
assertEquals(0, entry.getSlackTime());
entry = entries.get(2);
assertEquals(5 * 60, entry.getAccumulatedSlackTime());
assertEquals(time(10, 00), entry.getArrivalTime());
assertEquals(time(10, 05), entry.getDepartureTime());
assertEquals(2, entry.getSequence());
assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
assertEquals(5 * 60, entry.getSlackTime());
}
use of org.onebusaway.gtfs.model.Agency in project onebusaway-application-modules by camsys.
the class HastusGtfsFactory method processAgency.
private void processAgency() {
_agency = new Agency();
_agency.setId(_agencyId);
_agency.setLang("en");
_agency.setName("Community Transit");
_agency.setPhone("(800) 562-1375");
_agency.setTimezone("America/Los_Angeles");
_agency.setUrl("http://www.communitytransit.org/");
_dao.saveEntity(_agency);
}
use of org.onebusaway.gtfs.model.Agency in project onebusaway-gtfs-modules by OneBusAway.
the class AgencyMergeStrategyTest method testIdentityMatch.
@Test
public void testIdentityMatch() {
GtfsRelationalDaoImpl sourceA = new GtfsRelationalDaoImpl();
Agency agencyA = new Agency();
agencyA.setId("1");
agencyA.setName("Metro");
agencyA.setUrl("http://metro.gov/");
sourceA.saveEntity(agencyA);
GtfsRelationalDaoImpl sourceB = new GtfsRelationalDaoImpl();
Agency agencyB = new Agency();
agencyB.setId("1");
agencyB.setName("Metro");
agencyB.setUrl("http://metro.gov/");
sourceB.saveEntity(agencyB);
Agency agencyC = new Agency();
agencyC.setId("2");
agencyC.setName("Metra");
agencyC.setUrl("http://metra.gov/");
sourceB.saveEntity(agencyC);
GtfsMergeContext contextA = context(sourceA, _target, "a-");
_strategy.merge(contextA);
GtfsMergeContext contextB = context(sourceB, _target, "b-");
_strategy.merge(contextB);
assertEquals(EDuplicateDetectionStrategy.IDENTITY, contextB.getResolvedDuplicateDetectionStrategy());
Collection<Agency> agencies = _target.getAllAgencies();
assertEquals(2, agencies.size());
assertSame(agencyA, _target.getAgencyForId("1"));
assertSame(agencyC, _target.getAgencyForId("2"));
}
use of org.onebusaway.gtfs.model.Agency in project onebusaway-gtfs-modules by OneBusAway.
the class AgencyMergeStrategyTest method testRenameAllAgencyIdReferences.
@Test
public void testRenameAllAgencyIdReferences() {
GtfsRelationalDaoImpl sourceA = new GtfsRelationalDaoImpl();
Agency agencyA = new Agency();
agencyA.setId("1");
agencyA.setName("Metro");
agencyA.setUrl("http://metro.gov/");
sourceA.saveEntity(agencyA);
GtfsRelationalDaoImpl sourceB = new GtfsRelationalDaoImpl();
Agency agencyB = new Agency();
agencyB.setId("1");
agencyA.setName("Metra");
agencyA.setUrl("http://metra.gov/");
sourceB.saveEntity(agencyB);
Route route = new Route();
route.setAgency(agencyB);
route.setId(new AgencyAndId("1", "routeId"));
sourceB.saveEntity(route);
Trip trip = new Trip();
trip.setRoute(route);
trip.setId(new AgencyAndId("1", "tripId"));
trip.setServiceId(new AgencyAndId("1", "serviceId"));
trip.setShapeId(new AgencyAndId("1", "shapeId"));
sourceB.saveEntity(trip);
FareAttribute fare = new FareAttribute();
fare.setId(new AgencyAndId("1", "fareId"));
sourceB.saveEntity(fare);
Stop stop = new Stop();
stop.setId(new AgencyAndId("1", "stopId"));
sourceB.saveEntity(stop);
ServiceCalendar calendar = new ServiceCalendar();
calendar.setServiceId(new AgencyAndId("1", "serviceId"));
sourceB.saveEntity(calendar);
ServiceCalendarDate calendarDate = new ServiceCalendarDate();
calendarDate.setServiceId(new AgencyAndId("1", "serviceId"));
sourceB.saveEntity(calendarDate);
ShapePoint point = new ShapePoint();
point.setShapeId(new AgencyAndId("1", "shapeId"));
sourceB.saveEntity(point);
_strategy.merge(context(sourceA, _target, "a-"));
_strategy.merge(context(sourceB, _target, "b-"));
Collection<Agency> agencies = _target.getAllAgencies();
assertEquals(2, agencies.size());
assertSame(agencyA, _target.getAgencyForId("1"));
assertSame(agencyB, _target.getAgencyForId("b-1"));
assertEquals("b-1", route.getId().getAgencyId());
assertEquals("b-1", trip.getId().getAgencyId());
assertEquals("b-1", trip.getServiceId().getAgencyId());
assertEquals("b-1", trip.getShapeId().getAgencyId());
assertEquals("b-1", fare.getId().getAgencyId());
assertEquals("b-1", stop.getId().getAgencyId());
assertEquals("b-1", calendar.getServiceId().getAgencyId());
assertEquals("b-1", calendarDate.getServiceId().getAgencyId());
assertEquals("b-1", point.getShapeId().getAgencyId());
}
use of org.onebusaway.gtfs.model.Agency in project onebusaway-gtfs-modules by OneBusAway.
the class AgencyMergeStrategyTest method testFuzzyMatchAgencyName.
@Test
public void testFuzzyMatchAgencyName() {
GtfsRelationalDaoImpl sourceA = new GtfsRelationalDaoImpl();
Agency agencyA = new Agency();
agencyA.setId("1");
agencyA.setName("Metro");
agencyA.setUrl("http://metro.gov/");
sourceA.saveEntity(agencyA);
GtfsRelationalDaoImpl sourceB = new GtfsRelationalDaoImpl();
Agency agencyB = new Agency();
agencyB.setId("1");
agencyB.setName("Metra");
agencyB.setUrl("http://metra.gov/");
sourceB.saveEntity(agencyB);
Agency agencyC = new Agency();
agencyC.setId("2");
agencyC.setName("Metro");
agencyC.setUrl("http://metro.gov/");
sourceB.saveEntity(agencyC);
GtfsMergeContext contextA = context(sourceA, _target, "a-");
_strategy.merge(contextA);
GtfsMergeContext contextB = context(sourceB, _target, "b-");
_strategy.merge(contextB);
assertEquals(EDuplicateDetectionStrategy.FUZZY, contextB.getResolvedDuplicateDetectionStrategy());
Collection<Agency> agencies = _target.getAllAgencies();
assertEquals(2, agencies.size());
assertSame(agencyA, _target.getAgencyForId("1"));
assertSame(agencyB, _target.getAgencyForId("b-1"));
}
Aggregations