Skip to content

Commit cd79f8e

Browse files
add parent station ids, only use parent relationship for compat profile
1 parent b9e01b4 commit cd79f8e

5 files changed

Lines changed: 16 additions & 22 deletions

File tree

p/compat/location.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
import distance from 'gps-distance';
2-
import {enrichStation as basicEnrichStation} from '../../parse/location.js';
1+
import { enrichStation as basicEnrichStation } from '../../parse/location.js';
32

43

54
const enrichStation = (ctx, stop, locations) => {
6-
const {common} = ctx;
7-
const locs = locations || common?.locations;
8-
if (locs && locs[stop.name] && locs[stop.name].ts && locs[stop.name].ts + 1000 * 60 * 10 > Date.now()) {
9-
if (distance(locs[stop.name].location.latitude, locs[stop.name].location.longitude, stop.location.latitude, stop.location.longitude) * 1000 < 200) {
10-
let rich = locs[stop.name];
11-
stop = {
12-
...stop,
13-
id: rich.id,
14-
};
15-
}
16-
} else if (locs) {
17-
locs[stop.name] = {
18-
id: stop.id,
19-
location: stop.location,
20-
ts: Date.now(),
21-
};
5+
if (stop.station) {
6+
stop.id = stop.station.id;
227
}
238
return basicEnrichStation(ctx, stop, locations);
249
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@motis-project/motis-fptf-client",
33
"description": "Exposing the MOTIS API as a Friendly Public Transport Format API.",
4-
"version": "6.3.2",
4+
"version": "6.4.0",
55
"type": "module",
66
"main": "index.js",
77
"files": [

parse/location.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ const parseLocation = (ctx, l) => {
1212
name: l.name,
1313
location: res,
1414
};
15+
if (l.parentId) {
16+
s.type = 'stop';
17+
s.station = {
18+
type: 'station',
19+
id: l.parentId,
20+
name: l.name,
21+
location: res,
22+
}
23+
}
1524
return ctx.profile.enrichStation(ctx, s);
1625
}
1726
res.name = l.name;

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ What doesn't work (yet):
2323
* `trip()`
2424
* all other endpoints (`tripsByName()`, `radar()`, `journeysFromTrip()`, `remarks()`, `lines()`, `station()`)
2525

26-
By default, a [transitous](https://transitous.org) profile is included, but you can use it with any other MOTIS instance by setting the `MOTIS_BASE_URL` environment variable or modifying the profile. There is also a `compat` profile which will try to merge stops (which are often platforms in GTFS) to stations similar to the stations known from `db-vendo-client`/`hafas-client`. Other related platforms/substops (currently, those with the same name in a radius of 200m) will be merged into the first encountered stop id. In addition, just as the `transitous` profile, when `enrichStations` is enabled (default), the `station` attribute of stops will contain the matching station data from [db-hafas-stations](https://github.com/derhuerst/db-hafas-stations) including the EVA number as id, if available. This enables matching to other DB data.
26+
By default, a [transitous](https://transitous.org) profile is included, but you can use it with any other MOTIS instance by setting the `MOTIS_BASE_URL` environment variable or modifying the profile. There is also a `compat` profile which will try to merge stops (which are often platforms in GTFS) to stations similar to the stations known from `db-vendo-client`/`hafas-client`, by replacing their ID with that of their parent station. In addition, just as the `transitous` profile, when `enrichStations` is enabled (default), the `station` attribute of stops will contain the matching station data from [db-hafas-stations](https://github.com/derhuerst/db-hafas-stations) including the EVA number as id, if available. This enables matching to other DB data.
2727

2828
## Usage
2929

0 commit comments

Comments
 (0)