NAH.SH: use new products markup 🐛

This commit is contained in:
Jannis R 2018-03-21 01:42:13 +01:00
parent f037ddf74c
commit 87ec80d404
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 52 additions and 116 deletions

View file

@ -1,8 +1,5 @@
'use strict'
const createParseBitmask = require('../../parse/products-bitmask')
const createFormatBitmask = require('../../format/products-bitmask')
const _createParseLine = require('../../parse/line')
const _parseLocation = require('../../parse/location')
const _createParseJourney = require('../../parse/journey')
@ -38,26 +35,6 @@ const parseLocation = (profile, l, lines) => {
return res
}
const createParseLine = (profile, operators) => {
const parseLine = _createParseLine(profile, operators)
const parseLineWithMode = (l) => {
const res = parseLine(l)
res.mode = res.product = null
if ('class' in res) {
const data = products.bitmasks[parseInt(res.class)]
if (data) {
res.mode = data.mode
res.product = data.product
}
}
return res
}
return parseLineWithMode
}
const createParseJourney = (profile, stations, lines, remarks) => {
const parseJourney = _createParseJourney(profile, stations, lines, remarks)
@ -100,43 +77,17 @@ const createParseJourney = (profile, stations, lines, remarks) => {
return parseJourneyWithTickets
}
const defaultProducts = {
nationalExp: true,
national: true,
interregional: true,
regional: true,
suburban: true,
bus: true,
ferry: true,
subway: true,
tram: true,
onCall: true
}
const formatBitmask = createFormatBitmask(products)
const formatProducts = (products) => {
products = Object.assign(Object.create(null), defaultProducts, products)
return {
type: 'PROD',
mode: 'INC',
value: formatBitmask(products) + ''
}
}
const nahshProfile = {
locale: 'de-DE',
timezone: 'Europe/Berlin',
endpoint: 'http://nah.sh.hafas.de/bin/mgate.exe',
transformReqBody,
products: products.allProducts,
products,
parseProducts: createParseBitmask(products.allProducts, defaultProducts),
parseLine: createParseLine,
parseLocation,
parseJourney: createParseJourney,
formatProducts,
journeyLeg: true,
radar: false // todo: see #34
}

View file

@ -1,101 +1,86 @@
'use strict'
const p = {
nationalExp: {
bitmask: 1,
const p = [
{
id: 'nationalExp',
mode: 'train',
bitmasks: [1],
name: 'High-speed rail',
short: 'ICE/HSR',
mode: 'train',
product: 'nationalExp'
default: true
},
national: {
bitmask: 2,
{
id: 'national',
mode: 'train',
bitmasks: [2],
name: 'InterCity & EuroCity',
short: 'IC/EC',
mode: 'train',
product: 'national'
default: true
},
interregional: { // todo: also includes EN?
bitmask: 4,
{ // todo: also includes EN?
id: 'interregional',
mode: 'train',
bitmasks: [4],
name: 'Interregional',
short: 'IR',
mode: 'train',
product: 'interregional'
default: true
},
regional: {
bitmask: 8,
{
id: 'regional',
mode: 'train',
bitmasks: [8],
name: 'Regional & RegionalExpress',
short: 'RB/RE',
mode: 'train',
product: 'regional'
default: true
},
suburban: {
bitmask: 16,
{
id: 'suburban',
mode: 'train',
bitmasks: [16],
name: 'S-Bahn',
short: 'S',
mode: 'train',
product: 'suburban'
default: true
},
bus: {
bitmask: 32,
{
id: 'bus',
mode: 'bus',
bitmasks: [32],
name: 'Bus',
short: 'B',
mode: 'bus',
product: 'bus'
default: true
},
ferry: {
bitmask: 64,
{
id: 'ferry',
mode: 'watercraft',
bitmasks: [64],
name: 'Ferry',
short: 'F',
mode: 'watercraft',
product: 'ferry'
default: true
},
subway: {
bitmask: 128,
{
id: 'subway',
mode: 'train',
bitmasks: [128],
name: 'U-Bahn',
short: 'U',
mode: 'train',
product: 'subway'
default: true
},
tram: {
bitmask: 256,
{
id: 'tram',
mode: 'train',
bitmasks: [256],
name: 'Tram',
short: 'T',
mode: 'train',
product: 'tram'
default: true
},
onCall: {
bitmask: 512,
{
id: 'onCall',
mode: null, // todo
bitmasks: [512],
name: 'On-call transit',
short: 'on-call',
mode: null, // todo
product: 'onCall'
default: true
}
}
p.bitmasks = []
p.bitmasks[1] = p.nationalExp
p.bitmasks[2] = p.national
p.bitmasks[4] = p.interregional
p.bitmasks[8] = p.regional
p.bitmasks[16] = p.suburban
p.bitmasks[32] = p.bus
p.bitmasks[64] = p.ferry
p.bitmasks[128] = p.subway
p.bitmasks[256] = p.tram
p.bitmasks[512] = p.onCall
p.allProducts = [
p.nationalExp,
p.national,
p.interregional,
p.regional,
p.suburban,
p.bus,
p.ferry,
p.subway,
p.tram,
p.onCall
]
module.exports = p