db-vendo-client/p/vbb/index.js

86 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-11-18 17:53:12 +01:00
'use strict'
2019-10-20 00:19:52 +02:00
const {parseHook} = require('../../lib/profile-hooks')
2017-11-18 17:53:12 +01:00
2022-03-07 01:34:33 +01:00
const parseAndAddLocationDHID = require('./parse-loc-dhid')
2019-10-20 00:19:52 +02:00
const _parseLine = require('../../parse/line')
2017-11-18 17:53:12 +01:00
const _parseLocation = require('../../parse/location')
2019-10-20 00:19:52 +02:00
const _parseJourney = require('../../parse/journey')
const _parseDeparture = require('../../parse/departure')
2017-11-18 17:53:12 +01:00
const baseProfile = require('./base.json')
2018-03-16 14:23:27 +01:00
const products = require('./products')
2017-11-18 17:53:12 +01:00
2021-12-29 18:29:10 +01:00
const parseLineWithShortName = ({parsed}, p) => {
2019-10-20 00:19:52 +02:00
parsed.name = p.name.replace(/^(bus|tram)\s+/i, '')
return parsed
2017-11-18 17:53:12 +01:00
}
2019-10-20 00:19:52 +02:00
const parseLocation = ({parsed}, l) => {
2022-03-07 01:34:33 +01:00
parseAndAddLocationDHID(parsed, l)
2019-10-20 00:19:52 +02:00
return parsed
2017-11-18 17:53:12 +01:00
}
// todo: move this to parse/tickets.js?
2019-10-20 00:19:52 +02:00
const parseJourneyWithTickets = ({parsed}, j) => {
if (
j.trfRes &&
Array.isArray(j.trfRes.fareSetL)
2019-10-20 00:19:52 +02:00
) {
parsed.tickets = j.trfRes.fareSetL
.map((s) => {
if (!Array.isArray(s.fareL) || s.fareL.length === 0) return null
return {
name: s.name,
description: s.desc,
tickets: s.fareL.map((f) => ({
// todo: sometimes there's also t.ticketL
name: f.name,
price: f.price,
})),
}
})
.filter(set => !!set)
// todo: j.trfRes.totalPrice
// todo: j.trfRes.msgL
}
2019-10-20 00:19:52 +02:00
return parsed
}
2019-10-20 00:19:52 +02:00
const ringbahnClockwise = /^ringbahn s\s?41$/i
const ringbahnAnticlockwise = /^ringbahn s\s?42$/i
const parseDepartureRenameRingbahn = ({parsed}) => {
if (parsed.line && parsed.line.product === 'suburban') {
const d = parsed.direction && parsed.direction.trim()
if (ringbahnClockwise.test(d)) {
parsed.direction = 'Ringbahn S41 ⟳'
} else if (ringbahnAnticlockwise.test(d)) {
parsed.direction = 'Ringbahn S42 ⟲'
}
}
2019-10-20 00:19:52 +02:00
return parsed
}
2017-11-18 17:53:12 +01:00
const vbbProfile = {
...baseProfile,
locale: 'de-DE',
2017-11-18 17:53:12 +01:00
timezone: 'Europe/Berlin',
products: products,
2017-12-12 03:28:54 +01:00
2021-12-29 18:29:10 +01:00
parseLine: parseHook(_parseLine, parseLineWithShortName),
2019-10-20 00:19:52 +02:00
parseLocation: parseHook(_parseLocation, parseLocation),
parseJourney: parseHook(_parseJourney, parseJourneyWithTickets),
parseDeparture: parseHook(_parseDeparture, parseDepartureRenameRingbahn),
2017-11-18 17:53:12 +01:00
journeysWalkingSpeed: true,
refreshJourneyUseOutReconL: true,
trip: true,
2018-08-26 18:35:27 +02:00
radar: true,
2020-09-16 17:21:59 +02:00
reachableFrom: true,
2017-11-18 17:53:12 +01:00
}
module.exports = vbbProfile