merge next into tests-rewrite

This commit is contained in:
Jannis R 2018-06-10 14:57:51 +02:00
commit b419477a7d
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
17 changed files with 44 additions and 23 deletions

View file

@ -4,7 +4,7 @@
- [`journeyLeg(ref, lineName, [opt])`](journey-leg.md) get details for a leg of a journey - [`journeyLeg(ref, lineName, [opt])`](journey-leg.md) get details for a leg of a journey
- [`departures(station, [opt])`](departures.md) query the next departures at a station - [`departures(station, [opt])`](departures.md) query the next departures at a station
- [`locations(query, [opt])`](locations.md) find stations, POIs and addresses - [`locations(query, [opt])`](locations.md) find stations, POIs and addresses
- [`location(id)`](location.md) get details about a location - [`station(id)`](station.md) get details about a station
- [`nearby(location, [opt])`](nearby.md) show stations & POIs around - [`nearby(location, [opt])`](nearby.md) show stations & POIs around
- [`radar(north, west, south, east, [opt])`](radar.md) find all vehicles currently in a certain area - [`radar(north, west, south, east, [opt])`](radar.md) find all vehicles currently in a certain area

View file

@ -1,9 +1,9 @@
# `location(station)` # `station(id)`
`station` must be in one of these formats: `id` must be in one of these formats:
```js ```js
// a station ID, in a format compatible to the profile you use // a station ID, in a format compatible with the profile you use
'900000123456' '900000123456'
// an FPTF `station` object // an FPTF `station` object
@ -29,7 +29,7 @@ const vbbProfile = require('hafas-client/p/vbb')
const client = createClient(vbbProfile) const client = createClient(vbbProfile)
client.location('900000042101') // U Spichernstr. client.station('900000042101') // U Spichernstr.
.then(console.log) .then(console.log)
.catch(console.error) .catch(console.error)
``` ```

View file

@ -221,7 +221,7 @@ const createClient = (profile, request = _request) => {
}) })
} }
const location = (station) => { const station = (station) => {
if ('object' === typeof station) station = profile.formatStation(station.id) if ('object' === typeof station) station = profile.formatStation(station.id)
else if ('string' === typeof station) station = profile.formatStation(station) else if ('string' === typeof station) station = profile.formatStation(station)
else throw new Error('station must be an object or a string.') else throw new Error('station must be an object or a string.')
@ -368,7 +368,7 @@ const createClient = (profile, request = _request) => {
}) })
} }
const client = {departures, journeys, locations, location, nearby} const client = {departures, journeys, locations, station, nearby}
if (profile.journeyLeg) client.journeyLeg = journeyLeg if (profile.journeyLeg) client.journeyLeg = journeyLeg
if (profile.radar) client.radar = radar if (profile.radar) client.radar = radar
Object.defineProperty(client, 'profile', {value: profile}) Object.defineProperty(client, 'profile', {value: profile})

View file

@ -20,6 +20,7 @@ const request = (profile, data) => {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept-Encoding': 'gzip, deflate', 'Accept-Encoding': 'gzip, deflate',
'Accept': 'application/json',
'user-agent': 'https://github.com/public-transport/hafas-client' 'user-agent': 'https://github.com/public-transport/hafas-client'
}, },
query: {} query: {}

View file

