hk-bus-eta 1.7.2 → 1.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Ctb.js CHANGED
@@ -2,20 +2,28 @@ const utils = require('./utils');
2
2
 
3
3
  module.exports = {
4
4
  co: 'ctb',
5
- fetchEtas: ({stopId, route, bound }) => (
5
+ fetchEtas: ({stopId, route, bound, seq }) => (
6
6
  fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/CTB/${stopId}/${route}`, {
7
7
  cache: utils.isSafari ? 'default' : 'no-store'
8
8
  }).then(
9
9
  response => response.json()
10
- ).then(({data}) => data.filter(eta => eta.eta && eta.dir === bound).map(e => ({
11
- eta: e.eta,
12
- remark: {
13
- zh: e.rmk_tc,
14
- en: e.rmk_en
15
- },
16
- co: 'ctb'
17
- }))
18
- )
10
+ ).then(({data}) => (
11
+ data
12
+ .filter(eta => eta.eta && eta.dir === bound)
13
+ // filter the eta by the stop sequence information
14
+ // as the route data may not 100% match
15
+ // use the nearest seq
16
+ .sort((a,b) => Math.abs(a.seq - seq) < Math.abs(b.seq - seq) ? -1 : 1 )
17
+ .filter((eta, idx, self) => eta.seq === self[0].seq)
18
+ .map(e => ({
19
+ eta: e.eta,
20
+ remark: {
21
+ zh: e.rmk_tc,
22
+ en: e.rmk_en
23
+ },
24
+ co: 'ctb'
25
+ }))
26
+ ))
19
27
  ),
20
28
  fetchStopEtas: ( stopId ) => (
21
29
  fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/CTB/${stopId}`, {
package/Kmb.js CHANGED
@@ -5,11 +5,15 @@ module.exports = {
5
5
  fetchEtas: ({stopId, route, seq, serviceType, bound}) => (
6
6
  fetch(`https://data.etabus.gov.hk/v1/transport/kmb/eta/${stopId}/${route}/${serviceType}`,{
7
7
  cache: utils.isSafari ? 'default' : 'no-store'
8
- }).then( response => response.json() )
9
- .then(({data}) => data.filter(e =>
10
- e.dir === bound
11
- && e.seq === seq + 1 // api return 1-based seq
12
- ).map(e => ({
8
+ })
9
+ .then( response => response.json() )
10
+ .then(({data}) => (
11
+ data.filter(e =>
12
+ e.eta !== null
13
+ && e.dir === bound
14
+ && e.seq === seq + 1 // api return 1-based seq
15
+ )
16
+ .map(e => ({
13
17
  eta: e.eta,
14
18
  remark: {
15
19
  zh: e.rmk_tc,
@@ -17,7 +21,7 @@ module.exports = {
17
21
  },
18
22
  co: 'kmb'
19
23
  }))
20
- )
24
+ ))
21
25
  ),
22
26
  fetchStopEtas: ( stopId ) => (
23
27
  fetch(`https://data.etabus.gov.hk/v1/transport/kmb/stop-eta/${stopId}`, {
package/LightRail.js CHANGED
@@ -12,7 +12,7 @@ module.exports = {
12
12
  .reduce((acc, {route_list, platform_id}) => [
13
13
  ...acc,
14
14
  ...route_list
15
- .filter(({route_no, dest_ch, stop}) => route === route_no && dest_ch === dest.zh && stop === 0)
15
+ .filter(({route_no, dest_ch, stop}) => route === route_no && dest_ch.startsWith(dest.zh) && stop === 0)
16
16
  .map( ({time_en}) => {
17
17
  let waitTime = 0
18
18
  switch ( time_en.toLowerCase() ) {
package/Nwfb.js CHANGED
@@ -2,20 +2,28 @@ const utils = require('./utils');
2
2
 
3
3
  module.exports = {
4
4
  co: 'nwfb',
5
- fetchEtas: ({stopId, route, bound }) => (
5
+ fetchEtas: ({stopId, route, bound, seq }) => (
6
6
  fetch(`https://rt.data.gov.hk//v1/transport/citybus-nwfb/eta/NWFB/${stopId}/${route}`, {
7
7
  cache: utils.isSafari ? 'default' : 'no-store'
8
8
  }).then(
9
9
  response => response.json()
10
- ).then(({data}) => data.filter(eta => eta.eta && eta.dir === bound).map(e => ({
11
- eta: e.eta,
12
- remark: {
13
- zh: e.rmk_tc,
14
- en: e.rmk_en
15
- },
16
- co: 'nwfb'
17
- }))
18
- )
10
+ ).then(({data}) => (
11
+ data
12
+ .filter(eta => eta.eta && eta.dir === bound)
13
+ // filter the eta by the stop sequence information
14
+ // as the route data may not 100% match
15
+ // use the nearest seq
16
+ .sort((a,b) => Math.abs(a.seq - seq) < Math.abs(b.seq - seq) ? -1 : 1 )
17
+ .filter((eta, idx, self) => eta.seq === self[0].seq)
18
+ .map(e => ({
19
+ eta: e.eta,
20
+ remark: {
21
+ zh: e.rmk_tc,
22
+ en: e.rmk_en
23
+ },
24
+ co: 'nwfb'
25
+ }))
26
+ ))
19
27
  ),
20
28
  fetchStopEtas: ( stopId ) => (
21
29
  fetch(`https://rt.data.gov.hk/v1/transport/batch/stop-eta/NWFB/${stopId}`, {
package/index.js CHANGED
@@ -14,15 +14,15 @@ module.exports = {
14
14
  for ( const company_id of co ) {
15
15
  if (company_id === 'kmb' && stops.kmb ){
16
16
  _etas = _etas.concat( await KmbApi.fetchEtas({
17
- route,
18
- stopId: stops.kmb[seq],
19
- seq,
20
- serviceType, bound: bound[company_id]})
21
- )
17
+ route,
18
+ stopId: stops.kmb[seq],
19
+ seq,
20
+ serviceType, bound: bound[company_id]
21
+ }))
22
22
  } else if ( company_id === 'ctb' && stops.ctb ) {
23
- _etas = _etas.concat( await CtbApi.fetchEtas({stopId: stops.ctb[seq], route, bound: bound[company_id] }))
23
+ _etas = _etas.concat( await CtbApi.fetchEtas({stopId: stops.ctb[seq], route, bound: bound[company_id], seq }))
24
24
  } else if ( company_id === 'nwfb' && stops.nwfb ) {
25
- _etas = _etas.concat( await NwfbApi.fetchEtas({stopId: stops.nwfb[seq], route, bound: bound[company_id] }))
25
+ _etas = _etas.concat( await NwfbApi.fetchEtas({stopId: stops.nwfb[seq], route, bound: bound[company_id], seq }))
26
26
  } else if ( company_id === 'nlb' && stops.nlb ) {
27
27
  _etas = _etas.concat( await NlbApi.fetchEtas({stopId: stops.nlb[seq], nlbId}) )
28
28
  } else if ( company_id === 'lrtfeeder' && stops.lrtfeeder ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hk-bus-eta",
3
- "version": "1.7.2",
3
+ "version": "1.7.5",
4
4
  "description": "Query the ETA (Estimated Time of Arrival) of HK Bus",
5
5
  "main": "index.js",
6
6
  "scripts": {