public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.
ISC License
263 stars 52 forks source link

journeys(): Add attribute `additional` for stopovers #303

Closed dabund24 closed 7 months ago

dabund24 commented 8 months ago

Just like it's implemented for cancelled stopovers, there could be an attribute for additional stopovers. I think an if-statement in parse/stopover.js that checks for the isAdd attribute to be set to true will do. Here is a screenshot from db navigator and the corresponding stopovers response from hafas (db profile):

image

{
  locX: 0,
  idx: 9,
  dProdX: 0,
  dPltfS: { type: 'PL', txt: '4' },
  dTimeS: '173100',
  dTimeR: '173100',
  dProgType: 'PROGNOSED',
  dDirTxt: 'München Hbf',
  dDirFlg: '1',
  dTZOffset: 60,
  type: 'N',
  location: {
    type: 'stop',
    id: '8000260',
    name: 'Würzburg Hbf',
    location: {
      type: 'location',
      id: '8000260',
      latitude: 49.802163,
      longitude: 9.93593
    },
    products: {
      nationalExpress: true,
      national: true,
      regionalExpress: true,
      regional: true,
      suburban: false,
      bus: true,
      ferry: false,
      subway: false,
      tram: true,
      taxi: false
    }
  }
}
{
  locX: 2,
  idx: 10,
  aProdX: 0,
  aPltfR: { type: 'PL', txt: '3' },
  aTimeS: '181000',
  aTimeR: '181000',
  aProgType: 'PROGNOSED',
  aTZOffset: 60,
  dProdX: 0,
  dPltfR: { type: 'PL', txt: '3' },
  dTimeS: '181200',
  dTimeR: '181200',
  dProgType: 'PROGNOSED',
  dTZOffset: 60,
  isAdd: true,
  msgL: [
    {
      type: 'REM',
      remX: 1,
      sty: 'I',
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    },
    {
      type: 'REM',
      remX: 0,
      sty: 'I',
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    }
  ],
  type: 'N',
  remarkRefs: [],
  location: {
    type: 'stop',
    id: '8000009',
    name: 'Ansbach',
    location: {
      type: 'location',
      id: '8000009',
      latitude: 49.29794,
      longitude: 10.577733
    },
    products: {
      nationalExpress: true,
      national: true,
      regionalExpress: true,
      regional: true,
      suburban: true,
      bus: true,
      ferry: false,
      subway: false,
      tram: false,
      taxi: true
    }
  }
}
{
  locX: 3,
  idx: 11,
  aProdX: 0,
  aTimeS: '182400',
  aCncl: true,
  aTZOffset: 60,
  dProdX: 0,
  dTimeS: '182700',
  dCncl: true,
  dTZOffset: 60,
  msgL: [
    {
      type: 'REM',
      remX: 2,
      sty: 'I',
      txtC: [Object],
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    }
  ],
  type: 'N',
  dCnclRtSrcX: 0,
  remarkRefs: [],
  location: {
    type: 'stop',
    id: '8000284',
    name: 'Nürnberg Hbf',
    location: {
      type: 'location',
      id: '8000284',
      latitude: 49.445435,
      longitude: 11.08227
    },
    products: {
      nationalExpress: true,
      national: true,
      regionalExpress: false,
      regional: true,
      suburban: true,
      bus: true,
      ferry: false,
      subway: true,
      tram: true,
      taxi: false
    }
  }
}
{
  locX: 4,
  idx: 12,
  aProdX: 0,
  aTimeS: '190000',
  aCncl: true,
  aTZOffset: 60,
  dProdX: 0,
  dTimeS: '190000',
  dCncl: true,
  dTZOffset: 60,
  msgL: [
    {
      type: 'REM',
      remX: 2,
      sty: 'I',
      txtC: [Object],
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    }
  ],
  type: 'N',
  aTimeSCh: true,
  dTimeSCh: true,
  aCnclRtSrcX: 0,
  remarkRefs: [],
  location: {
    type: 'stop',
    id: '8000183',
    name: 'Ingolstadt Hbf',
    location: {
      type: 'location',
      id: '8000183',
      latitude: 48.744538,
      longitude: 11.437335
    },
    products: {
      nationalExpress: true,
      national: false,
      regionalExpress: true,
      regional: true,
      suburban: false,
      bus: true,
      ferry: false,
      subway: false,
      tram: false,
      taxi: false
    }
  }
}
{
  locX: 5,
  idx: 13,
  aProdX: 0,
  aPltfR: { type: 'PL', txt: '4' },
  aTimeS: '190000',
  aTimeR: '190000',
  aProgType: 'PROGNOSED',
  aTZOffset: 60,
  dProdX: 0,
  dPltfR: { type: 'PL', txt: '4' },
  dTimeS: '190200',
  dTimeR: '190200',
  dProgType: 'PROGNOSED',
  dTZOffset: 60,
  isAdd: true,
  msgL: [
    {
      type: 'REM',
      remX: 1,
      sty: 'I',
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    },
    {
      type: 'REM',
      remX: 0,
      sty: 'I',
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    }
  ],
  type: 'N',
  remarkRefs: [],
  location: {
    type: 'stop',
    id: '8000078',
    name: 'Donauwörth',
    location: {
      type: 'location',
      id: '8000078',
      latitude: 48.714028,
      longitude: 10.771522
    },
    products: {
      nationalExpress: true,
      national: true,
      regionalExpress: false,
      regional: true,
      suburban: false,
      bus: true,
      ferry: false,
      subway: false,
      tram: false,
      taxi: true
    }
  }
}
{
  locX: 6,
  idx: 14,
  aProdX: 0,
  aPltfR: { type: 'PL', txt: '4' },
  aTimeS: '192000',
  aTimeR: '192000',
  aProgType: 'PROGNOSED',
  aTZOffset: 60,
  dProdX: 0,
  dPltfR: { type: 'PL', txt: '4' },
  dTimeS: '192100',
  dTimeR: '192100',
  dProgType: 'PROGNOSED',
  dTZOffset: 60,
  isAdd: true,
  msgL: [
    {
      type: 'REM',
      remX: 1,
      sty: 'I',
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    },
    {
      type: 'REM',
      remX: 0,
      sty: 'I',
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    }
  ],
  type: 'N',
  remarkRefs: [],
  location: {
    type: 'stop',
    id: '8000013',
    name: 'Augsburg Hbf',
    location: {
      type: 'location',
      id: '8000013',
      latitude: 48.365247,
      longitude: 10.885595
    },
    products: {
      nationalExpress: true,
      national: true,
      regionalExpress: true,
      regional: true,
      suburban: false,
      bus: true,
      ferry: false,
      subway: false,
      tram: true,
      taxi: false
    }
  }
}
{
  locX: 1,
  idx: 15,
  aProdX: 0,
  aPltfS: { type: 'PL', txt: '19' },
  aPltfR: { type: 'PL', txt: '15' },
  aPlatfCh: true,
  aTimeS: '194000',
  aTimeR: '194000',
  aProgType: 'PROGNOSED',
  aTZOffset: 60,
  msgL: [
    {
      type: 'REM',
      remX: 0,
      sty: 'I',
      prio: 478,
      fIdx: -1,
      tIdx: -1,
      tagL: [Array],
      sort: 818413568,
      hint: null
    }
  ],
  type: 'N',
  remarkRefs: [],
  location: {
    type: 'stop',
    id: '8000261',
    name: 'München Hbf',
    location: {
      type: 'location',
      id: '8000261',
      latitude: 48.140364,
      longitude: 11.558744
    },
    products: {
      nationalExpress: true,
      national: true,
      regionalExpress: true,
      regional: true,
      suburban: true,
      bus: true,
      ferry: false,
      subway: true,
      tram: true,
      taxi: false
    }
  }
}

I can create a pr if nothing speaks against implementing this :)

derhuerst commented 7 months ago

This is a good idea and falls nicely into the project's scope, thanks for proposing it!

When creating a PR, please make sure to include a parse test like the {a,d}TZOffset one. In order to obtain the required full HAFAS response ({a,d}TZOffset equivalent), run hafas-client with DEBUG=hafas-client, so that it will print the raw HAFAS responses (and requests, but you're not interested in copying them) to stderr. (You can use ./tools/debug-cli/cli.js db … to find a connection that corresponds to your screenshot.)

derhuerst commented 7 months ago

Fixed in #304, published as hafas-client@6.2.0. 🎉