@ -10,7 +10,7 @@ client.journeys('8011167', '8000261', {results: 1, tickets: true})
// client.departures('8011167', {duration: 1}) // client.departures('8011167', {duration: 1})
// client.locations('Berlin Jungfernheide') // client.locations('Berlin Jungfernheide')
// client.locations('Atze Musiktheater', {poi: true, addressses: false, fuzzy: false}) // client.locations('Atze Musiktheater', {poi: true, addressses: false, fuzzy: false})
// client.location('8000309') // Regensburg Hbf // client.station('8000309') // Regensburg Hbf
// client.nearby(52.4751309, 13.3656537, {results: 1}) // client.nearby(52.4751309, 13.3656537, {results: 1})
.then((data) => { .then((data) => {

View file

@ -10,7 +10,7 @@ client.journeys('008010226', '008013456', {results: 1})
// client.departures('008010226', { duration: 5 }) // client.departures('008010226', { duration: 5 })
// client.locations('Magdeburg Hbf', {results: 2}) // client.locations('Magdeburg Hbf', {results: 2})
// client.locations('Kunstmuseum Kloster Unser Lieben Frauen Magdeburg', {results: 2}) // client.locations('Kunstmuseum Kloster Unser Lieben Frauen Magdeburg', {results: 2})
// client.location('008010226') // Magdeburg-Neustadt // client.station('008010226') // Magdeburg-Neustadt
// client.nearby({ // client.nearby({
// type: 'location', // type: 'location',
// latitude: 52.148842, // latitude: 52.148842,

View file

@ -10,7 +10,7 @@ client.journeys('8000103', '8000199', {results: 10, tickets: true})
// client.departures('8000199', {duration: 10}) // client.departures('8000199', {duration: 10})
// client.journeyLeg('1|30161|5|100|14032018', 'Bus 52') // client.journeyLeg('1|30161|5|100|14032018', 'Bus 52')
// client.locations('Schleswig', {results: 1}) // client.locations('Schleswig', {results: 1})
// client.location('706990') // Kiel Holunderbusch // client.station('706990') // Kiel Holunderbusch
// client.nearby({type: 'location', latitude: 54.295691, longitude: 10.116424}, {distance: 60}) // client.nearby({type: 'location', latitude: 54.295691, longitude: 10.116424}, {distance: 60})
// client.radar(54.4, 10.0, 54.2, 10.2, {results: 10}) // client.radar(54.4, 10.0, 54.2, 10.2, {results: 10})

View file

@ -9,7 +9,7 @@ const client = createClient(oebbProfile)
client.journeys('1291501', '8100002', {results: 1}) client.journeys('1291501', '8100002', {results: 1})
// client.departures('8100002', {duration: 1}) // client.departures('8100002', {duration: 1})
// client.locations('Salzburg', {results: 2}) // client.locations('Salzburg', {results: 2})
// client.location('8100173') // Graz Hbf // client.station('8100173') // Graz Hbf
// client.nearby(47.812851, 13.045604, {distance: 60}) // client.nearby(47.812851, 13.045604, {distance: 60})
// client.radar({ // client.radar({
// north: 47.827203, // north: 47.827203,

View file

@ -9,7 +9,7 @@ const client = createClient(vbbProfile)
client.journeys('900000003201', '900000024101', {results: 1, polylines: true}) client.journeys('900000003201', '900000024101', {results: 1, polylines: true})
// client.departures('900000013102', {duration: 1}) // client.departures('900000013102', {duration: 1})
// client.locations('Alexanderplatz', {results: 2}) // client.locations('Alexanderplatz', {results: 2})
// client.location('900000042101') // Spichernstr // client.station('900000042101') // Spichernstr
// client.nearby(52.5137344, 13.4744798, {distance: 60}) // client.nearby(52.5137344, 13.4744798, {distance: 60})
// client.radar({ // client.radar({
// north: 52.52411, // north: 52.52411,

View file

@ -30,6 +30,8 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
res.delay = Math.round((realtime - planned) / 1000) res.delay = Math.round((realtime - planned) / 1000)
} else res.delay = null } else res.delay = null
// todo: DRY with parseStopover
// todo: DRY with parseJourneyLeg
if (d.stbStop.aCncl || d.stbStop.dCncl) { if (d.stbStop.aCncl || d.stbStop.dCncl) {
res.cancelled = true res.cancelled = true
Object.defineProperty(res, 'canceled', {value: true}) Object.defineProperty(res, 'canceled', {value: true})

View file

@ -23,6 +23,8 @@ const createParseJourneyLeg = (profile, stations, lines, remarks, polylines) =>
arrival: arr.toISO() arrival: arr.toISO()
} }
// todo: DRY with parseDeparture
// todo: DRY with parseStopover
if (pt.dep.dTimeR && pt.dep.dTimeS) { if (pt.dep.dTimeR && pt.dep.dTimeS) {
const realtime = profile.parseDateTime(profile, j.date, pt.dep.dTimeR) const realtime = profile.parseDateTime(profile, j.date, pt.dep.dTimeR)
const planned = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) const planned = profile.parseDateTime(profile, j.date, pt.dep.dTimeS)

View file

@ -7,16 +7,32 @@ const createParseStopover = (profile, stations, lines, remarks, date) => {
const res = { const res = {
station: stations[parseInt(st.locX)] || null, station: stations[parseInt(st.locX)] || null,
arrival: null, arrival: null,
departure: null arrivalDelay: null,
departure: null,
departureDelay: null
} }
// todo: DRY with parseDeparture
// todo: DRY with parseJourneyLeg
if (st.aTimeR || st.aTimeS) { if (st.aTimeR || st.aTimeS) {
const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS) const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS)
res.arrival = arr.toISO() res.arrival = arr.toISO()
} }
if (st.aTimeR && st.aTimeS) {
const realtime = profile.parseDateTime(profile, date, st.aTimeR)
const planned = profile.parseDateTime(profile, date, st.aTimeS)
res.arrivalDelay = Math.round((realtime - planned) / 1000)
}
if (st.dTimeR || st.dTimeS) { if (st.dTimeR || st.dTimeS) {
const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS) const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS)
res.departure = dep.toISO() res.departure = dep.toISO()
} }
if (st.dTimeR && st.dTimeS) {
const realtime = profile.parseDateTime(profile, date, st.dTimeR)
const planned = profile.parseDateTime(profile, date, st.dTimeS)
res.departureDelay = Math.round((realtime - planned) / 1000)
}
// mark stations the train passes without stopping // mark stations the train passes without stopping
if(st.dInS === false && st.aOutS === false) res.passBy = true if(st.dInS === false && st.aOutS === false) res.passBy = true

