@golemio/pid
Version:
Golemio PID Module
71 lines • 3.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RopidGTFSCisStopsTransformation = void 0;
const ropid_gtfs_1 = require("../../../schema-definitions/ropid-gtfs");
const helpers_1 = require("@golemio/core/dist/integration-engine/helpers");
const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation");
class RopidGTFSCisStopsTransformation extends AbstractTransformation_1.AbstractTransformation {
constructor() {
super(...arguments);
this.name = ropid_gtfs_1.RopidGTFS.name + "CisStops";
this.transformInternal = ({ data }) => {
const cis_stops = [];
const stopGroups = [];
for (const stopGroup of data) {
for (const stop of stopGroup.stops) {
cis_stops.push({
alt_idos_name: stop.altIdosName,
cis: stopGroup.cis,
id: stop.id,
jtsk_x: stop.jtskX,
jtsk_y: stop.jtskY,
lat: stop.lat,
lon: stop.lon,
platform: stop.platform,
wheelchair_access: stop.wheelchairAccess,
zone: stop.zone,
});
}
stopGroups.push({
avg_jtsk_x: stopGroup.avgJtskX,
avg_jtsk_y: stopGroup.avgJtskY,
avg_lat: stopGroup.avgLat,
avg_lon: stopGroup.avgLon,
cis: stopGroup.cis,
district_code: stopGroup.districtCode,
full_name: stopGroup.fullName,
idos_category: stopGroup.idosCategory,
idos_name: stopGroup.idosName,
municipality: stopGroup.municipality,
name: stopGroup.name,
node: stopGroup.node,
unique_name: stopGroup.uniqueName,
});
}
return {
cis_stops,
cis_stop_groups: this.getUniqueStopGroups(stopGroups),
};
};
this.getUniqueStopGroups = (data) => {
const uniqueMap = new Map();
const duplicateCisStopGroups = [];
data.forEach((item) => {
if (uniqueMap.has(item.cis)) {
duplicateCisStopGroups.push(item.cis);
uniqueMap.delete(item.cis);
}
else {
uniqueMap.set(item.cis, item);
}
});
if (duplicateCisStopGroups.length > 0) {
helpers_1.log.warn("CIS_STOP_GROUPS contains duplicate cis. Items with this cis was removed: " +
JSON.stringify(duplicateCisStopGroups));
}
return [...uniqueMap.values()];
};
}
}
exports.RopidGTFSCisStopsTransformation = RopidGTFSCisStopsTransformation;
//# sourceMappingURL=RopidGTFSCisStopsTransformation.js.map