use of org.onebusaway.transit_data_federation.impl.realtime.SiriLikeRealtimeSource.NodesAndTimestamp in project onebusaway-application-modules by camsys.
the class SiriLikeRealtimeSourceTest method testParseRoute2Multi.
// @Test
public void testParseRoute2Multi() throws Exception {
URL url = getClass().getResource("SiriLike_2_multi.xml").toURI().toURL();
NodesAndTimestamp vehicles = source.parseVehicles(url);
assertNotNull(vehicles);
assertEquals(4, vehicles.getNodes().size());
// as we don't have predictions, there isn't much we can do with this
VehicleLocationRecord vlr = source.parse(vehicles.getNodes().get(0), 0);
assertNotNull(vlr);
assertEquals("UTA", vlr.getTripId().getAgencyId());
assertEquals("2726063", vlr.getTripId().getId());
assertNull(vlr.getBlockId());
assertEquals(1470204000000l, vlr.getServiceDate());
assertEquals("13034", vlr.getVehicleId().getId());
assertEquals(40.76492, vlr.getCurrentLocationLat(), 0.0001);
assertEquals(-111.8756, vlr.getCurrentLocationLon(), 0.0001);
assertEquals(-2.0, vlr.getScheduleDeviation(), 0.01);
}
use of org.onebusaway.transit_data_federation.impl.realtime.SiriLikeRealtimeSource.NodesAndTimestamp in project onebusaway-application-modules by camsys.
the class SiriLikeRealtimeSourceTest method testParseEmpty.
@Test
public void testParseEmpty() throws Exception {
URL url = getClass().getResource("SiriLike_Empty.xml").toURI().toURL();
NodesAndTimestamp vehicles = source.parseVehicles(url);
assertNotNull(vehicles);
assertEquals(0, vehicles.getNodes().size());
}
use of org.onebusaway.transit_data_federation.impl.realtime.SiriLikeRealtimeSource.NodesAndTimestamp in project onebusaway-application-modules by camsys.
the class SiriLikeRealtimeSourceTest method testParseRoute2.
// @Test
public void testParseRoute2() throws Exception {
URL url = getClass().getResource("SiriLike_2.xml").toURI().toURL();
NodesAndTimestamp vehicles = source.parseVehicles(url);
assertNotNull(vehicles);
assertEquals(1, vehicles.getNodes().size());
// as we don't have predictions, there isn't much we can do with this
VehicleLocationRecord vlr = source.parse(vehicles.getNodes().get(0), 0);
assertNotNull(vlr);
assertEquals("UTA", vlr.getTripId().getAgencyId());
assertEquals("2726094", vlr.getTripId().getId());
assertNull(vlr.getBlockId());
assertEquals(1470204000000l, vlr.getServiceDate());
assertEquals("07011", vlr.getVehicleId().getId());
assertEquals(40.76589, vlr.getCurrentLocationLat(), 0.0001);
assertEquals(-111.90987, vlr.getCurrentLocationLon(), 0.0001);
assertEquals(-2.0, vlr.getScheduleDeviation(), 0.01);
}
use of org.onebusaway.transit_data_federation.impl.realtime.SiriLikeRealtimeSource.NodesAndTimestamp in project onebusaway-application-modules by camsys.
the class SiriLikeRealtimeSource method parseVehicles.
// process URL into a series of fragments representing vehicle activity
public NodesAndTimestamp parseVehicles(URL url) throws Exception {
List<Node> vehicles = new ArrayList<Node>();
Document doc = builder.parse(url.toString());
String recordedAtStr = (String) recordedAtExpression.evaluate(doc, XPathConstants.STRING);
long timestamp = parseDate(recordedAtStr).getTime();
_log.debug("timestamp=" + new Date(timestamp) + " for date " + recordedAtStr);
NodeList nl = (NodeList) this.mvjExpression.evaluate(doc, XPathConstants.NODESET);
if (nl == null || nl.getLength() == 0) {
_log.debug("no nodes found");
return new NodesAndTimestamp(vehicles, timestamp);
}
for (int i = 0; i < nl.getLength(); i++) {
vehicles.add(nl.item(i));
}
return new NodesAndTimestamp(vehicles, timestamp);
}
use of org.onebusaway.transit_data_federation.impl.realtime.SiriLikeRealtimeSource.NodesAndTimestamp in project onebusaway-application-modules by camsys.
the class SiriLikeRealtimeSource method handleUpdates.
private synchronized void handleUpdates(MonitoredResult result) throws Exception {
int vehicles = 0;
int trips = 0;
for (String route : getRoutes()) {
NodesAndTimestamp nodesAndTimestamp = parseVehicles(new URL(constructUrl(route, getApiKey(), getUrl())));
_log.debug("found " + nodesAndTimestamp.getNodes().size() + " nodes");
for (Node n : nodesAndTimestamp.getNodes()) {
vehicles++;
VehicleLocationRecord vlr = parse(n, nodesAndTimestamp.getTimestamp());
if (vlr != null) {
trips++;
result.addMatchedTripId(vlr.getTripId().getId());
try {
_vehicleLocationListener.handleVehicleLocationRecord(vlr);
} catch (Exception any) {
// bury
}
}
}
}
_log.info("updated " + trips + " of " + vehicles + " for agency " + getAgency());
}
Aggregations