From b7c1ee3b0589c455c3134d918dfffdb2de73aa53 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 16 Mar 2018 14:23:27 +0100 Subject: [PATCH] new products markup --- p/db/index.js | 10 ++-- p/db/modes.js | 108 ------------------------------------- p/db/products.js | 85 +++++++++++++++++++++++++++++ p/insa/products.js | 94 +++++++++++++------------------- p/oebb/products.js | 130 ++++++++++++++++++--------------------------- p/vbb/index.js | 10 ++-- p/vbb/modes.js | 112 -------------------------------------- p/vbb/products.js | 60 +++++++++++++++++++++ 8 files changed, 242 insertions(+), 367 deletions(-) delete mode 100644 p/db/modes.js create mode 100644 p/db/products.js delete mode 100644 p/vbb/modes.js create mode 100644 p/vbb/products.js diff --git a/p/db/index.js b/p/db/index.js index d8cc5e6f..2f6870c5 100644 --- a/p/db/index.js +++ b/p/db/index.js @@ -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, diff --git a/p/db/modes.js b/p/db/modes.js deleted file mode 100644 index dcca851f..00000000 --- a/p/db/modes.js +++ /dev/null @@ -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 diff --git a/p/db/products.js b/p/db/products.js new file mode 100644 index 00000000..d1e26771 --- /dev/null +++ b/p/db/products.js @@ -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 + } +] diff --git a/p/insa/products.js b/p/insa/products.js index d6b343e5..66bd63ec 100644 --- a/p/insa/products.js +++ b/p/insa/products.js @@ -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 diff --git a/p/oebb/products.js b/p/oebb/products.js index 646d4588..1c0fd223 100644 --- a/p/oebb/products.js +++ b/p/oebb/products.js @@ -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 diff --git a/p/vbb/index.js b/p/vbb/index.js index 3f9f9ecd..10b5e743 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -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, diff --git a/p/vbb/modes.js b/p/vbb/modes.js deleted file mode 100644 index 3e771793..00000000 --- a/p/vbb/modes.js +++ /dev/null @@ -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 diff --git a/p/vbb/products.js b/p/vbb/products.js new file mode 100644 index 00000000..678972ac --- /dev/null +++ b/p/vbb/products.js @@ -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 + } +]