mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parse fns: opt param 💥
- parseLine - parseDeparture - parseJourney - parseJourneyLeg - parseLocation - parseMovement - parseNearby - parseStopover
This commit is contained in:
parent
6ca7924f7b
commit
b6fbaa5825
16 changed files with 43 additions and 43 deletions
|
@ -37,8 +37,8 @@ Assuming the endpoint returns all lines names prefixed with `foo `, We can strip
|
|||
// get the default line parser
|
||||
const createParseLine = require('hafas-client/parse/line')
|
||||
|
||||
const createParseLineWithoutFoo = (profile, data) => {
|
||||
const parseLine = createParseLine(profile, data)
|
||||
const createParseLineWithoutFoo = (profile, opt, data) => {
|
||||
const parseLine = createParseLine(profile, opt, data)
|
||||
|
||||
// wrapper function with additional logic
|
||||
const parseLineWithoutFoo = (l) => {
|
||||
|
|
14
index.js
14
index.js
|
@ -51,7 +51,7 @@ const createClient = (profile, request = _request) => {
|
|||
})
|
||||
.then((d) => {
|
||||
if (!Array.isArray(d.jnyL)) return [] // todo: throw err?
|
||||
const parse = profile.parseDeparture(profile, {
|
||||
const parse = profile.parseDeparture(profile, opt, {
|
||||
locations: d.locations,
|
||||
lines: d.lines,
|
||||
remarks: d.remarks
|
||||
|
@ -167,7 +167,7 @@ const createClient = (profile, request = _request) => {
|
|||
.then((d) => {
|
||||
if (!Array.isArray(d.outConL)) return []
|
||||
|
||||
const parse = profile.parseJourney(profile, {
|
||||
const parse = profile.parseJourney(profile, opt, {
|
||||
locations: d.locations,
|
||||
lines: d.lines,
|
||||
remarks: d.remarks,
|
||||
|
@ -225,7 +225,7 @@ const createClient = (profile, request = _request) => {
|
|||
.then((d) => {
|
||||
if (!d.match || !Array.isArray(d.match.locL)) return []
|
||||
const parse = profile.parseLocation
|
||||
return d.match.locL.map(loc => parse(profile, {lines: d.lines}, loc))
|
||||
return d.match.locL.map(loc => parse(profile, opt, {lines: d.lines}, loc))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ const createClient = (profile, request = _request) => {
|
|||
// todo: proper stack trace?
|
||||
throw new Error('invalid response')
|
||||
}
|
||||
return profile.parseLocation(profile, {lines: d.lines}, d.locL[0])
|
||||
return profile.parseLocation(profile, opt, {lines: d.lines}, d.locL[0])
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,7 @@ const createClient = (profile, request = _request) => {
|
|||
.then((d) => {
|
||||
if (!Array.isArray(d.locL)) return []
|
||||
const parse = profile.parseNearby
|
||||
return d.locL.map(loc => parse(profile, loc))
|
||||
return d.locL.map(loc => parse(profile, opt, loc))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ const createClient = (profile, request = _request) => {
|
|||
}
|
||||
})
|
||||
.then((d) => {
|
||||
const parse = profile.parseJourneyLeg(profile, {
|
||||
const parse = profile.parseJourneyLeg(profile, opt, {
|
||||
locations: d.locations,
|
||||
lines: d.lines,
|
||||
remarks: d.remarks,
|
||||
|
@ -374,7 +374,7 @@ const createClient = (profile, request = _request) => {
|
|||
.then((d) => {
|
||||
if (!Array.isArray(d.jnyL)) return []
|
||||
|
||||
const parse = profile.parseMovement(profile, {
|
||||
const parse = profile.parseMovement(profile, opt, {
|
||||
locations: d.locations,
|
||||
lines: d.lines,
|
||||
remarks: d.remarks,
|
||||
|
|
|
@ -88,13 +88,13 @@ const request = (profile, opt, data) => {
|
|||
d.operators = c.opL.map(op => profile.parseOperator(profile, op))
|
||||
}
|
||||
if (Array.isArray(c.prodL)) {
|
||||
const parse = profile.parseLine(profile, {
|
||||
const parse = profile.parseLine(profile, opt, {
|
||||
operators: d.operators
|
||||
})
|
||||
d.lines = c.prodL.map(parse)
|
||||
}
|
||||
if (Array.isArray(c.locL)) {
|
||||
const parse = loc => profile.parseLocation(profile, {lines: d.lines}, loc)
|
||||
const parse = loc => profile.parseLocation(profile, opt, {lines: d.lines}, loc)
|
||||
d.locations = c.locL.map(parse)
|
||||
}
|
||||
return d
|
||||
|
|
|
@ -34,8 +34,8 @@ const transformJourneysQuery = (query, opt) => {
|
|||
return query
|
||||
}
|
||||
|
||||
const createParseJourney = (profile, data) => {
|
||||
const parseJourney = _createParseJourney(profile, data)
|
||||
const createParseJourney = (profile, opt, data) => {
|
||||
const parseJourney = _createParseJourney(profile, opt, data)
|
||||
|
||||
// todo: j.sotRating, j.conSubscr, j.isSotCon, j.showARSLink, k.sotCtxt
|
||||
// todo: j.conSubscr, j.showARSLink, j.useableTime
|
||||
|
|
|
@ -21,8 +21,8 @@ const transformReqBody = (body) => {
|
|||
return body
|
||||
}
|
||||
|
||||
const parseLocation = (profile, data, l) => {
|
||||
const res = _parseLocation(profile, data, l)
|
||||
const parseLocation = (profile, opt, data, l) => {
|
||||
const res = _parseLocation(profile, opt, data, l)
|
||||
// weird fix for empty lines, e.g. IC/EC at Flensburg Hbf
|
||||
if (res.lines) {
|
||||
res.lines = res.lines.filter(x => x.id && x.name)
|
||||
|
@ -36,8 +36,8 @@ const parseLocation = (profile, data, l) => {
|
|||
return res
|
||||
}
|
||||
|
||||
const createParseJourney = (profile, data) => {
|
||||
const parseJourney = _createParseJourney(profile, data)
|
||||
const createParseJourney = (profile, opt, data) => {
|
||||
const parseJourney = _createParseJourney(profile, opt, data)
|
||||
|
||||
const parseJourneyWithTickets = (j) => {
|
||||
const res = parseJourney(j)
|
||||
|
|
|
@ -25,10 +25,10 @@ const transformReqBody = (body) => {
|
|||
return body
|
||||
}
|
||||
|
||||
const parseLocation = (profile, data, l) => {
|
||||
const parseLocation = (profile, opt, data, l) => {
|
||||
// ÖBB has some 'stations' **in austria** with no departures/products,
|
||||
// like station entrances, that are actually POIs.
|
||||
const res = _parseLocation(profile, data, l)
|
||||
const res = _parseLocation(profile, opt, data, l)
|
||||
if (
|
||||
res.type === 'station' &&
|
||||
!res.products &&
|
||||
|
|
|
@ -23,8 +23,8 @@ const transformReqBody = (body) => {
|
|||
return body
|
||||
}
|
||||
|
||||
const createParseLine = (profile, data) => {
|
||||
const parseLine = _createParseLine(profile, data)
|
||||
const createParseLine = (profile, opt, data) => {
|
||||
const parseLine = _createParseLine(profile, opt, data)
|
||||
|
||||
const parseLineWithMoreDetails = (l) => {
|
||||
const res = parseLine(l)
|
||||
|
@ -42,8 +42,8 @@ const createParseLine = (profile, data) => {
|
|||
return parseLineWithMoreDetails
|
||||
}
|
||||
|
||||
const parseLocation = (profile, data, l) => {
|
||||
const res = _parseLocation(profile, data, l)
|
||||
const parseLocation = (profile, opt, data, l) => {
|
||||
const res = _parseLocation(profile, opt, data, l)
|
||||
|
||||
if (res.type === 'station') {
|
||||
res.name = shorten(res.name)
|
||||
|
@ -56,8 +56,8 @@ const parseLocation = (profile, data, l) => {
|
|||
return res
|
||||
}
|
||||
|
||||
const createParseJourney = (profile, data) => {
|
||||
const parseJourney = _createParseJourney(profile, data)
|
||||
const createParseJourney = (profile, opt, data) => {
|
||||
const parseJourney = _createParseJourney(profile, opt, data)
|
||||
|
||||
const parseJourneyWithTickets = (j) => {
|
||||
const res = parseJourney(j)
|
||||
|
@ -86,8 +86,8 @@ const createParseJourney = (profile, data) => {
|
|||
return parseJourneyWithTickets
|
||||
}
|
||||
|
||||
const createParseDeparture = (profile, data) => {
|
||||
const parseDeparture = _createParseDeparture(profile, data)
|
||||
const createParseDeparture = (profile, opt, data) => {
|
||||
const parseDeparture = _createParseDeparture(profile, opt, data)
|
||||
|
||||
const ringbahnClockwise = /^ringbahn s\s?41$/i
|
||||
const ringbahnAnticlockwise = /^ringbahn s\s?42$/i
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// todo: d.stbStop.dProgType
|
||||
// todo: d.freq, d.freq.jnyL, see https://github.com/public-transport/hafas-client/blob/9203ed1481f08baacca41ac5e3c19bf022f01b0b/parse.js#L115
|
||||
|
||||
const createParseDeparture = (profile, {stations, lines, remarks}) => {
|
||||
const createParseDeparture = (profile, opt, {stations, lines, remarks}) => {
|
||||
const findRemark = rm => remarks[parseInt(rm.remX)] || null
|
||||
|
||||
const parseDeparture = (d) => {
|
||||
|
|
|
@ -4,7 +4,7 @@ const parseDateTime = require('./date-time')
|
|||
|
||||
const clone = obj => Object.assign({}, obj)
|
||||
|
||||
const createParseJourneyLeg = (profile, data) => {
|
||||
const createParseJourneyLeg = (profile, opt, data) => {
|
||||
const {locations, lines, remarks, polylines} = data
|
||||
|
||||
// todo: finish parse/remark.js first
|
||||
|
@ -42,7 +42,7 @@ const createParseJourneyLeg = (profile, data) => {
|
|||
let p = pt.jny.polyG.polyXL
|
||||
p = Array.isArray(p) && polylines[p[0]]
|
||||
// todo: there can be >1 polyline
|
||||
const parse = profile.parsePolyline(profile, data)
|
||||
const parse = profile.parsePolyline(profile, opt, data)
|
||||
res.polyline = p && parse(p) || null
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ const createParseJourneyLeg = (profile, data) => {
|
|||
if (pt.arr.aPlatfS) res.arrivalPlatform = pt.arr.aPlatfS
|
||||
|
||||
if (passed && pt.jny.stopL) {
|
||||
const parse = profile.parseStopover(profile, data, j.date)
|
||||
const parse = profile.parseStopover(profile, opt, data, j.date)
|
||||
const passedStations = pt.jny.stopL.map(parse)
|
||||
// filter stations the train passes without stopping, as this doesn't comply with fptf (yet)
|
||||
res.passed = passedStations.filter((x) => !x.passBy)
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
const clone = obj => Object.assign({}, obj)
|
||||
|
||||
const createParseJourney = (profile, data) => {
|
||||
const parseLeg = profile.parseJourneyLeg(profile, data)
|
||||
const createParseJourney = (profile, opt, data) => {
|
||||
const parseLeg = profile.parseJourneyLeg(profile, opt, data)
|
||||
|
||||
// todo: c.sDays
|
||||
// todo: c.conSubscr
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const slugg = require('slugg')
|
||||
|
||||
const createParseLine = (profile, {operators}) => {
|
||||
const createParseLine = (profile, opt, {operators}) => {
|
||||
const byBitmask = []
|
||||
for (let product of profile.products) {
|
||||
for (let bitmask of product.bitmasks) {
|
||||
|
|
|
@ -7,8 +7,8 @@ const ADDRESS = 'A'
|
|||
// todo: what is s.rRefL?
|
||||
// todo: is passing in profile necessary?
|
||||
|
||||
// todo: [breaking] change to createParseLocation(profile, data) => (l) => loc
|
||||
const parseLocation = (profile, {lines}, l) => {
|
||||
// todo: [breaking] change to createParseLocation(profile, opt, data) => (l) => loc
|
||||
const parseLocation = (profile, opt, {lines}, l) => {
|
||||
const res = {type: 'location'}
|
||||
if (l.crd) {
|
||||
res.latitude = l.crd.y / 1000000
|
||||
|
|
|
@ -10,7 +10,7 @@ const createParseMovement = (profile, data) => {
|
|||
// todo: what is m.ani.dirGeo[n]? maybe the speed?
|
||||
// todo: what is m.ani.proc[n]? wut?
|
||||
const parseMovement = (m) => {
|
||||
const pStopover = profile.parseStopover(profile, data, m.date)
|
||||
const pStopover = profile.parseStopover(profile, opt, data, m.date)
|
||||
|
||||
const res = {
|
||||
direction: profile.parseStationName(m.dirTxt),
|
||||
|
@ -38,13 +38,13 @@ const createParseMovement = (profile, data) => {
|
|||
}
|
||||
|
||||
if (m.ani.poly) {
|
||||
const parse = profile.parsePolyline(profile, data)
|
||||
const parse = profile.parsePolyline(profile, opt, data)
|
||||
res.polyline = parse(m.ani.poly)
|
||||
} else if (m.ani.polyG) {
|
||||
let p = m.ani.polyG.polyXL
|
||||
p = Array.isArray(p) && polylines[p[0]]
|
||||
// todo: there can be >1 polyline
|
||||
const parse = profile.parsePolyline(profile, data)
|
||||
const parse = profile.parsePolyline(profile, opt, data)
|
||||
res.polyline = p && parse(p) || null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
// todo: what is s.dur?
|
||||
|
||||
// todo: [breaking] change to createParseNearby(profile, data) => (n) => nearby
|
||||
const parseNearby = (profile, data, n) => {
|
||||
const res = profile.parseLocation(profile, data, n)
|
||||
const parseNearby = (profile, opt, data, n) => {
|
||||
const res = profile.parseLocation(profile, opt, data, n)
|
||||
res.distance = n.dist
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const {toGeoJSON} = require('@mapbox/polyline')
|
||||
const distance = require('gps-distance')
|
||||
|
||||
const createParsePolyline = (profile, {locations}) => {
|
||||
const createParsePolyline = (profile, opt, {locations}) => {
|
||||
// todo: what is p.delta?
|
||||
// todo: what is p.type?
|
||||
// todo: what is p.crdEncS?
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// todo: arrivalDelay, departureDelay or only delay ?
|
||||
// todo: arrivalPlatform, departurePlatform
|
||||
const createParseStopover = (profile, {locations, lines, remarks}, date) => {
|
||||
const createParseStopover = (profile, opt, {locations, lines, remarks}, date) => {
|
||||
const parseStopover = (st) => {
|
||||
const res = {
|
||||
station: locations[parseInt(st.locX)] || null,
|
||||
|
|
Loading…
Add table
Reference in a new issue