View file

@ -278,8 +278,8 @@ test('locations named Jungfernheide', co(function* (t) {
t.end() t.end()
})) }))
test('location', co(function* (t) { test('station', co(function* (t) {
const s = yield client.location(regensburgHbf) const s = yield client.station(regensburgHbf)
validate(t, s, 'station', 'station') validate(t, s, 'station', 'station')
t.equal(s.id, regensburgHbf) t.equal(s.id, regensburgHbf)

View file

@ -217,8 +217,8 @@ test('locations named Magdeburg', co(function*(t) {
t.end() t.end()
})) }))
test('location Magdeburg-Buckau', co(function* (t) { test('station Magdeburg-Buckau', co(function* (t) {
const s = yield client.location(magdeburgBuckau) const s = yield client.station(magdeburgBuckau)
validate(t, s, 'station', 'station') validate(t, s, 'station', 'station')
t.equal(s.id, magdeburgBuckau) t.equal(s.id, magdeburgBuckau)

View file

@ -267,8 +267,8 @@ test('locations named Kiel', co(function* (t) {
t.end() t.end()
})) }))
test('location', co(function* (t) { test('station', co(function* (t) {
const s = yield client.location(kielHbf) const s = yield client.station(kielHbf)
validate(t, s, 'station', 'station') validate(t, s, 'station', 'station')
t.equal(s.id, kielHbf) t.equal(s.id, kielHbf)

View file

@ -303,8 +303,8 @@ test('locations named Salzburg', co(function* (t) {
t.end() t.end()
})) }))
test('location', co(function* (t) { test('station', co(function* (t) {
const loc = yield client.location(wienRenngasse) const loc = yield client.station(wienRenngasse)
// todo: find a way to always get products from the API // todo: find a way to always get products from the API
// todo: cfg.stationProductsOptional option // todo: cfg.stationProductsOptional option

View file

@ -342,8 +342,8 @@ test('locations', co(function* (t) {
t.end() t.end()
})) }))
test('location', co(function* (t) { test('station', co(function* (t) {
const s = yield client.location(spichernstr) const s = yield client.station(spichernstr)
validate(t, s, 'station', 'station') validate(t, s, 'station', 'station')
t.equal(s.id, spichernstr) t.equal(s.id, spichernstr)