products[].product -> products[].id

This commit is contained in:
Jannis R 2018-03-16 17:06:32 +01:00
parent bbb68d86d5
commit 94bbe2361b
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
11 changed files with 48 additions and 48 deletions

View file

@ -7,8 +7,8 @@ const createFormatProductsFilter = (profile) => {
const byProduct = {} const byProduct = {}
const defaultProducts = {} const defaultProducts = {}
for (let product of profile.products) { for (let product of profile.products) {
byProduct[product.product] = product byProduct[product.id] = product
defaultProducts[product.product] = product.default defaultProducts[product.id] = product.default
} }
const formatProductsFilter = (filter) => { const formatProductsFilter = (filter) => {

View file

@ -53,18 +53,18 @@ const validateProfile = (profile) => {
} }
if (profile.products.length === 0) throw new Error('profile.products is empty.') if (profile.products.length === 0) throw new Error('profile.products is empty.')
for (let product of profile.products) { for (let product of profile.products) {
if ('string' !== typeof product.product) { if ('string' !== typeof product.id) {
throw new Error('profile.products[].product must be a string.') throw new Error('profile.products[].id must be a string.')
} }
if ('boolean' !== typeof product.default) { if ('boolean' !== typeof product.default) {
throw new Error('profile.products[].default must be a boolean.') throw new Error('profile.products[].default must be a boolean.')
} }
if (!Array.isArray(product.bitmasks)) { if (!Array.isArray(product.bitmasks)) {
throw new Error(product.product + '.bitmasks must be an array.') throw new Error(product.id + '.bitmasks must be an array.')
} }
for (let bitmask of product.bitmasks) { for (let bitmask of product.bitmasks) {
if ('number' !== typeof bitmask) { if ('number' !== typeof bitmask) {
throw new Error(product.product + '.bitmasks[] must be a number.') throw new Error(product.id + '.bitmasks[] must be a number.')
} }
} }
} }

View file

@ -3,7 +3,7 @@
// todo: https://gist.github.com/anonymous/d3323a5d2d6e159ed42b12afd0380434#file-haf_products-properties-L1-L95 // todo: https://gist.github.com/anonymous/d3323a5d2d6e159ed42b12afd0380434#file-haf_products-properties-L1-L95
module.exports = [ module.exports = [
{ {
product: 'nationalExp', id: 'nationalExp',
mode: 'train', mode: 'train',
bitmasks: [1], bitmasks: [1],
name: 'InterCityExpress', name: 'InterCityExpress',
@ -11,7 +11,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'national', id: 'national',
mode: 'train', mode: 'train',
bitmasks: [2], bitmasks: [2],
name: 'InterCity & EuroCity', name: 'InterCity & EuroCity',
@ -19,7 +19,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'regionalExp', id: 'regionalExp',
mode: 'train', mode: 'train',
bitmasks: [4], bitmasks: [4],
name: 'RegionalExpress & InterRegio', name: 'RegionalExpress & InterRegio',
@ -27,7 +27,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'regional', id: 'regional',
mode: 'train', mode: 'train',
bitmasks: [8], bitmasks: [8],
name: 'Regio', name: 'Regio',
@ -35,7 +35,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'suburban', id: 'suburban',
mode: 'train', mode: 'train',
bitmasks: [16], bitmasks: [16],
name: 'S-Bahn', name: 'S-Bahn',
@ -43,7 +43,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'bus', id: 'bus',
mode: 'bus', mode: 'bus',
bitmasks: [32], bitmasks: [32],
name: 'Bus', name: 'Bus',
@ -51,7 +51,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'ferry', id: 'ferry',
mode: 'watercraft', mode: 'watercraft',
bitmasks: [64], bitmasks: [64],
name: 'Ferry', name: 'Ferry',
@ -59,7 +59,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'subway', id: 'subway',
mode: 'train', mode: 'train',
bitmasks: [128], bitmasks: [128],
name: 'U-Bahn', name: 'U-Bahn',
@ -67,7 +67,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'tram', id: 'tram',
mode: 'tram', mode: 'tram',
bitmasks: [256], bitmasks: [256],
name: 'Tram', name: 'Tram',
@ -75,7 +75,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'taxi', id: 'taxi',
mode: 'taxi', mode: 'taxi',
bitmasks: [512], bitmasks: [512],
name: 'Group Taxi', name: 'Group Taxi',

View file

@ -2,7 +2,7 @@
module.exports = [ module.exports = [
{ {
product: 'nationalExp', id: 'nationalExp',
mode: 'train', mode: 'train',
bitmasks: [1], bitmasks: [1],
name: 'InterCityExpress', name: 'InterCityExpress',
@ -10,7 +10,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'national', id: 'national',
mode: 'train', mode: 'train',
bitmasks: [2], bitmasks: [2],
name: 'InterCity & EuroCity', name: 'InterCity & EuroCity',
@ -18,7 +18,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'regional', id: 'regional',
mode: 'train', mode: 'train',
bitmasks: [8], bitmasks: [8],
name: 'RegionalExpress & RegionalBahn', name: 'RegionalExpress & RegionalBahn',
@ -26,7 +26,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'suburban', id: 'suburban',
mode: 'train', mode: 'train',
bitmasks: [16], bitmasks: [16],
name: 'S-Bahn', name: 'S-Bahn',
@ -34,7 +34,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'tram', id: 'tram',
mode: 'train', mode: 'train',
bitmasks: [32], bitmasks: [32],
name: 'Tram', name: 'Tram',
@ -42,7 +42,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'bus', id: 'bus',
mode: 'bus', mode: 'bus',
bitmasks: [64, 128], bitmasks: [64, 128],
name: 'Bus', name: 'Bus',
@ -50,7 +50,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'tourismTrain', id: 'tourismTrain',
mode: 'train', mode: 'train',
bitmasks: [256], bitmasks: [256],
name: 'Tourism Train', name: 'Tourism Train',

View file

@ -2,7 +2,7 @@
module.exports = [ module.exports = [
{ {
product: 'nationalExp', id: 'nationalExp',
mode: 'train', mode: 'train',
bitmasks: [1], bitmasks: [1],
name: 'InterCityExpress & RailJet', name: 'InterCityExpress & RailJet',
@ -10,7 +10,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'national', id: 'national',
mode: 'train', mode: 'train',
bitmasks: [2, 4], bitmasks: [2, 4],
name: 'InterCity & EuroCity', name: 'InterCity & EuroCity',
@ -18,7 +18,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'interregional', id: 'interregional',
mode: 'train', mode: 'train',
bitmasks: [8, 4096], bitmasks: [8, 4096],
name: 'Durchgangszug & EuroNight', name: 'Durchgangszug & EuroNight',
@ -26,7 +26,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'regional', id: 'regional',
mode: 'train', mode: 'train',
bitmasks: [16], bitmasks: [16],
name: 'Regional & RegionalExpress', name: 'Regional & RegionalExpress',
@ -34,7 +34,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'suburban', id: 'suburban',
mode: 'train', mode: 'train',
bitmasks: [32], bitmasks: [32],
name: 'S-Bahn', name: 'S-Bahn',
@ -42,7 +42,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'bus', id: 'bus',
mode: 'bus', mode: 'bus',
bitmasks: [64], bitmasks: [64],
name: 'Bus', name: 'Bus',
@ -50,7 +50,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'ferry', id: 'ferry',
mode: 'watercraft', mode: 'watercraft',
bitmasks: [128], bitmasks: [128],
name: 'Ferry', name: 'Ferry',
@ -58,7 +58,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'subway', id: 'subway',
mode: 'train', mode: 'train',
bitmasks: [256], bitmasks: [256],
name: 'U-Bahn', name: 'U-Bahn',
@ -66,7 +66,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'tram', id: 'tram',
mode: 'train', mode: 'train',
bitmasks: [512], bitmasks: [512],
name: 'Tram', name: 'Tram',
@ -74,7 +74,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'onCall', id: 'onCall',
mode: null, // todo mode: null, // todo
bitmasks: [2048], bitmasks: [2048],
name: 'On-call transit', name: 'On-call transit',

View file

@ -2,7 +2,7 @@
module.exports = [ module.exports = [
{ {
product: 'suburban', id: 'suburban',
mode: 'train', mode: 'train',
bitmasks: [1], bitmasks: [1],
name: 'S-Bahn', name: 'S-Bahn',
@ -10,7 +10,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'subway', id: 'subway',
mode: 'train', mode: 'train',
bitmasks: [2], bitmasks: [2],
name: 'U-Bahn', name: 'U-Bahn',
@ -18,7 +18,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'tram', id: 'tram',
mode: 'train', mode: 'train',
bitmasks: [4], bitmasks: [4],
name: 'Tram', name: 'Tram',
@ -26,7 +26,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'bus', id: 'bus',
mode: 'bus', mode: 'bus',
bitmasks: [8], bitmasks: [8],
name: 'Bus', name: 'Bus',
@ -34,7 +34,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'ferry', id: 'ferry',
mode: 'watercraft', mode: 'watercraft',
bitmasks: [16], bitmasks: [16],
name: 'Fähre', name: 'Fähre',
@ -42,7 +42,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'express', id: 'express',
mode: 'train', mode: 'train',
bitmasks: [32], bitmasks: [32],
name: 'IC/ICE', name: 'IC/ICE',
@ -50,7 +50,7 @@ module.exports = [
default: true default: true
}, },
{ {
product: 'regional', id: 'regional',
mode: 'train', mode: 'train',
bitmasks: [64], bitmasks: [64],
name: 'RB/RE', name: 'RB/RE',

View file

@ -33,9 +33,9 @@ const createParseLine = (profile, operators) => {
if ('class' in res) { if ('class' in res) {
// todo: what if `res.class` is the sum of two bitmasks? // todo: what if `res.class` is the sum of two bitmasks?
const data = byBitmask[parseInt(res.class)] const product = byBitmask[parseInt(res.class)]
res.mode = data && data.mode || null res.mode = product && product.mode || null
res.product = data && data.product || null res.product = product && product.id || null
} }
if ('number' === typeof p.oprX) { if ('number' === typeof p.oprX) {

View file

@ -4,7 +4,7 @@ const createParseBitmask = (profile) => {
const defaultProducts = {} const defaultProducts = {}
let withBitmask = [] let withBitmask = []
for (let product of profile.products) { for (let product of profile.products) {
defaultProducts[product.product] = false defaultProducts[product.id] = false
for (let bitmask of product.bitmasks) { for (let bitmask of product.bitmasks) {
withBitmask.push([bitmask, product]) withBitmask.push([bitmask, product])
} }
@ -16,7 +16,7 @@ const createParseBitmask = (profile) => {
for (let [pBitmask, product] of withBitmask) { for (let [pBitmask, product] of withBitmask) {
if ((pBitmask & bitmask) > 0) { if ((pBitmask & bitmask) > 0) {
res[product.product] = true res[product.id] = true
bitmask -= pBitmask bitmask -= pBitmask
} }
} }

View file

@ -73,7 +73,7 @@ const assertIsJungfernheide = (t, s) => {
// todo: DRY with other tests // todo: DRY with other tests
const assertValidProducts = (t, p) => { const assertValidProducts = (t, p) => {
for (let product of allProducts) { for (let product of allProducts) {
product = product.product // wat product = product.id
t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean') t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean')
} }
} }

View file

@ -58,7 +58,7 @@ const assertIsMagdeburgHbf = (t, s) => {
// todo: DRY with other tests // todo: DRY with other tests
const assertValidProducts = (t, p) => { const assertValidProducts = (t, p) => {
for (let product of allProducts) { for (let product of allProducts) {
product = product.product // wat product = product.id
t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean') t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean')
} }
} }

View file

@ -77,7 +77,7 @@ const assertIsSalzburgHbf = (t, s) => {
// todo: DRY with other tests // todo: DRY with other tests
const assertValidProducts = (t, p) => { const assertValidProducts = (t, p) => {
for (let product of allProducts) { for (let product of allProducts) {
product = product.product // wat product = product.id
t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean') t.equal(typeof p[product], 'boolean', 'product ' + p + ' must be a boolean')
} }
} }