product -> line

migrating to the FPTF naming scheme
This commit is contained in:
Jannis R 2017-05-16 01:30:43 +02:00
parent 44f6d3cd71
commit 3e9be845aa
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 26 additions and 25 deletions

View file

@ -10,7 +10,7 @@ const defaults = {
onBody: id, onBody: id,
onReq: id, onReq: id,
onLocation: parse.location, onLocation: parse.location,
onProduct: parse.product, onLine: parse.line,
onRemark: parse.remark, onRemark: parse.remark,
onOperator: parse.operator onOperator: parse.operator
} }
@ -42,7 +42,7 @@ const request = (opt) => {
const c = d.common || {} const c = d.common || {}
if (Array.isArray(c.locL)) d.locations = c.locL.map(opt.onLocation) if (Array.isArray(c.locL)) d.locations = c.locL.map(opt.onLocation)
if (Array.isArray(c.prodL)) d.products = c.prodL.map(opt.onProduct) if (Array.isArray(c.prodL)) d.lines = c.prodL.map(opt.onLine)
if (Array.isArray(c.remL)) d.remarks = c.remL.map(opt.onRemark) if (Array.isArray(c.remL)) d.remarks = c.remL.map(opt.onRemark)
if (Array.isArray(c.opL)) d.operators = c.opL.map(opt.onOperator) if (Array.isArray(c.opL)) d.operators = c.opL.map(opt.onOperator)
return d return d

View file

@ -40,9 +40,10 @@ const location = (l) => {
// todo: what is p.number vs p.line? // todo: what is p.number vs p.line?
// todo: what is p.icoX? // todo: what is p.icoX?
// todo: what is p.oprX? // todo: what is p.oprX?
const product = (p) => { const line = (p) => {
if (!p) return null if (!p) return null
const result = {line: p.line, name: p.name, class: p.cls} const result = {type: 'line', name: p.line || p.name}
if (p.cls) result.class = p.cls
if (p.prodCtx) { if (p.prodCtx) {
result.productCode = +p.prodCtx.catCode result.productCode = +p.prodCtx.catCode
result.productName = p.prodCtx.catOutS result.productName = p.prodCtx.catOutS
@ -64,8 +65,8 @@ const operator = (a) => ({
// s = stations, p = products, r = remarks, c = connection // s = stations, ln = lines, r = remarks, c = connection
const stop = (tz, s, p, r, c) => (st) => { const stop = (tz, s, ln, r, c) => (st) => {
const result = {station: s[parseInt(st.locX)]} const result = {station: s[parseInt(st.locX)]}
if (st.aTimeR || st.aTimeS) { if (st.aTimeR || st.aTimeS) {
result.arrival = dateTime(tz, c.date, st.aTimeR || st.aTimeS) result.arrival = dateTime(tz, c.date, st.aTimeR || st.aTimeS)
@ -77,15 +78,15 @@ const stop = (tz, s, p, r, c) => (st) => {
} }
// todo: finish parseRemark first // todo: finish parseRemark first
// s = stations, p = products, r = remarks, c = connection // s = stations, ln = lines, r = remarks, c = connection
const applyRemark = (s, p, r, c) => (rm) => null const applyRemark = (s, ln, r, c) => (rm) => null
// todo: pt.sDays // todo: pt.sDays
// todo: pt.dep.dProgType, pt.arr.dProgType // todo: pt.dep.dProgType, pt.arr.dProgType
// todo: what is pt.jny.dirFlg? // todo: what is pt.jny.dirFlg?
// todo: how does pt.freq work? // todo: how does pt.freq work?
// s = stations, p = products, r = remarks, c = connection // s = stations, ln = lines, r = remarks, c = connection
const part = (tz, s, p, r, c) => (pt) => { const part = (tz, s, ln, r, c) => (pt) => {
const result = { const result = {
origin: Object.assign({}, s[parseInt(pt.dep.locX)]) origin: Object.assign({}, s[parseInt(pt.dep.locX)])
, destination: Object.assign({}, s[parseInt(pt.arr.locX)]) , destination: Object.assign({}, s[parseInt(pt.arr.locX)])
@ -96,21 +97,21 @@ const part = (tz, s, p, r, c) => (pt) => {
dateTime(tz, c.date, pt.dep.dTimeR) - dateTime(tz, c.date, pt.dep.dTimeS) dateTime(tz, c.date, pt.dep.dTimeR) - dateTime(tz, c.date, pt.dep.dTimeS)
if (pt.type === 'WALK') result.mode = 'walking' if (pt.type === 'WALK') result.mode = 'walking'
else if (pt.type === 'JNY') { else if (pt.type === 'JNY') {
result.product = p[parseInt(pt.jny.prodX)] result.line = ln[parseInt(pt.jny.prodX)]
result.direction = pt.jny.dirTxt // todo: parse this result.direction = pt.jny.dirTxt // todo: parse this
if (pt.dep.dPlatfS) result.departurePlatform = pt.dep.dPlatfS if (pt.dep.dPlatfS) result.departurePlatform = pt.dep.dPlatfS
if (pt.arr.aPlatfS) result.arrivalPlatform = pt.arr.aPlatfS if (pt.arr.aPlatfS) result.arrivalPlatform = pt.arr.aPlatfS
if (pt.jny.stopL) result.passed = pt.jny.stopL.map(stop(tz, s, p, r, c)) if (pt.jny.stopL) result.passed = pt.jny.stopL.map(stop(tz, s, ln, r, c))
if (Array.isArray(pt.jny.remL)) if (Array.isArray(pt.jny.remL))
pt.jny.remL.forEach(applyRemark(s, p, r, c)) pt.jny.remL.forEach(applyRemark(s, ln, r, c))
if (pt.jny.freq && pt.jny.freq.jnyL) if (pt.jny.freq && pt.jny.freq.jnyL)
result.alternatives = pt.jny.freq.jnyL result.alternatives = pt.jny.freq.jnyL
.filter((a) => a.stopL[0].locX === pt.dep.locX) .filter((a) => a.stopL[0].locX === pt.dep.locX)
.map((a) => ({ .map((a) => ({
product: p[parseInt(a.prodX)], line: ln[parseInt(a.prodX)],
when: dateTime(tz, c.date, a.stopL[0].dTimeS) when: dateTime(tz, c.date, a.stopL[0].dTimeS)
})) }))
} }
@ -122,9 +123,9 @@ const part = (tz, s, p, r, c) => (pt) => {
// todo: c.conSubscr // todo: c.conSubscr
// todo: c.trfRes x vbb-parse-ticket // todo: c.trfRes x vbb-parse-ticket
// todo: use computed information from part // todo: use computed information from part
// s = stations, p = products, r = remarks // s = stations, ln = lines, r = remarks
const route = (tz, s, p, r) => (c) => { const route = (tz, s, ln, r) => (c) => {
const parts = c.secL.map(part(tz, s, p, r, c)) const parts = c.secL.map(part(tz, s, ln, r, c))
return { return {
parts parts
, origin: parts[0].origin , origin: parts[0].origin
@ -137,13 +138,13 @@ const route = (tz, s, p, r) => (c) => {
// todo: what is d.jny.dirFlg? // todo: what is d.jny.dirFlg?
// todo: d.stbStop.dProgType // todo: d.stbStop.dProgType
// todo: what is d.stbStop.dTimeR? // todo: what is d.stbStop.dTimeR?
// tz = timezone, s = stations, p = products, r = remarks // tz = timezone, s = stations, ln = lines, r = remarks
const departure = (tz, s, p, r) => (d) => { const departure = (tz, s, ln, r) => (d) => {
const result = { const result = {
station: s[parseInt(d.stbStop.locX)] station: s[parseInt(d.stbStop.locX)]
, when: dateTime(tz, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS) , when: dateTime(tz, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
, direction: d.dirTxt , direction: d.dirTxt
, product: p[parseInt(d.prodX)] , line: ln[parseInt(d.prodX)]
, remarks: d.remL ? d.remL.map((rm) => r[parseInt(rm.remX)]) : null , remarks: d.remL ? d.remL.map((rm) => r[parseInt(rm.remX)]) : null
, trip: +d.jid.split('|')[1] , trip: +d.jid.split('|')[1]
} }
@ -153,7 +154,7 @@ const departure = (tz, s, p, r) => (d) => {
} }
// todo: remarks // todo: remarks
// todo: products // todo: lines
// todo: what is s.pCls? // todo: what is s.pCls?
// todo: what is s.wt? // todo: what is s.wt?
// todo: what is s.dur? // todo: what is s.dur?
@ -170,11 +171,11 @@ const nearby = (n) => {
// todo: what is m.ani.dirGeo[n]? maybe the speed? // todo: what is m.ani.dirGeo[n]? maybe the speed?
// todo: what is m.ani.proc[n]? wut? // todo: what is m.ani.proc[n]? wut?
// todo: how does m.ani.poly work? // todo: how does m.ani.poly work?
// tz = timezone, l = locations, p = products, r = remarks // tz = timezone, l = locations, ln = lines, r = remarks
const movement = (tz, l, p, r) => (m) => { const movement = (tz, l, ln, r) => (m) => {
const result = { const result = {
direction: m.dirTxt direction: m.dirTxt
, product: p[m.prodX] , line: ln[m.prodX]
, coordinates: m.pos ? { , coordinates: m.pos ? {
latitude: m.pos.y / 1000000, latitude: m.pos.y / 1000000,
longitude: m.pos.x / 1000000 longitude: m.pos.x / 1000000
@ -204,7 +205,7 @@ const movement = (tz, l, p, r) => (m) => {
module.exports = { module.exports = {
dateTime, dateTime,
location, product, remark, operator, location, line, remark, operator,
stop, applyRemark, part, route, stop, applyRemark, part, route,
departure, departure,
nearby, nearby,