Skip to content

Commit 8b708b2

Browse files
committed
WIP
1 parent b863a9d commit 8b708b2

11 files changed

+5413
-35
lines changed

parse-rest/line.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ const parseLine = (ctx, p) => { // p = line
1717
// todo: what is p.catCode?
1818

1919
// todo: ICEs seem to have a catCode of 0
20-
const catCode = parseInt(p.catCode)
21-
if (!Number.isNaN(catCode)) {
22-
const product = profile.products.find(p => p.bitmasks.includes(catCode))
20+
const cls = parseInt(p.cls)
21+
if (!Number.isNaN(cls)) {
22+
const product = profile.products.find(p => p.bitmasks.includes(cls))
2323
res.mode = product && product.mode || null
2424
res.product = product && product.id || null
2525
}
2626

27-
if (p.operator) res.operator = p.operator
27+
if (p.operator) {
28+
res.operator = {
29+
type: 'operator',
30+
id: slugg(p.operator.trim()),
31+
name: p.operator.trim()
32+
}
33+
}
2834

2935
return res
3036
}

parse/journey-leg.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
const parseWhen = require('./when')
4-
const parsePlatform = require('./platform')
53
const findRemarks = require('./find-remarks')
64

75
const clone = obj => Object.assign({}, obj)

parse/location.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@ const ADDRESS = 'A'
88

99
const leadingZeros = /^0+/
1010

11+
const parseNr = nr => parseFloat(nr.slice(0, 2) + '.' + nr.slice(2))
12+
1113
// todo: what is s.rRefL?
1214
const parseLocation = (ctx, l) => {
1315
const {profile, opt} = ctx
1416

1517
const lid = parse(l.lid, {delimiter: '@'})
1618
const res = {
1719
type: 'location',
18-
id: (l.extId || lid.L || lid.b || '').replace(leadingZeros, '') || null
19-
}
20-
21-
if (l.crd) {
22-
res.latitude = l.crd.y / 1000000
23-
res.longitude = l.crd.x / 1000000
20+
id: (l.extId || lid.L || lid.b || '').replace(leadingZeros, '') || null,
21+
22+
latitude: (
23+
l.crd && 'number' === typeof l.crd.y
24+
? parseNr(l.crd.y + '')
25+
: (lid.Y ? parseNr(lid.Y) : null)
26+
),
27+
longitude: (
28+
l.crd && 'number' === typeof l.crd.x
29+
? parseNr(l.crd.x + '')
30+
: (lid.X ? parseNr(lid.X) : null)
31+
),
2432
}
2533

2634
if (l.type === STATION) {

parse/stopover.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
const parseWhen = require('./when')
4-
const parsePlatform = require('./platform')
53
const findRemarks = require('./find-remarks')
64

75
const parseStopover = (ctx, st, date) => { // st = raw stopover

rest-exe-example.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ const berlinYorckstrS1 = '8089051'
2626
const frankfurtHbf = '8000105'
2727
const somewhereInBerlin = {type: 'location', address: 'foo', latitude: 52.51072, longitude: 13.37793}
2828

29-
// journeys('8000150', berlinOstkreuz, {
30-
// results: 3,
31-
// stopovers: true,
32-
// remarks: true
33-
// })
29+
journeys('8000150', berlinOstkreuz, {
30+
results: 3,
31+
stopovers: true,
32+
remarks: true
33+
})
3434
// .then(journeys => journeys.flatMap(j => [...j.legs, '---']))
3535
// .then(([journey]) => journey.legs.map(l => l.tripId).find(tripId => !!tripId))
3636
// .then(trip)

0 commit comments

Comments
 (0)