public-transport / db-hafas

JavaScript client for the Deutsche Bahn HAFAS API.
https://github.com/public-transport/db-hafas
ISC License
75 stars 5 forks source link

Journey options not fully recognized #26

Closed gaudes closed 4 years ago

gaudes commented 4 years ago

Hello,

as discussed here:

https://forum.iobroker.net/topic/35169/test-adapter-fahrplan-v0-1-x-github-alpha-version/21

I have the following journey:

Provider: DB From: 8002334 To: 8000107 Options: {"results":3,"language":"de","remarks":true,"transfers":0,"products":{"suburban":true}}

So I should only get connections without transfer and products suburban.

But there appears one connection in the early morning (4:xx) with 1 change and product Bus frequently.

Thanks and regards,

Ralf

derhuerst commented 4 years ago

But there appears one connection in the early morning (4:xx) with 1 change and product Bus frequently.

Please give me a specific example to reproduce.

gaudes commented 4 years ago

Hi, the options mentioned in my first post is a specific example. Or do you need the JSON result ?

Thanks and regards,

Ralf

derhuerst commented 4 years ago

the options mentioned in my first post is a specific example.

Please provide an exact date & time, preferred to be 2 days in the future, and a train/line name.

Or do you need the JSON result ?

That would be even better, yes.

[...] in the early morning (4:xx) [...]

What does 4:xx mean?

gaudes commented 4 years ago

Here is the JSON return from HAFAS:

{"earlierRef":"2|OB|MT#11#328606#328606#328635#328635#0#0#5#328297#1#-2147482598#0#1#2|PDH#739ef3a2818c2b4937276bef9bee9e35|RD#27072020|RT#233726|US#1","laterRef":"2|OF|MT#11#328673#328673#328686#328686#0#0#165#328642#3#-2147482598#0#1#2|PDH#739ef3a2818c2b4937276bef9bee9e35|RD#27072020|RT#233726|US#1","journeys":[{"type":"journey","legs":[{"origin":{"type":"stop","id":"8002334","name":"Gottenheim","location":{"type":"location","id":"8002334","latitude":48.051658,"longitude":7.727748},"products":{"nationalExpress":false,"national":false,"regionalExp":false,"regional":true,"suburban":true,"bus":true,"ferry":false,"subway":false,"tram":false,"taxi":false}},"destination":{"type":"stop","id":"500042","name":"Salzgasse, Gottenheim","location":{"type":"location","id":"500042","latitude":48.05022,"longitude":7.727568},"products":{"nationalExpress":false,"national":false,"regionalExp":false,"regional":true,"suburban":false,"bus":true,"ferry":false,"subway":false,"tram":false,"taxi":false}},"arrival":"2020-07-28T04:52:00+02:00","plannedArrival":"2020-07-28T04:52:00+02:00","arrivalDelay":null,"departure":"2020-07-28T04:46:00+02:00","plannedDeparture":"2020-07-28T04:46:00+02:00","departureDelay":null,"public":true,"walking":true,"distance":471},{"origin":{"type":"stop","id":"500042","name":"Salzgasse, Gottenheim","location":{"type":"location","id":"500042","latitude":48.05022,"longitude":7.727568},"products":{"nationalExpress":false,"national":false,"regionalExp":false,"regional":true,"suburban":false,"bus":true,"ferry":false,"subway":false,"tram":false,"taxi":false}},"destination":{"type":"stop","id":"422410","name":"Hauptbahnhof ZOB, Freiburg im Breisgau","location":{"type":"location","id":"422410","latitude":47.996833,"longitude":7.841317},"products":{"nationalExpress":true,"national":true,"regionalExp":false,"regional":true,"suburban":true,"bus":true,"ferry":false,"subway":false,"tram":true,"taxi":false},"station":{"type":"station","id":"8000107","name":"Freiburg(Breisgau) Hbf","location":{"type":"location","id":"8000107","latitude":47.997974,"longitude":7.841344},"products":{"nationalExpress":true,"national":true,"regionalExp":false,"regional":true,"suburban":true,"bus":true,"ferry":false,"subway":false,"tram":true,"taxi":false}}},"arrival":"2020-07-28T05:15:00+02:00","plannedArrival":"2020-07-28T05:15:00+02:00","arrivalDelay":null,"departure":"2020-07-28T04:52:00+02:00","plannedDeparture":"2020-07-28T04:52:00+02:00","departureDelay":null,"reachable":true,"tripId":"1|607461|0|80|28072020","line":{"type":"line","id":"5-rbgsbg-7211","fahrtNr":"0","name":"Bus 7211","public":true,"adminCode":"rbgSBG","mode":"bus","product":"bus","operator":{"type":"operator","id":"sudbadenbus","name":"Südbadenbus"}},"direction":"Freiburg","arrivalPlatform":null,"plannedArrivalPlatform":null,"departurePlatform":null,"plannedDeparturePlatform":null}],"refreshToken":"¶HKI¶G@F$A=1@O=Gottenheim@L=8002334@a=128@$A=1@O=Salzgasse, Gottenheim@L=500042@a=128@$202007280446$202007280452$$$1$$$§T$A=1@O=Salzgasse, Gottenheim@L=500042@a=128@$A=1@O=Hauptbahnhof ZOB, Freiburg im Breisgau@L=422410@a=128@$202007280452$202007280515$Bus 7211$$1$$$¶GP¶ft@0@2000@120@0@100@1@1000@0@@@@@false@0@-1@$f@$f@$f@$f@$f@$§bt@0@2000@120@0@100@1@1000@0@@@@@false@0@-1@$f@$f@$f@$f@$f@$§tf@$f@$f@$f@$f@$f@$§","price":null},{"type":"journey","legs":[{"origin":{"type":"stop","id":"8002334","name":"Gottenheim","location":{"type":"location","id":"8002334","latitude":48.051658,"longitude":7.727748},"products":{"nationalExpress":false,"national":false,"regionalExp":false,"regional":true,"suburban":true,"bus":true,"ferry":false,"subway":false,"tram":false,"taxi":false}},"destination":{"type":"stop","id":"8000107","name":"Freiburg(Breisgau) Hbf","location":{"type":"location","id":"8000107","latitude":47.997974,"longitude":7.841344},"products":{"nationalExpress":true,"national":true,"regionalExp":false,"regional":true,"suburban":true,"bus":true,"ferry":false,"subway":false,"tram":true,"taxi":false}},"arrival":"2020-07-28T05:34:00+02:00","plannedArrival":"2020-07-28T05:34:00+02:00","arrivalDelay":null,"departure":"2020-07-28T05:21:00+02:00","plannedDeparture":"2020-07-28T05:21:00+02:00","departureDelay":null,"reachable":true,"tripId":"1|287559|0|80|28072020","line":{"type":"line","id":"4-8006c6-10","fahrtNr":"9851","name":"S 10","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Villingen(Schwarzw)","arrivalPlatform":"7","plannedArrivalPlatform":"7","departurePlatform":"2","plannedDeparturePlatform":"2","cycle":{"min":540,"max":2100,"nr":5},"alternatives":[{"tripId":"1|287517|0|80|28072020","line":{"type":"line","id":"4-8006c6-11","fahrtNr":"9801","name":"S 11","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Neustadt(Schwarzw)","when":"2020-07-28T05:53:00+02:00","plannedWhen":"2020-07-28T05:53:00+02:00","delay":null},{"tripId":"1|287563|0|80|28072020","line":{"type":"line","id":"4-8006c6-1","fahrtNr":"9853","name":"S 1","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Freiburg(Breisgau) Hbf","when":"2020-07-28T06:28:00+02:00","plannedWhen":"2020-07-28T06:28:00+02:00","delay":null},{"tripId":"1|287397|0|80|28072020","line":{"type":"line","id":"4-8006c6-1","fahrtNr":"9603","name":"S 1","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Seebrugg","when":"2020-07-28T06:57:00+02:00","plannedWhen":"2020-07-28T06:57:00+02:00","delay":null},{"tripId":"1|287539|0|80|28072020","line":{"type":"line","id":"4-8006c6-12","fahrtNr":"9833","name":"S 12","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Freiburg(Breisgau) Hbf","when":"2020-07-28T07:06:00+02:00","plannedWhen":"2020-07-28T07:06:00+02:00","delay":null},{"tripId":"1|287535|0|80|28072020","line":{"type":"line","id":"4-8006c6-1","fahrtNr":"9829","name":"S 1","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Freiburg(Breisgau) Hbf","when":"2020-07-28T07:32:00+02:00","plannedWhen":"2020-07-28T07:32:00+02:00","delay":null}]}],"refreshToken":"¶HKI¶T$A=1@O=Gottenheim@L=8002334@a=128@$A=1@O=Freiburg(Breisgau) Hbf@L=8000107@a=128@$202007280521$202007280534$S     10$$1$$$","cycle":{"min":540},"remarks":[],"price":null},{"type":"journey","legs":[{"origin":{"type":"stop","id":"8002334","name":"Gottenheim","location":{"type":"location","id":"8002334","latitude":48.051658,"longitude":7.727748},"products":{"nationalExpress":false,"national":false,"regionalExp":false,"regional":true,"suburban":true,"bus":true,"ferry":false,"subway":false,"tram":false,"taxi":false}},"destination":{"type":"stop","id":"8000107","name":"Freiburg(Breisgau) Hbf","location":{"type":"location","id":"8000107","latitude":47.997974,"longitude":7.841344},"products":{"nationalExpress":true,"national":true,"regionalExp":false,"regional":true,"suburban":true,"bus":true,"ferry":false,"subway":false,"tram":true,"taxi":false}},"arrival":"2020-07-28T06:06:00+02:00","plannedArrival":"2020-07-28T06:06:00+02:00","arrivalDelay":null,"departure":"2020-07-28T05:53:00+02:00","plannedDeparture":"2020-07-28T05:53:00+02:00","departureDelay":null,"reachable":true,"tripId":"1|287517|0|80|28072020","line":{"type":"line","id":"4-8006c6-11","fahrtNr":"9801","name":"S 11","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Neustadt(Schwarzw)","arrivalPlatform":"7","plannedArrivalPlatform":"7","departurePlatform":"2","plannedDeparturePlatform":"2","cycle":{"min":540,"max":2100,"nr":5},"alternatives":[{"tripId":"1|287563|0|80|28072020","line":{"type":"line","id":"4-8006c6-1","fahrtNr":"9853","name":"S 1","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Freiburg(Breisgau) Hbf","when":"2020-07-28T06:28:00+02:00","plannedWhen":"2020-07-28T06:28:00+02:00","delay":null},{"tripId":"1|287397|0|80|28072020","line":{"type":"line","id":"4-8006c6-1","fahrtNr":"9603","name":"S 1","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Seebrugg","when":"2020-07-28T06:57:00+02:00","plannedWhen":"2020-07-28T06:57:00+02:00","delay":null},{"tripId":"1|287539|0|80|28072020","line":{"type":"line","id":"4-8006c6-12","fahrtNr":"9833","name":"S 12","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Freiburg(Breisgau) Hbf","when":"2020-07-28T07:06:00+02:00","plannedWhen":"2020-07-28T07:06:00+02:00","delay":null},{"tripId":"1|287535|0|80|28072020","line":{"type":"line","id":"4-8006c6-1","fahrtNr":"9829","name":"S 1","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Freiburg(Breisgau) Hbf","when":"2020-07-28T07:32:00+02:00","plannedWhen":"2020-07-28T07:32:00+02:00","delay":null},{"tripId":"1|287402|0|80|28072020","line":{"type":"line","id":"4-8006c6-1","fahrtNr":"9605","name":"S 1","public":true,"adminCode":"8006C6","mode":"train","product":"suburban","operator":{"type":"operator","id":"db-regio-ag-baden-wurttemberg","name":"DB Regio AG Baden-Württemberg"}},"direction":"Seebrugg","when":"2020-07-28T08:01:00+02:00","plannedWhen":"2020-07-28T08:01:00+02:00","delay":null}]}],"refreshToken":"¶HKI¶T$A=1@O=Gottenheim@L=8002334@a=128@$A=1@O=Freiburg(Breisgau) Hbf@L=8000107@a=128@$202007280553$202007280606$S     11$$1$$$","cycle":{"min":540},"remarks":[],"price":null}],"realtimeDataFrom":1595885997}

As you see the first result at 04:46 departure is a bus connection, although I had specified in the options only suburban.

Thanks and regards,

Ralf

derhuerst commented 4 years ago

Please give me the code you're using to fetch this data.

I cannot confirm this behaviour:

const createClient = require('hafas-client')
const dbProfile = require('hafas-client/p/db')

const client = createClient(dbProfile, 'debugging')

client.journeys('8002334', '8000107', {
    departure: "2020-07-28T04:40+02:00",
    products: {bus: false},
    transfers: 0,
})
.then((data) => {
    for (const j of data.journeys) console.log(j.legs)
})
[
    {
        origin: {
            type: 'stop',
            id: '8002334',
            name: 'Gottenheim',
            location: [Object],
            products: [Object]
        },
        destination: {
            type: 'stop',
            id: '8000107',
            name: 'Freiburg(Breisgau) Hbf',
            location: [Object],
            products: [Object]
        },
        arrival: '2020-07-28T05:34:00+02:00',
        plannedArrival: '2020-07-28T05:34:00+02:00',
        arrivalDelay: null,
        departure: '2020-07-28T05:21:00+02:00',
        plannedDeparture: '2020-07-28T05:21:00+02:00',
        departureDelay: null,
        reachable: true,
        tripId: '1|287559|0|80|28072020',
        line: {
            type: 'line',
            id: '4-8006c6-10',
            fahrtNr: '9851',
            name: 'S 10',
            public: true,
            adminCode: '8006C6',
            mode: 'train',
            product: 'suburban',
            operator: [Object]
        },
        direction: 'Villingen(Schwarzw)',
        arrivalPlatform: '7',
        plannedArrivalPlatform: '7',
        departurePlatform: '2',
        plannedDeparturePlatform: '2',
        cycle: { min: 540, max: 2100, nr: 5 },
        alternatives: [ [Object], [Object], [Object], [Object], [Object] ]
    }
]
[
    {
        origin: {
            type: 'stop',
            id: '8002334',
            name: 'Gottenheim',
            location: [Object],
            products: [Object]
        },
        destination: {
            type: 'stop',
            id: '8000107',
            name: 'Freiburg(Breisgau) Hbf',
            location: [Object],
            products: [Object]
        },
        arrival: '2020-07-28T06:06:00+02:00',
        plannedArrival: '2020-07-28T06:06:00+02:00',
        arrivalDelay: null,
        departure: '2020-07-28T05:53:00+02:00',
        plannedDeparture: '2020-07-28T05:53:00+02:00',
        departureDelay: null,
        reachable: true,
        tripId: '1|287517|0|80|28072020',
        line: {
            type: 'line',
            id: '4-8006c6-11',
            fahrtNr: '9801',
            name: 'S 11',
            public: true,
            adminCode: '8006C6',
            mode: 'train',
            product: 'suburban',
            operator: [Object]
        },
        direction: 'Neustadt(Schwarzw)',
        arrivalPlatform: '7',
        plannedArrivalPlatform: '7',
        departurePlatform: '2',
        plannedDeparturePlatform: '2',
        cycle: { min: 540, max: 2100, nr: 5 },
        alternatives: [ [Object], [Object], [Object], [Object], [Object] ]
    }
]
[
    {
        origin: {
            type: 'stop',
            id: '8002334',
            name: 'Gottenheim',
            location: [Object],
            products: [Object]
        },
        destination: {
            type: 'stop',
            id: '8000107',
            name: 'Freiburg(Breisgau) Hbf',
            location: [Object],
            products: [Object]
        },
        arrival: '2020-07-28T06:41:00+02:00',
        plannedArrival: '2020-07-28T06:41:00+02:00',
        arrivalDelay: null,
        departure: '2020-07-28T06:28:00+02:00',
        plannedDeparture: '2020-07-28T06:28:00+02:00',
        departureDelay: null,
        reachable: true,
        tripId: '1|287563|0|80|28072020',
        line: {
            type: 'line',
            id: '4-8006c6-1',
            fahrtNr: '9853',
            name: 'S 1',
            public: true,
            adminCode: '8006C6',
            mode: 'train',
            product: 'suburban',
            operator: [Object]
        },
        direction: 'Freiburg(Breisgau) Hbf',
        arrivalPlatform: '6',
        plannedArrivalPlatform: '6',
        departurePlatform: '2',
        plannedDeparturePlatform: '2',
        cycle: { min: 540, max: 1860, nr: 5 },
        alternatives: [ [Object], [Object], [Object], [Object], [Object] ]
    }
]
gaudes commented 4 years ago

I'm using it with classes.

I have a class for RouteOptions (Parameter opt from client.journeys) which has a function for returning the value for opt:

returnRouteOptions(){
        try{ 
            let aRouteOptions = { results: this.results, language: this.language, remarks: this.remarks, departure: new Date() };
            if (this.via !== "") aRouteOptions["via"] = this.via;
            if (this.transfers >= 0) aRouteOptions["transfers"] = this.transfers;
            if (this.bycicles === true) aRouteOptions["bike"] = this.bycicles;
            if (this.products !== null) aRouteOptions["products"] = this.products;
            return aRouteOptions;
        } catch (e){
            throw new Error(`Exception in returnRouteOptions [${e}]`);
        }   
    }

Then I have a class with a function using the options:

aRouteResult = await hClient.journeys(this.StationFrom.id.toString(), this.StationTo.id.toString(), RouteOptions.returnRouteOptions());

For debugging purpose I have currently included:

console.log(JSON.stringify(RouteOptions.returnRouteOptions());

The result is:

{"results":3,"language":"de","remarks":true,"departure":"2020-07-28T20:03:56.039Z","transfers":0,"products":{"suburban":true}}
derhuerst commented 4 years ago

I'm using it with classes.

This doesn‘t make a difference as long as you call hafas-client coorectly (which you do).

For debugging purpose I have currently included:

console.log(JSON.stringify(RouteOptions.returnRouteOptions());

The result is:

{"results":3,"language":"de","remarks":true,"departure":"2020-07-28T20:03:56.039Z","transfers":0,"products":{"suburban":true}}

Note that you passed suburban: true (which is the default anyways), and I passed bus: false. products works like the toggles in the DB Navigator app: You have to disable all others to get results for only one product.

gaudes commented 4 years ago

Hi,

that was the information I missed:

products works like the toggles in the DB Navigator app: You have to disable all others to get results for only one product.

Thank you very much.