new products markup

This commit is contained in:
Jannis R 2018-03-16 14:23:27 +01:00
parent f96131423f
commit b7c1ee3b05
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
8 changed files with 242 additions and 367 deletions

View file

@ -7,10 +7,10 @@ const createParseBitmask = require('../../parse/products-bitmask')
const createFormatBitmask = require('../../format/products-bitmask')
const {bike} = require('../../format/filters')
const modes = require('./modes')
const products = require('./products')
const formatLoyaltyCard = require('./loyalty-cards').format
const formatBitmask = createFormatBitmask(modes)
const formatBitmask = createFormatBitmask(products)
const transformReqBody = (body) => {
body.client = {id: 'DB', v: '16040000', type: 'IPH', name: 'DB Navigator'}
@ -47,7 +47,7 @@ const createParseLine = (profile, operators) => {
res.mode = res.product = null
if ('class' in res) {
const data = modes.bitmasks[parseInt(res.class)]
const data = products.bitmasks[parseInt(res.class)]
if (data) {
res.mode = data.mode
res.product = data.product
@ -137,11 +137,11 @@ const dbProfile = {
transformReqBody,
transformJourneysQuery,
products: modes.allProducts,
products: products.allProducts,
// todo: parseLocation
parseLine: createParseLine,
parseProducts: createParseBitmask(modes.allProducts, defaultProducts),
parseProducts: createParseBitmask(products.allProducts, defaultProducts),
parseJourney: createParseJourney,
formatStation,

View file

@ -1,108 +0,0 @@
'use strict'
// todo: https://gist.github.com/anonymous/d3323a5d2d6e159ed42b12afd0380434#file-haf_products-properties-L1-L95
const m = {
nationalExp: {
bitmask: 1,
name: 'InterCityExpress',
short: 'ICE',
mode: 'train',
product: 'nationalExp'
},
national: {
bitmask: 2,
name: 'InterCity & EuroCity',
short: 'IC/EC',
mode: 'train',
product: 'national'
},
regionalExp: {
bitmask: 4,
name: 'RegionalExpress & InterRegio',
short: 'RE/IR',
mode: 'train',
product: 'regionalExp'
},
regional: {
bitmask: 8,
name: 'Regio',
short: 'RB',
mode: 'train',
product: 'regional'
},
suburban: {
bitmask: 16,
name: 'S-Bahn',
short: 'S',
mode: 'train',
product: 'suburban'
},
bus: {
bitmask: 32,
name: 'Bus',
short: 'B',
mode: 'bus',
product: 'bus'
},
ferry: {
bitmask: 64,
name: 'Ferry',
short: 'F',
mode: 'watercraft',
product: 'ferry'
},
subway: {
bitmask: 128,
name: 'U-Bahn',
short: 'U',
mode: 'train',
product: 'subway'
},
tram: {
bitmask: 256,
name: 'Tram',
short: 'T',
mode: 'tram',
product: 'tram'
},
taxi: {
bitmask: 512,
name: 'Group Taxi',
short: 'Taxi',
mode: 'taxi',
product: 'taxi'
},
unknown: {
bitmask: 0,
name: 'unknown',
short: '?',
product: 'unknown'
}
}
m.bitmasks = []
m.bitmasks[1] = m.nationalExp
m.bitmasks[2] = m.national
m.bitmasks[4] = m.regionalExp
m.bitmasks[8] = m.regional
m.bitmasks[16] = m.suburban
m.bitmasks[32] = m.bus
m.bitmasks[64] = m.ferry
m.bitmasks[128] = m.subway
m.bitmasks[256] = m.tram
m.bitmasks[512] = m.taxi
m.allProducts = [
m.nationalExp,
m.national,
m.regionalExp,
m.regional,
m.suburban,
m.bus,
m.ferry,
m.subway,
m.tram,
m.taxi
]
module.exports = m

85
p/db/products.js Normal file
View file

@ -0,0 +1,85 @@
'use strict'
// todo: https://gist.github.com/anonymous/d3323a5d2d6e159ed42b12afd0380434#file-haf_products-properties-L1-L95
module.exports = [
{
product: 'nationalExp',
mode: 'train',
bitmasks: [1],
name: 'InterCityExpress',
short: 'ICE',
default: true
},
{
product: 'national',
mode: 'train',
bitmasks: [2],
name: 'InterCity & EuroCity',
short: 'IC/EC',
default: true
},
{
product: 'regionalExp',
mode: 'train',
bitmasks: [4],
name: 'RegionalExpress & InterRegio',
short: 'RE/IR',
default: true
},
{
product: 'regional',
mode: 'train',
bitmasks: [8],
name: 'Regio',
short: 'RB',
default: true
},
{
product: 'suburban',
mode: 'train',
bitmasks: [16],
name: 'S-Bahn',
short: 'S',
default: true
},
{
product: 'bus',
mode: 'bus',
bitmasks: [32],
name: 'Bus',
short: 'B',
default: true
},
{
product: 'ferry',
mode: 'watercraft',
bitmasks: [64],
name: 'Ferry',
short: 'F',
default: true
},
{
product: 'subway',
mode: 'train',
bitmasks: [128],
name: 'U-Bahn',
short: 'U',
default: true
},
{
product: 'tram',
mode: 'tram',
bitmasks: [256],
name: 'Tram',
short: 'T',
default: true
},
{
product: 'taxi',
mode: 'taxi',
bitmasks: [512],
name: 'Group Taxi',
short: 'Taxi',
default: true
}
]

View file

@ -1,82 +1,60 @@
'use strict'
// TODO Jannis R.: DRY
const p = {
nationalExp: {
bitmask: 1,
module.exports = [
{
product: 'nationalExp',
mode: 'train',
bitmasks: [1],
name: 'InterCityExpress',
short: 'ICE',
mode: 'train',
product: 'nationalExp'
default: true
},
national: {
bitmask: 2,
{
product: 'national',
mode: 'train',
bitmasks: [2],
name: 'InterCity & EuroCity',
short: 'IC/EC',
mode: 'train',
product: 'national'
default: true
},
regional: {
bitmask: 8,
{
product: 'regional',
mode: 'train',
bitmasks: [8],
name: 'RegionalExpress & RegionalBahn',
short: 'RE/RB',
mode: 'train',
product: 'regional'
default: true
},
suburban: {
bitmask: 16,
{
product: 'suburban',
mode: 'train',
bitmasks: [16],
name: 'S-Bahn',
short: 'S',
mode: 'train',
product: 'suburban'
default: true
},
tram: {
bitmask: 32,
{
product: 'tram',
mode: 'train',
bitmasks: [32],
name: 'Tram',
short: 'T',
mode: 'train',
product: 'tram'
default: true
},
bus: {
bitmask: 64+128,
{
product: 'bus',
mode: 'bus',
bitmasks: [64, 128],
name: 'Bus',
short: 'B',
mode: 'bus',
product: 'bus'
default: true
},
tourismTrain: {
bitmask: 256,
{
product: 'tourismTrain',
mode: 'train',
bitmasks: [256],
name: 'Tourism Train',
short: 'TT',
mode: 'train',
product: 'tourismTrain'
},
unknown: {
bitmask: 0,
name: 'unknown',
short: '?',
product: 'unknown'
default: true
}
}
p.bitmasks = []
p.bitmasks[1] = p.nationalExp
p.bitmasks[2] = p.national
p.bitmasks[8] = p.regional
p.bitmasks[16] = p.suburban
p.bitmasks[32] = p.tram
p.bitmasks[64] = p.bus
p.bitmasks[128] = p.bus
p.bitmasks[256] = p.tourismTrain
p.allProducts = [
p.nationalExp,
p.national,
p.regional,
p.suburban,
p.tram,
p.bus,
p.tourismTrain
]
module.exports = p

View file

@ -1,112 +1,84 @@
'use strict'
const p = {
nationalExp: {
bitmask: 1,
module.exports = [
{
product: 'nationalExp',
mode: 'train',
bitmasks: [1],
name: 'InterCityExpress & RailJet',
short: 'ICE/RJ',
mode: 'train',
product: 'nationalExp'
default: true
},
national: {
bitmask: 2 + 4,
{
product: 'national',
mode: 'train',
bitmasks: [2, 4],
name: 'InterCity & EuroCity',
short: 'IC/EC',
mode: 'train',
product: 'national'
default: true
},
interregional: {
bitmask: 8 + 4096,
{
product: 'interregional',
mode: 'train',
bitmasks: [8, 4096],
name: 'Durchgangszug & EuroNight',
short: 'D/EN',
mode: 'train',
product: 'interregional'
default: true
},
regional: {
bitmask: 16,
{
product: 'regional',
mode: 'train',
bitmasks: [16],
name: 'Regional & RegionalExpress',
short: 'R/REX',
mode: 'train',
product: 'regional'
default: true
},
suburban: {
bitmask: 32,
{
product: 'suburban',
mode: 'train',
bitmasks: [32],
name: 'S-Bahn',
short: 'S',
mode: 'train',
product: 'suburban'
default: true
},
bus: {
bitmask: 64,
{
product: 'bus',
mode: 'bus',
bitmasks: [64],
name: 'Bus',
short: 'B',
mode: 'bus',
product: 'bus'
default: true
},
ferry: {
bitmask: 128,
{
product: 'ferry',
mode: 'watercraft',
bitmasks: [128],
name: 'Ferry',
short: 'F',
mode: 'watercraft',
product: 'ferry'
default: true
},
subway: {
bitmask: 256,
{
product: 'subway',
mode: 'train',
bitmasks: [256],
name: 'U-Bahn',
short: 'U',
mode: 'train',
product: 'subway'
default: true
},
tram: {
bitmask: 512,
{
product: 'tram',
mode: 'train',
bitmasks: [512],
name: 'Tram',
short: 'T',
mode: 'train',
product: 'tram'
default: true
},
onCall: {
bitmask: 2048,
{
product: 'onCall',
mode: null, // todo
bitmasks: [2048],
name: 'On-call transit',
short: 'on-call',
mode: null, // todo
product: 'onCall'
},
unknown: {
bitmask: 0,
name: 'unknown',
short: '?',
product: 'unknown'
default: true
}
}
p.bitmasks = []
p.bitmasks[1] = p.nationalExp
p.bitmasks[2] = p.national
p.bitmasks[4] = p.national
p.bitmasks[2+4] = p.national
p.bitmasks[8] = p.interregional
p.bitmasks[16] = p.regional
p.bitmasks[32] = p.suburban
p.bitmasks[64] = p.bus
p.bitmasks[128] = p.ferry
p.bitmasks[256] = p.subway
p.bitmasks[512] = p.tram
p.bitmasks[1024] = p.unknown
p.bitmasks[2048] = p.onCall
p.bitmasks[4096] = p.interregional
p.bitmasks[8+4096] = p.interregional
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

View file

@ -15,9 +15,9 @@ const _formatStation = require('../../format/station')
const createParseBitmask = require('../../parse/products-bitmask')
const createFormatBitmask = require('../../format/products-bitmask')
const modes = require('./modes')
const products = require('./products')
const formatBitmask = createFormatBitmask(modes)
const formatBitmask = createFormatBitmask(products)
const transformReqBody = (body) => {
body.client = {type: 'IPA', id: 'VBB', name: 'vbbPROD', v: '4010300'}
@ -36,7 +36,7 @@ const createParseLine = (profile, operators) => {
res.mode = res.product = null
if ('class' in res) {
const data = modes.bitmasks[parseInt(res.class)]
const data = products.bitmasks[parseInt(res.class)]
if (data) {
res.mode = data.mode
res.product = data.product
@ -176,12 +176,12 @@ const vbbProfile = {
transformReqBody,
products: modes.allProducts,
products: products.allProducts,
parseStationName: shorten,
parseLocation,
parseLine: createParseLine,
parseProducts: createParseBitmask(modes.allProducts, defaultProducts),
parseProducts: createParseBitmask(products.allProducts, defaultProducts),
parseJourney: createParseJourney,
parseDeparture: createParseDeparture,
parseStopover: createParseStopover,

View file

@ -1,112 +0,0 @@
'use strict'
// todo: remove useless keys
const m = {
suburban: {
category: 0,
bitmask: 1,
name: 'S-Bahn',
mode: 'train',
short: 'S',
product: 'suburban'
},
subway: {
category: 1,
bitmask: 2,
name: 'U-Bahn',
mode: 'train',
short: 'U',
product: 'subway'
},
tram: {
category: 2,
bitmask: 4,
name: 'Tram',
mode: 'train',
short: 'T',
product: 'tram'
},
bus: {
category: 3,
bitmask: 8,
name: 'Bus',
mode: 'bus',
short: 'B',
product: 'bus'
},
ferry: {
category: 4,
bitmask: 16,
name: 'Fähre',
mode: 'watercraft',
short: 'F',
product: 'ferry'
},
express: {
category: 5,
bitmask: 32,
name: 'IC/ICE',
mode: 'train',
short: 'E',
product: 'express'
},
regional: {
category: 6,
bitmask: 64,
name: 'RB/RE',
mode: 'train',
short: 'R',
product: 'regional'
},
unknown: {
category: null,
bitmask: 0,
name: 'unknown',
mode: null,
short: '?',
product: 'unknown'
}
}
m.bitmasks = []
m.bitmasks[1] = m.suburban
m.bitmasks[2] = m.subway
m.bitmasks[4] = m.tram
m.bitmasks[8] = m.bus
m.bitmasks[16] = m.ferry
m.bitmasks[32] = m.express
m.bitmasks[64] = m.regional
m.categories = [
m.suburban,
m.subway,
m.tram,
m.bus,
m.ferry,
m.express,
m.regional,
m.unknown
]
m.allProducts = [
m.suburban,
m.subway,
m.tram,
m.bus,
m.ferry,
m.express,
m.regional
]
// m.parseCategory = (category) => {
// return m.categories[parseInt(category)] || m.unknown
// }
module.exports = m

60
p/vbb/products.js Normal file
View file

@ -0,0 +1,60 @@
'use strict'
module.exports = [
{
product: 'suburban',
mode: 'train',
bitmasks: [1],
name: 'S-Bahn',
short: 'S',
default: true
},
{
product: 'subway',
mode: 'train',
bitmasks: [2],
name: 'U-Bahn',
short: 'U',
default: true
},
{
product: 'tram',
mode: 'train',
bitmasks: [4],
name: 'Tram',
short: 'T',
default: true
},
{
product: 'bus',
mode: 'bus',
bitmasks: [8],
name: 'Bus',
short: 'B',
default: true
},
{
product: 'ferry',
mode: 'watercraft',
bitmasks: [16],
name: 'Fähre',
short: 'F',
default: true
},
{
product: 'express',
mode: 'train',
bitmasks: [32],
name: 'IC/ICE',
short: 'E',
default: true
},
{
product: 'regional',
mode: 'train',
bitmasks: [64],
name: 'RB/RE',
short: 'R',
default: true
}
]