mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 10:06:32 +02:00 
			
		
		
		
	parseLeg: use remarks without fIdx/tIdx 🐛
This commit is contained in:
		
							parent
							
								
									82de7409e8
								
							
						
					
					
						commit
						25fb25c18d
					
				
					 5 changed files with 353 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -13,9 +13,17 @@ const applyRemarks = (leg, refs) => {
 | 
			
		|||
	for (let [remark, ref] of findRemarks(refs)) {
 | 
			
		||||
		const {fromLocation, toLocation} = ref
 | 
			
		||||
 | 
			
		||||
		const fromI = fromLocation ? leg.stopovers.findIndex(s => s.stop === fromLocation) : -1
 | 
			
		||||
		const toI = toLocation ? leg.stopovers.findIndex(s => s.stop === toLocation) : -1
 | 
			
		||||
		if (fromI < 0 || toI < 0) continue
 | 
			
		||||
		let fromI = 0, toI = leg.stopovers.length - 1
 | 
			
		||||
		// this fails if `s.stop` is a new object (not reference-equal)
 | 
			
		||||
		// todo: do this index- or ID-based
 | 
			
		||||
		if (fromLocation) {
 | 
			
		||||
			fromI = leg.stopovers.findIndex(s => s.stop === fromLocation)
 | 
			
		||||
			if (fromI < 0) continue
 | 
			
		||||
		}
 | 
			
		||||
		if (toLocation) {
 | 
			
		||||
			toI = leg.stopovers.findIndex(s => s.stop === toLocation)
 | 
			
		||||
			if (toI < 0) continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		const wholeLeg = fromI === 0 && toI === (leg.stopovers.length - 1)
 | 
			
		||||
		if (wholeLeg) addRemark(leg, remark)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										105
									
								
								test/fixtures/rejseplanen-trip.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								test/fixtures/rejseplanen-trip.js
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,105 @@
 | 
			
		|||
'use strict'
 | 
			
		||||
 | 
			
		||||
const aalborg = {
 | 
			
		||||
	type: 'stop',
 | 
			
		||||
	id: '8600020',
 | 
			
		||||
	name: 'Aalborg St.',
 | 
			
		||||
	location: {
 | 
			
		||||
		type: 'location',
 | 
			
		||||
		id: '8600020',
 | 
			
		||||
		latitude: 57.043037,
 | 
			
		||||
		longitude: 9.917044
 | 
			
		||||
	},
 | 
			
		||||
	products: {
 | 
			
		||||
		'national-train': true,
 | 
			
		||||
		'national-train-2': true,
 | 
			
		||||
		'local-train': true,
 | 
			
		||||
		o: true,
 | 
			
		||||
		's-tog': false,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const hobro = {
 | 
			
		||||
	type: 'stop',
 | 
			
		||||
	id: '8600032',
 | 
			
		||||
	name: 'Hobro St.',
 | 
			
		||||
	location: {
 | 
			
		||||
		type: 'location',
 | 
			
		||||
		id: '8600032',
 | 
			
		||||
		latitude: 56.643539,
 | 
			
		||||
		longitude: 9.78279
 | 
			
		||||
	},
 | 
			
		||||
	products: {
 | 
			
		||||
		'national-train': true,
 | 
			
		||||
		'national-train-2': true,
 | 
			
		||||
		'local-train': true,
 | 
			
		||||
		o: true,
 | 
			
		||||
		's-tog': false,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
	origin: aalborg,
 | 
			
		||||
	destination: hobro,
 | 
			
		||||
	arrival: '2020-07-13T11:25:00+02:00',
 | 
			
		||||
	plannedArrival: '2020-07-13T11:25:00+02:00',
 | 
			
		||||
	arrivalDelay: null,
 | 
			
		||||
	departure: '2020-07-13T10:35:00+02:00',
 | 
			
		||||
	plannedDeparture: '2020-07-13T10:35:00+02:00',
 | 
			
		||||
	departureDelay: null,
 | 
			
		||||
	reachable: true,
 | 
			
		||||
	line: {
 | 
			
		||||
		type: 'line',
 | 
			
		||||
		id: 'replacement-bus-rod',
 | 
			
		||||
		fahrtNr: '20002',
 | 
			
		||||
		name: 'Replacement bus RØD',
 | 
			
		||||
		public: true,
 | 
			
		||||
		adminCode: '000001',
 | 
			
		||||
		mode: 'train',
 | 
			
		||||
		product: 'o',
 | 
			
		||||
		operator: {type: 'operator', id: 'dsb', name: 'DSB'},
 | 
			
		||||
	},
 | 
			
		||||
	direction: null,
 | 
			
		||||
	arrivalPlatform: null,
 | 
			
		||||
	plannedArrivalPlatform: null,
 | 
			
		||||
	departurePlatform: null,
 | 
			
		||||
	plannedDeparturePlatform: null,
 | 
			
		||||
	stopovers: [
 | 
			
		||||
		{
 | 
			
		||||
			stop: aalborg,
 | 
			
		||||
			arrival: null,
 | 
			
		||||
			plannedArrival: null,
 | 
			
		||||
			arrivalDelay: null,
 | 
			
		||||
			arrivalPlatform: null,
 | 
			
		||||
			plannedArrivalPlatform: null,
 | 
			
		||||
			departure: '2020-07-13T10:35:00+02:00',
 | 
			
		||||
			plannedDeparture: '2020-07-13T10:35:00+02:00',
 | 
			
		||||
			departureDelay: null,
 | 
			
		||||
			departurePlatform: null,
 | 
			
		||||
			plannedDeparturePlatform: null
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			stop: hobro,
 | 
			
		||||
			arrival: '2020-07-13T11:25:00+02:00',
 | 
			
		||||
			plannedArrival: '2020-07-13T11:25:00+02:00',
 | 
			
		||||
			arrivalDelay: null,
 | 
			
		||||
			arrivalPlatform: null,
 | 
			
		||||
			plannedArrivalPlatform: null,
 | 
			
		||||
			departure: null,
 | 
			
		||||
			plannedDeparture: null,
 | 
			
		||||
			departureDelay: null,
 | 
			
		||||
			departurePlatform: null,
 | 
			
		||||
			plannedDeparturePlatform: null
 | 
			
		||||
		}
 | 
			
		||||
	],
 | 
			
		||||
	remarks: [{
 | 
			
		||||
		type: 'hint',
 | 
			
		||||
		code: 'NO',
 | 
			
		||||
		text: 'Vi kører med Togbusser på denne tur, som derfor varer længere end normalt. Tiderne, du ser i Rejseplanen, er kun vejledende. Togbusserne kører i pendulfart mellem stationerne. Det skyldes akutte driftsforstyrrelser. I Togbussen kan du ikke tage din cykel med.',
 | 
			
		||||
	}, {
 | 
			
		||||
		type: 'status',
 | 
			
		||||
		code: 'text.realtime.journey.additional.service',
 | 
			
		||||
		text: 'Extra bus or train',
 | 
			
		||||
	}],
 | 
			
		||||
	id: '1|51255|0|86|13072020'
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										207
									
								
								test/fixtures/rejseplanen-trip.json
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										207
									
								
								test/fixtures/rejseplanen-trip.json
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,207 @@
 | 
			
		|||
{
 | 
			
		||||
	"common": {
 | 
			
		||||
		"locL": [
 | 
			
		||||
			{
 | 
			
		||||
				"lid": "A=1@O=Aalborg St.@X=9917044@Y=57043037@U=86@L=8600020@",
 | 
			
		||||
				"type": "S",
 | 
			
		||||
				"name": "Aalborg St.",
 | 
			
		||||
				"icoX": 2,
 | 
			
		||||
				"extId": "8600020",
 | 
			
		||||
				"state": "F",
 | 
			
		||||
				"crd": {
 | 
			
		||||
					"x": 9917044,
 | 
			
		||||
					"y": 57043037,
 | 
			
		||||
					"layerX": 0,
 | 
			
		||||
					"crdSysX": 0
 | 
			
		||||
				},
 | 
			
		||||
				"pCls": 239
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				"lid": "A=1@O=Hobro St.@X=9782790@Y=56643539@U=86@L=8600032@",
 | 
			
		||||
				"type": "S",
 | 
			
		||||
				"name": "Hobro St.",
 | 
			
		||||
				"icoX": 2,
 | 
			
		||||
				"extId": "8600032",
 | 
			
		||||
				"state": "F",
 | 
			
		||||
				"crd": {
 | 
			
		||||
					"x": 9782790,
 | 
			
		||||
					"y": 56643539,
 | 
			
		||||
					"layerX": 0,
 | 
			
		||||
					"crdSysX": 0
 | 
			
		||||
				},
 | 
			
		||||
				"pCls": 303
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"prodL": [
 | 
			
		||||
			{
 | 
			
		||||
				"name": "Replacement bus RØD",
 | 
			
		||||
				"nameS": "RØD",
 | 
			
		||||
				"number": "RØD",
 | 
			
		||||
				"icoX": 0,
 | 
			
		||||
				"cls": 8,
 | 
			
		||||
				"oprX": 0,
 | 
			
		||||
				"prodCtx": {
 | 
			
		||||
					"name": "Replacement bus RØD",
 | 
			
		||||
					"num": "20002",
 | 
			
		||||
					"line": "RØD",
 | 
			
		||||
					"matchId": "RØD",
 | 
			
		||||
					"catOut": "Togbus  ",
 | 
			
		||||
					"catOutS": "018",
 | 
			
		||||
					"catOutL": "Replacement bus",
 | 
			
		||||
					"catIn": "018",
 | 
			
		||||
					"catCode": "3",
 | 
			
		||||
					"admin": "000001"
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"polyL": [],
 | 
			
		||||
		"layerL": [
 | 
			
		||||
			{
 | 
			
		||||
				"id": "standard",
 | 
			
		||||
				"name": "standard",
 | 
			
		||||
				"index": 0,
 | 
			
		||||
				"annoCnt": 0
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"crdSysL": [
 | 
			
		||||
			{
 | 
			
		||||
				"id": "standard",
 | 
			
		||||
				"index": 0,
 | 
			
		||||
				"type": "WGS84"
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"opL": [
 | 
			
		||||
			{
 | 
			
		||||
				"name": "DSB",
 | 
			
		||||
				"icoX": 1
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"remL": [
 | 
			
		||||
			{
 | 
			
		||||
				"type": "I",
 | 
			
		||||
				"code": "NO",
 | 
			
		||||
				"icoX": 3,
 | 
			
		||||
				"txtN": "Vi kører med Togbusser på denne tur, som derfor varer længere end normalt. Tiderne, du ser i Rejseplanen, er kun vejledende. Togbusserne kører i pendulfart mellem stationerne. Det skyldes akutte driftsforstyrrelser. I Togbussen kan du ikke tage din cykel med."
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				"type": "R",
 | 
			
		||||
				"code": "text.realtime.journey.additional.service",
 | 
			
		||||
				"icoX": 4,
 | 
			
		||||
				"txtN": "Extra bus or train"
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"icoL": [
 | 
			
		||||
			{
 | 
			
		||||
				"res": "prod_gen",
 | 
			
		||||
				"fg": {
 | 
			
		||||
					"r": 255,
 | 
			
		||||
					"g": 255,
 | 
			
		||||
					"b": 255
 | 
			
		||||
				},
 | 
			
		||||
				"bg": {
 | 
			
		||||
					"r": 80,
 | 
			
		||||
					"g": 183,
 | 
			
		||||
					"b": 72
 | 
			
		||||
				}
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				"res": "DSB",
 | 
			
		||||
				"txt": "DSB"
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				"res": "prod_ic",
 | 
			
		||||
				"fg": {
 | 
			
		||||
					"r": 255,
 | 
			
		||||
					"g": 255,
 | 
			
		||||
					"b": 255
 | 
			
		||||
				},
 | 
			
		||||
				"bg": {
 | 
			
		||||
					"r": 239,
 | 
			
		||||
					"g": 65,
 | 
			
		||||
					"b": 48
 | 
			
		||||
				}
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				"res": "INFO"
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				"res": "rt_warn"
 | 
			
		||||
			}
 | 
			
		||||
		]
 | 
			
		||||
	},
 | 
			
		||||
	"journey": {
 | 
			
		||||
		"jid": "1|51255|0|86|13072020",
 | 
			
		||||
		"date": "20200713",
 | 
			
		||||
		"prodX": 0,
 | 
			
		||||
		"status": "A",
 | 
			
		||||
		"isRchbl": true,
 | 
			
		||||
		"stopL": [
 | 
			
		||||
			{
 | 
			
		||||
				"locX": 0,
 | 
			
		||||
				"idx": 0,
 | 
			
		||||
				"dProdX": 0,
 | 
			
		||||
				"dInR": true,
 | 
			
		||||
				"dTimeS": "103500",
 | 
			
		||||
				"dProgType": "PROGNOSED",
 | 
			
		||||
				"type": "N"
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				"locX": 1,
 | 
			
		||||
				"idx": 1,
 | 
			
		||||
				"aProdX": 0,
 | 
			
		||||
				"aOutR": true,
 | 
			
		||||
				"aTimeS": "112500",
 | 
			
		||||
				"aProgType": "PROGNOSED",
 | 
			
		||||
				"type": "N"
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"sDaysL": [
 | 
			
		||||
			{
 | 
			
		||||
				"sDaysR": "not every day",
 | 
			
		||||
				"sDaysI": "13. Jul",
 | 
			
		||||
				"sDaysB": "10000000000000000000",
 | 
			
		||||
				"fLocX": 0,
 | 
			
		||||
				"tLocX": 1,
 | 
			
		||||
				"fLocIdx": 0,
 | 
			
		||||
				"tLocIdx": 1
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"msgL": [
 | 
			
		||||
			{
 | 
			
		||||
				"type": "REM",
 | 
			
		||||
				"remX": 0,
 | 
			
		||||
				"dspl": "U",
 | 
			
		||||
				"fLocX": 0,
 | 
			
		||||
				"tLocX": 1,
 | 
			
		||||
				"tagL": [
 | 
			
		||||
					"RES_JNY_DTL"
 | 
			
		||||
				],
 | 
			
		||||
				"sort": 684195840,
 | 
			
		||||
				"persist": false
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				"type": "REM",
 | 
			
		||||
				"remX": 1,
 | 
			
		||||
				"dspl": "U",
 | 
			
		||||
				"tagL": [
 | 
			
		||||
					"RES_JNY_H3"
 | 
			
		||||
				],
 | 
			
		||||
				"sort": 13107200,
 | 
			
		||||
				"persist": false
 | 
			
		||||
			}
 | 
			
		||||
		],
 | 
			
		||||
		"subscr": "F",
 | 
			
		||||
		"prodL": [
 | 
			
		||||
			{
 | 
			
		||||
				"prodX": 0,
 | 
			
		||||
				"fLocX": 0,
 | 
			
		||||
				"tLocX": 1,
 | 
			
		||||
				"fIdx": 0,
 | 
			
		||||
				"tIdx": 1
 | 
			
		||||
			}
 | 
			
		||||
		]
 | 
			
		||||
	},
 | 
			
		||||
	"fpB": "20200710",
 | 
			
		||||
	"fpE": "20200923",
 | 
			
		||||
	"planrtTS": "1594478912"
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -12,6 +12,7 @@ require('./db-arrivals')
 | 
			
		|||
require('./vbb-departures')
 | 
			
		||||
require('./bvg-radar')
 | 
			
		||||
require('./oebb-trip')
 | 
			
		||||
require('./rejseplanen-trip')
 | 
			
		||||
require('./db-netz-remarks')
 | 
			
		||||
require('./vsn-departures')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										29
									
								
								test/rejseplanen-trip.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								test/rejseplanen-trip.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
'use strict'
 | 
			
		||||
 | 
			
		||||
const test = require('tape')
 | 
			
		||||
 | 
			
		||||
const createClient = require('..')
 | 
			
		||||
const rawProfile = require('../p/rejseplanen')
 | 
			
		||||
const res = require('./fixtures/rejseplanen-trip.json')
 | 
			
		||||
const expected = require('./fixtures/rejseplanen-trip.js')
 | 
			
		||||
 | 
			
		||||
const client = createClient(rawProfile, 'public-transport/hafas-client:test')
 | 
			
		||||
const {profile} = client
 | 
			
		||||
 | 
			
		||||
const opt = {
 | 
			
		||||
	stopovers: true,
 | 
			
		||||
	polyline: true,
 | 
			
		||||
	subStops: false,
 | 
			
		||||
	entrances: true,
 | 
			
		||||
	remarks: true,
 | 
			
		||||
	when: '2020-07-11T16:49:00+02:00',
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test('parses a trip correctly (Rejseplanen)', (t) => {
 | 
			
		||||
	const common = profile.parseCommon({profile, opt, res})
 | 
			
		||||
	const ctx = {profile, opt, common, res}
 | 
			
		||||
	const trip = profile.parseTrip(ctx, res.journey)
 | 
			
		||||
 | 
			
		||||
	t.deepEqual(trip, expected)
 | 
			
		||||
	t.end()
 | 
			
		||||
})
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue