diff --git a/p/insa/example.js b/p/insa/example.js index 1a46a1d6..054ae1f3 100644 --- a/p/insa/example.js +++ b/p/insa/example.js @@ -16,6 +16,7 @@ client.journeys('008010226', '008013456', {results: 1}) // latitude: 52.148842, // longitude: 11.641705 // }, {distance: 200}) +// client.radar(52.148364, 11.600826, 52.108486, 11.651451, {results: 10}) // .then(([journey]) => { // const leg = journey.legs[0] diff --git a/p/insa/index.js b/p/insa/index.js index ee1b8973..4a2de867 100644 --- a/p/insa/index.js +++ b/p/insa/index.js @@ -76,7 +76,7 @@ const insaProfile = { parseLine: createParseLine, journeyLeg: true - // todo: radar? + radar: true } module.exports = insaProfile; diff --git a/p/insa/products.js b/p/insa/products.js index 81cb82f7..d6b343e5 100644 --- a/p/insa/products.js +++ b/p/insa/products.js @@ -65,7 +65,8 @@ p.bitmasks[2] = p.national p.bitmasks[8] = p.regional p.bitmasks[16] = p.suburban p.bitmasks[32] = p.tram -p.bitmasks[64+128] = p.bus +p.bitmasks[64] = p.bus +p.bitmasks[128] = p.bus p.bitmasks[256] = p.tourismTrain p.allProducts = [ diff --git a/parse/location.js b/parse/location.js index c0de893d..e6689e6b 100644 --- a/parse/location.js +++ b/parse/location.js @@ -20,7 +20,7 @@ const parseLocation = (profile, l, lines) => { type: 'station', id: l.extId, name: l.name, - location: res + location: 'number' === typeof res.latitude ? res : null } if ('pCls' in l) station.products = profile.parseProducts(l.pCls) diff --git a/test/insa.js b/test/insa.js index 09be1d80..f22581d6 100644 --- a/test/insa.js +++ b/test/insa.js @@ -310,3 +310,56 @@ test('location', co(function*(t) { t.end() })) + +test('radar', co(function* (t) { + const north = 52.148364 + const west = 11.600826 + const south = 52.108486 + const east = 11.651451 + const vehicles = yield client.radar(north, west, south, east, { + duration: 5 * 60, when, results: 10 + }) + + t.ok(Array.isArray(vehicles)) + t.ok(vehicles.length > 0) + for (let v of vehicles) { + assertValidLine(t, v.line) + + t.equal(typeof v.location.latitude, 'number') + t.ok(v.location.latitude <= 57, 'vehicle is too far away') + t.ok(v.location.latitude >= 47, 'vehicle is too far away') + t.equal(typeof v.location.longitude, 'number') + t.ok(v.location.longitude >= 8, 'vehicle is too far away') + t.ok(v.location.longitude <= 14, 'vehicle is too far away') + + t.ok(Array.isArray(v.nextStops)) + for (let st of v.nextStops) { + assertValidStopover(t, st, true) + + if (st.arrival) { + t.equal(typeof st.arrival, 'string') + const arr = +new Date(st.arrival) + // note that this can be an ICE train + t.ok(isRoughlyEqual(14 * hour, +when, arr)) + } + if (st.departure) { + t.equal(typeof st.departure, 'string') + const dep = +new Date(st.departure) + // note that this can be an ICE train + t.ok(isRoughlyEqual(14 * hour, +when, dep)) + } + } + + t.ok(Array.isArray(v.frames)) + for (let f of v.frames) { + // see #28 + // todo: check if this works by now + assertValidStation(t, f.origin, true) + assertValidStationProducts(t, f.origin.products) + assertValidStation(t, f.destination, true) + assertValidStationProducts(t, f.destination.products) + t.equal(typeof f.t, 'number') + } + } + t.end() +}))