use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class BlockSequenceIndex method toString.
@Override
public String toString() {
BlockSequence first = _sequences.get(0);
BlockConfigurationEntry blockConfig = first.getBlockConfig();
BlockEntry block = blockConfig.getBlock();
List<BlockStopTimeEntry> bsts = first.getStopTimes();
BlockStopTimeEntry firstBst = bsts.get(0);
BlockStopTimeEntry lastBst = bsts.get(bsts.size() - 1);
StopEntry fromStop = firstBst.getStopTime().getStop();
StopEntry toStop = lastBst.getStopTime().getStop();
return "BlockSequenceIndex [ex: block=" + block.getId() + " fromStop=" + fromStop.getId() + " toStop=" + toStop.getId() + " serviceIds=" + getServiceIds() + "]";
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class SiriService method handleVehicleMonitoring.
/**
**
* Private Methods
***
*/
private void handleVehicleMonitoring(ServiceDelivery serviceDelivery, VehicleMonitoringDeliveryStructure deliveryForModule, SiriEndpointDetails endpointDetails) {
List<VehicleLocationRecord> records = new ArrayList<VehicleLocationRecord>();
Date now = new Date();
long timeFrom = now.getTime() - _blockInstanceSearchWindow * 60 * 1000;
long timeTo = now.getTime() + _blockInstanceSearchWindow * 60 * 1000;
for (VehicleActivityStructure vehicleActivity : deliveryForModule.getVehicleActivity()) {
Date time = vehicleActivity.getRecordedAtTime();
if (time == null)
time = now;
MonitoredVehicleJourney mvj = vehicleActivity.getMonitoredVehicleJourney();
Duration delay = mvj.getDelay();
if (delay == null)
continue;
VehicleRefStructure vehicleRef = mvj.getVehicleRef();
if (vehicleRef == null || vehicleRef.getValue() == null)
continue;
BlockEntry block = getBlockForMonitoredVehicleJourney(mvj, endpointDetails);
if (block == null) {
TripEntry trip = getTripForMonitoredVehicleJourney(mvj, endpointDetails);
if (trip != null)
block = trip.getBlock();
}
if (block == null)
continue;
List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(block.getId(), timeFrom, timeTo);
// TODO : We currently assume that a block won't overlap with itself
if (instances.size() != 1)
continue;
BlockInstance instance = instances.get(0);
VehicleLocationRecord r = new VehicleLocationRecord();
r.setTimeOfRecord(time.getTime());
r.setServiceDate(instance.getServiceDate());
r.setBlockId(block.getId());
String agencyId = block.getId().getAgencyId();
r.setVehicleId(new AgencyAndId(agencyId, vehicleRef.getValue()));
r.setScheduleDeviation(delay.getTimeInMillis(now) / 1000);
LocationStructure location = mvj.getVehicleLocation();
if (location != null) {
r.setCurrentLocationLat(location.getLatitude().doubleValue());
r.setCurrentLocationLon(location.getLongitude().doubleValue());
}
records.add(r);
}
if (!records.isEmpty())
_vehicleLocationListener.handleVehicleLocationRecords(records);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class UserReportingServiceImpl method reportProblemWithTrip.
@Override
public void reportProblemWithTrip(TripProblemReportBean problem) {
AgencyAndId tripId = AgencyAndIdLibrary.convertFromString(problem.getTripId());
TripEntry trip = _graph.getTripEntryForId(tripId);
if (trip == null)
return;
BlockEntry block = trip.getBlock();
TripProblemReportRecord record = new TripProblemReportRecord();
record.setCode(problem.getCode());
record.setServiceDate(problem.getServiceDate());
String vehicleId = problem.getVehicleId();
if (vehicleId != null)
record.setVehicleId(AgencyAndIdLibrary.convertFromString(vehicleId));
String stopId = problem.getStopId();
if (stopId != null)
record.setStopId(AgencyAndIdLibrary.convertFromString(stopId));
record.setTime(problem.getTime());
record.setTripId(tripId);
record.setBlockId(block.getId());
record.setUserComment(problem.getUserComment());
if (problem.getUserLat() != null && !Double.isNaN(problem.getUserLat()))
record.setUserLat(problem.getUserLat());
if (problem.getUserLon() != null && !Double.isNaN(problem.getUserLon()))
record.setUserLon(problem.getUserLon());
if (problem.getUserLocationAccuracy() != null && !Double.isNaN(problem.getUserLocationAccuracy()))
record.setUserLocationAccuracy(problem.getUserLocationAccuracy());
record.setUserOnVehicle(problem.isUserOnVehicle());
record.setUserVehicleNumber(problem.getUserVehicleNumber());
Map<BlockInstance, List<BlockLocation>> locationsByInstance = _blockStatusService.getBlocks(block.getId(), problem.getServiceDate(), record.getVehicleId(), problem.getTime());
BlockInstance blockInstance = getBestBlockInstance(locationsByInstance.keySet());
if (blockInstance != null) {
List<BlockLocation> blockLocations = locationsByInstance.get(blockInstance);
BlockLocation blockLocation = getBestLocation(blockLocations, problem);
if (blockLocation != null) {
record.setPredicted(blockLocation.isPredicted());
if (blockLocation.isDistanceAlongBlockSet())
record.setDistanceAlongBlock(blockLocation.getDistanceAlongBlock());
if (blockLocation.isScheduleDeviationSet())
record.setScheduleDeviation(blockLocation.getScheduleDeviation());
CoordinatePoint p = blockLocation.getLocation();
if (p != null) {
record.setVehicleLat(p.getLat());
record.setVehicleLon(p.getLon());
}
record.setMatchedVehicleId(blockLocation.getVehicleId());
}
}
record.setStatus(problem.getStatus());
_userReportingDao.saveOrUpdate(record);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class ExtendedCalendarServiceImplTest method testGetNextServiceDatesForDepartureInterval.
@Test
public void testGetNextServiceDatesForDepartureInterval() {
BlockEntry blockA = block("blockA");
blockConfiguration(blockA, serviceIds(lsids("sA"), lsids()));
List<BlockEntry> blocks = Arrays.asList(blockA);
Mockito.when(_transitGraphDao.getAllBlocks()).thenReturn(blocks);
_service.start();
ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids());
int inFrom = time(8, 00);
int inTo = time(20, 00);
ServiceInterval interval = new ServiceInterval(inFrom, inFrom, inTo, inTo);
long time = dateAsLong("2010-09-10 09:30");
List<Date> dates = _service.getNextServiceDatesForDepartureInterval(serviceIds, interval, time);
assertEquals(1, dates.size());
assertEquals(date("2010-09-10 00:00"), dates.get(0));
time = dateAsLong("2010-09-10 21:30");
dates = _service.getNextServiceDatesForDepartureInterval(serviceIds, interval, time);
assertEquals(1, dates.size());
assertEquals(date("2010-09-11 00:00"), dates.get(0));
time = dateAsLong("2010-09-11 21:30");
dates = _service.getNextServiceDatesForDepartureInterval(serviceIds, interval, time);
assertEquals(0, dates.size());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImplTest method testFrequencies.
@Test
public void testFrequencies() {
BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
StopEntryImpl stopA = stop("a", 47.0, -122.0);
StopEntryImpl stopB = stop("b", 47.1, -122.1);
/**
**
* Block A
***
*/
BlockEntryImpl blockA = block("a");
TripEntryImpl tripA = trip("a", "s1");
stopTime(0, stopA, tripA, 0, 10, 0);
stopTime(0, stopB, tripA, 20, 20, 0);
FrequencyEntry freqA1 = frequency(time(6, 00), time(9, 00), 10, 0);
FrequencyEntry freqA2 = frequency(time(15, 00), time(18, 00), 10, 0);
List<FrequencyEntry> freqsA = Arrays.asList(freqA1, freqA2);
linkBlockTrips(blockA, freqsA, tripA);
/**
**
* Block B
***
*/
BlockEntryImpl blockB = block("b");
TripEntryImpl tripB = trip("b", "s1");
stopTime(0, stopA, tripB, 20, 30, 0);
stopTime(0, stopB, tripB, 50, 50, 0);
FrequencyEntry freqB1 = frequency(time(9, 00), time(15, 00), 20, 0);
FrequencyEntry freqB2 = frequency(time(18, 00), time(21, 00), 20, 0);
List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
linkBlockTrips(blockB, freqsB, tripB);
List<FrequencyBlockTripIndex> allIndices = factory.createFrequencyTripIndices(Arrays.asList((BlockEntry) blockB, blockA));
assertEquals(1, allIndices.size());
List<FrequencyBlockTripIndex> indices = grep(allIndices, aid("a"));
assertEquals(1, indices.size());
FrequencyBlockTripIndex index = indices.get(0);
List<TripEntry> trips = trips(index.getTrips());
assertEquals(4, trips.size());
assertEquals(tripA, trips.get(0));
assertEquals(tripB, trips.get(1));
assertEquals(tripA, trips.get(2));
assertEquals(tripB, trips.get(3));
List<FrequencyEntry> freqs = index.getFrequencies();
assertEquals(Arrays.asList(freqA1, freqB1, freqA2, freqB2), freqs);
ServiceIdActivation serviceIds = index.getServiceIds();
assertEquals(1, serviceIds.getActiveServiceIds().size());
assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
FrequencyServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
assertTrue(Arrays.equals(new int[] { time(6, 0), time(9, 0), time(15, 0), time(18, 0) }, intervalBlock.getStartTimes()));
assertTrue(Arrays.equals(new int[] { time(9, 0), time(15, 0), time(18, 0), time(21, 0) }, intervalBlock.getEndTimes()));
}
Aggregations