radar: support delays

This commit is contained in:
Jannis R 2017-12-18 11:57:48 +01:00
parent aeac22b569
commit 9e5e8b9d56
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 28 additions and 4 deletions

View file

@ -76,7 +76,9 @@ The response may look like this:
} }
}, },
arrival: null, arrival: null,
departure: '2017-12-17T19:16:00.000+01:00' arrivalDelay: null,
departure: '2017-12-17T19:16:00.000+01:00',
departureDelay: null
} /* … */ ], } /* … */ ],
frames: [ { frames: [ {
origin: { origin: {
@ -123,11 +125,15 @@ The response may look like this:
nextStops: [ { nextStops: [ {
station: { /* S+U Alexanderplatz/Dircksenstr. */ }, station: { /* S+U Alexanderplatz/Dircksenstr. */ },
arrival: null, arrival: null,
departure: '2017-12-17T19:52:00.000+01:00' arrivalDelay: null,
departure: '2017-12-17T19:52:00.000+01:00',
departureDelay: null
}, { }, {
station: { /* Memhardstr. */ }, station: { /* Memhardstr. */ },
arrival: '2017-12-17T19:54:00.000+01:00', arrival: '2017-12-17T19:54:00.000+01:00',
departure: '2017-12-17T19:54:00.000+01:00' arrivalDelay: null,
departure: '2017-12-17T19:54:00.000+01:00',
departureDelay: null
}, /* … */ ], }, /* … */ ],
frames: [ { frames: [ {
origin: { /* S+U Alexanderplatz/Dircksenstr. */ }, origin: { /* S+U Alexanderplatz/Dircksenstr. */ },

View file

@ -17,11 +17,23 @@ const createParseMovement = (profile, locations, lines, remarks) => {
? profile.parseDateTime(profile, m.date, s.aTimeR || s.aTimeS) ? profile.parseDateTime(profile, m.date, s.aTimeR || s.aTimeS)
: null : null
return { const res = {
station: locations[s.locX], station: locations[s.locX],
departure: dep ? dep.toISO() : null, departure: dep ? dep.toISO() : null,
arrival: arr ? arr.toISO() : null arrival: arr ? arr.toISO() : null
} }
if (m.dTimeR && m.dTimeS) {
const plannedDep = profile.parseDateTime(profile, m.date, s.dTimeS)
res.departureDelay = Math.round((dep - plannedDep) / 1000)
} else res.departureDelay = null
if (m.aTimeR && m.aTimeS) {
const plannedArr = profile.parseDateTime(profile, m.date, s.aTimeS)
res.arrivalDelay = Math.round((arr - plannedArr) / 1000)
} else res.arrivalDelay = null
return res
} }
const res = { const res = {

View file

@ -81,6 +81,12 @@ const isValidDateTime = (w) => {
const assertValidStopover = (t, s, coordsOptional = false) => { const assertValidStopover = (t, s, coordsOptional = false) => {
if ('arrival' in s) t.ok(isValidDateTime(s.arrival)) if ('arrival' in s) t.ok(isValidDateTime(s.arrival))
if ('departure' in s) t.ok(isValidDateTime(s.departure)) if ('departure' in s) t.ok(isValidDateTime(s.departure))
if (s.arrivalDelay !== null && s.arrivalDelay !== undefined) {
t.equal(typeof s.arrivalDelay, 'number')
}
if (s.departureDelay !== null && s.departureDelay !== undefined) {
t.equal(typeof s.departureDelay, 'number')
}
if (!('arrival' in s) && !('departure' in s)) { if (!('arrival' in s) && !('departure' in s)) {
t.fail('stopover doesn\'t contain arrival or departure') t.fail('stopover doesn\'t contain arrival or departure')
} }