use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockLocationHistoryServiceImpl method getHistoryForTripId.
@Override
public Map<AgencyAndIdInstance, List<BlockLocationArchiveRecord>> getHistoryForTripId(AgencyAndId tripId) {
TripEntry trip = _transitGraphDao.getTripEntryForId(tripId);
if (trip == null)
return null;
BlockEntry block = trip.getBlock();
List<File> files = getFilesForBlockId(block.getId());
CsvEntityReader reader = new CsvEntityReader();
reader.setTokenizerStrategy(new DelimiterTokenizerStrategy("\t"));
EntityHandlerImpl handler = new EntityHandlerImpl(tripId);
reader.addEntityHandler(handler);
try {
for (File file : files) {
InputStream in = openFileForInput(file);
reader.readEntities(BlockLocationArchiveRecord.class, in);
in.close();
}
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
Map<AgencyAndIdInstance, List<BlockLocationArchiveRecord>> recordsByInstance = handler.getRecordsByInstance();
for (List<BlockLocationArchiveRecord> records : recordsByInstance.values()) Collections.sort(records, new DistanceAlongBlockComparator());
return recordsByInstance;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntryImpl method getDistanceAlongBlockForIndex.
@Override
public double getDistanceAlongBlockForIndex(int index) {
int tripIndex = tripIndices[index];
BlockTripEntry blockTrip = trips.get(tripIndex);
TripEntry trip = blockTrip.getTrip();
List<StopTimeEntry> stopTimes = trip.getStopTimes();
int stopTimeIndex = index - accumulatedStopTimeIndices[tripIndex];
StopTimeEntry stopTime = stopTimes.get(stopTimeIndex);
return blockTrip.getDistanceAlongBlock() + stopTime.getShapeDistTraveled();
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class AgencyResource method getAgencyExpiryDateDelta.
@Path("{agencyId}/expiry-date-delta")
@GET
@Produces("application/json")
public Response getAgencyExpiryDateDelta(@PathParam("agencyId") String agencyId) {
try {
Date endDate = agencyEndDateMap.get(agencyId);
if (endDate == null) {
_log.info("Service end date for agency " + agencyId + " not cached. Reloading");
List<TripEntry> trips = _graph.getAllTrips();
Set<AgencyAndId> tripSvcIds = new HashSet<AgencyAndId>();
for (TripEntry trip : trips) {
if (trip.getRoute().getId().getAgencyId().equals(agencyId)) {
tripSvcIds.add(trip.getServiceId().getId());
}
}
Set<ServiceDate> serviceDates = new HashSet<ServiceDate>();
for (AgencyAndId serviceId : tripSvcIds) {
serviceDates.addAll(_calendarService.getServiceDatesForServiceId(serviceId));
}
ServiceDate[] serviceDateArray = serviceDates.toArray(new ServiceDate[serviceDates.size()]);
Arrays.sort(serviceDateArray);
if (serviceDateArray.length > 0) {
endDate = serviceDateArray[serviceDateArray.length - 1].getAsDate();
agencyEndDateMap.put(agencyId, endDate);
} else {
// set the end date to the epoch
endDate = new Date(0l);
}
}
Calendar latestSvcDate = Calendar.getInstance();
latestSvcDate.setTime(endDate);
int delta = deltaInDays(Calendar.getInstance(), latestSvcDate);
return Response.ok(ok("agency-expiry-date-delta", delta)).build();
} catch (Exception e) {
_log.error("getAgencyExpiryDateDelta broke", e);
return Response.ok(error("agency-expiry-date-delta", e)).build();
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImplTest method testGetStopsForRoute.
@Test
public void testGetStopsForRoute() {
AgencyAndId routeId = new AgencyAndId("1", "route");
RouteEntryImpl route = new RouteEntryImpl();
route.setId(new AgencyAndId("1", "raw_route"));
List<RouteEntry> routes = Arrays.asList((RouteEntry) route);
RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
routeCollection.setId(routeId);
routeCollection.setChildren(routes);
route.setParent(routeCollection);
Mockito.when(_transitGraphDao.getRouteCollectionForId(routeId)).thenReturn(routeCollection);
RouteCollectionNarrative.Builder rcNarrative = RouteCollectionNarrative.builder();
Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(rcNarrative.create());
StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
StopEntryImpl stopB = stop("stopB", 47.1, -122.1);
StopEntryImpl stopC = stop("stopC", 47.2, -122.2);
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "sidA");
TripEntryImpl tripB = trip("tripB", "sidA");
tripA.setRoute(route);
tripA.setDirectionId("0");
tripB.setRoute(route);
tripB.setDirectionId("1");
route.setTrips(Arrays.asList((TripEntry) tripA, tripB));
TripNarrative.Builder tnA = TripNarrative.builder();
tnA.setTripHeadsign("Destination A");
Mockito.when(_narrativeService.getTripForId(tripA.getId())).thenReturn(tnA.create());
TripNarrative.Builder tnB = TripNarrative.builder();
tnB.setTripHeadsign("Destination B");
Mockito.when(_narrativeService.getTripForId(tripB.getId())).thenReturn(tnB.create());
stopTime(0, stopA, tripA, time(9, 00), time(9, 00), 0);
stopTime(1, stopB, tripA, time(9, 30), time(9, 30), 100);
stopTime(2, stopC, tripA, time(10, 00), time(10, 00), 200);
stopTime(3, stopC, tripB, time(11, 30), time(11, 30), 0);
stopTime(4, stopA, tripB, time(12, 30), time(12, 30), 200);
linkBlockTrips(blockA, tripA, tripB);
List<BlockTripIndex> blockIndices = blockTripIndices(blockA);
Mockito.when(_blockIndexService.getBlockTripIndicesForRouteCollectionId(routeId)).thenReturn(blockIndices);
StopBean stopBeanA = getStopBean(stopA);
StopBean stopBeanB = getStopBean(stopB);
StopBean stopBeanC = getStopBean(stopC);
List<AgencyAndId> stopIds = Arrays.asList(stopA.getId(), stopB.getId(), stopC.getId());
Mockito.when(_routeService.getStopsForRouteCollection(routeId)).thenReturn(stopIds);
Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopBeanA);
Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBeanB);
Mockito.when(_stopBeanService.getStopForId(stopC.getId())).thenReturn(stopBeanC);
AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
shapeIds.add(shapeId);
tripA.setShapeId(shapeId);
EncodedPolylineBean polyline = new EncodedPolylineBean();
Mockito.when(_shapeBeanService.getMergedPolylinesForShapeIds(shapeIds)).thenReturn(Arrays.asList(polyline));
// Setup complete
StopsForRouteBean stopsForRoute = _service.getStopsForRoute(routeId);
List<StopBean> stops = stopsForRoute.getStops();
assertEquals(3, stops.size());
assertSame(stopBeanA, stops.get(0));
assertSame(stopBeanB, stops.get(1));
assertSame(stopBeanC, stops.get(2));
List<EncodedPolylineBean> polylines = stopsForRoute.getPolylines();
assertEquals(1, polylines.size());
assertSame(polyline, polylines.get(0));
List<StopGroupingBean> groupings = stopsForRoute.getStopGroupings();
assertEquals(1, groupings.size());
StopGroupingBean grouping = groupings.get(0);
assertEquals("direction", grouping.getType());
List<StopGroupBean> groups = grouping.getStopGroups();
assertEquals(2, groups.size());
StopGroupBean groupA = groups.get(0);
StopGroupBean groupB = groups.get(1);
NameBean nameA = groupA.getName();
assertEquals("destination", nameA.getType());
assertEquals("Destination A", nameA.getName());
List<String> stopIdsA = groupA.getStopIds();
assertEquals(3, stopIdsA.size());
assertEquals(ids(stopA.getId(), stopB.getId(), stopC.getId()), stopIdsA);
NameBean nameB = groupB.getName();
assertEquals("destination", nameB.getType());
assertEquals("Destination B", nameB.getName());
List<String> stopIdsB = groupB.getStopIds();
assertEquals(2, stopIdsB.size());
assertEquals(ids(stopC.getId(), stopA.getId()), stopIdsB);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImplTest method linkBlockTrips.
private static void linkBlockTrips(ServiceIdActivation serviceIds, BlockEntryImpl block, TripEntryImpl... trips) {
List<TripEntry> tripsInBlock = new ArrayList<TripEntry>();
for (TripEntryImpl trip : trips) tripsInBlock.add(trip);
Builder builder = BlockConfigurationEntryImpl.builder();
builder.setBlock(block);
builder.setTripGapDistances(new double[tripsInBlock.size()]);
builder.setServiceIds(serviceIds);
builder.setTrips(tripsInBlock);
BlockConfigurationEntry config = builder.create();
List<BlockConfigurationEntry> configs = block.getConfigurations();
if (configs == null) {
configs = new ArrayList<BlockConfigurationEntry>();
block.setConfigurations(configs);
}
configs.add(config);
}
Aggregations