File indexing completed on 2024-05-12 04:42:56
0001 /* 0002 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 function parseICEStatus(response) 0007 { 0008 if (response.gpsStatus != 'VALID') { 0009 return {}; 0010 } 0011 return { 0012 latitude = response.latitude, 0013 longitude = response.longitude, 0014 speed = response.speed, 0015 timestamp = new Date(response.serverTime).toISOString() 0016 }; 0017 } 0018 0019 /** @see https://github.com/derhuerst/wifi-on-ice-portal-client */ 0020 function parseICETrip(response) 0021 { 0022 let section = {}; 0023 section.mode = 'PublicTransport'; 0024 section.route = {}; 0025 section.route.direction = response.trip.stopInfo.finalStationName; // TODO destination object 0026 section.route.line = {}; 0027 section.route.line.name = response.trip.trainType + ' ' + response.trip.vzn; 0028 section.route.line.mode = 'LongDistanceTrain'; 0029 section.distance = response.trip.totalDistance; 0030 section.intermediateStops = []; 0031 for (s of response.trip.stops) { 0032 let stop = {}; 0033 stop.stopPoint = {}; 0034 stop.stopPoint.type = 'Stop'; 0035 stop.stopPoint.name = s.station.name; 0036 stop.stopPoint.latitude = s.station.geocoordinates.latitude; 0037 stop.stopPoint.longitude = s.station.geocoordinates.longitude; 0038 stop.stopPoint.identifier = {}; 0039 stop.stopPoint.identifier.ibnr = s.station.evaNr.substr(0, 7); 0040 stop.scheduledPlatform = s.track.scheduled; 0041 stop.expectedPlatform = s.track.actual; 0042 stop.scheduledDepartureTime = new Date(s.timetable.scheduledDepartureTime).toISOString(); 0043 stop.expectedDepartureTime = new Date(s.timetable.actualDepartureTime).toISOString(); 0044 stop.scheduledArrivalTime = new Date(s.timetable.scheduledArrivalTime).toISOString(); 0045 stop.expectedArrivalTime = new Date(s.timetable.actualArrivalTime).toISOString(); 0046 if (s.delayReasons) { 0047 stop.notes = []; 0048 for (d of s.delayReasons) { 0049 stop.notes.push(d.text); 0050 } 0051 } 0052 if (s.info.status === 1 && s.info.distanceFromStart === 0) { 0053 stop.disruptionEffect = 'NoService'; 0054 } 0055 section.intermediateStops.push(stop); 0056 } 0057 0058 let jny = {}; 0059 jny.sections = [section]; 0060 return jny; 0061 } 0062 0063 function parseZugportalTrip(response) 0064 { 0065 let section = { 0066 mode = 'PublicTransport', 0067 route = { 0068 line = { 0069 name = response.name, 0070 // TODO complete map from response.type 0071 mode = response.type == 'CITY_TRAIN' ? 'RapidTransit' : 'Train' 0072 } 0073 }, 0074 intermediateStops = [], 0075 notes = [] 0076 }; 0077 for (s of response.stops) { 0078 let stop = { 0079 stopPoint = { 0080 type = 'Stop', 0081 name = s.station.name, 0082 identifier = { ibnr = s.station.evaNo } 0083 }, 0084 scheduledPlatform = s.track.target, 0085 expectedPlatform = s.track.prediction, 0086 notes = [] 0087 }; 0088 if (s.station.position) { 0089 stop.stopPoint.latitude = s.station.position.latitude; 0090 stop.stopPoint.longitude = s.station.position.longitude; 0091 } 0092 if (s.departureTime) { 0093 stop.scheduledDepartureTime = s.departureTime.target; 0094 stop.expectedDepartureTime = s.departureTime.predicted; 0095 } 0096 if (s.arrivalTime) { 0097 stop.scheduledArrivalTime = s.arrivalTime.target; 0098 stop.expectedArrivalTime = s.arrivalTime.predicted; 0099 } 0100 0101 if (s.status === "Canceled" || s.canceled === true) { 0102 stop.disruptionEffect = 'NoService'; 0103 } 0104 0105 for (message of s.messages) { 0106 if (message.type === "CUSTOMER_REASON") { 0107 notes.push(message.textShort || message.text); 0108 } 0109 } 0110 0111 section.intermediateStops.push(stop); 0112 } 0113 0114 for (him of response.hims) { 0115 section.notes.push(him.captionHtml || him.caption); 0116 } 0117 0118 // TODO uic, trainNo 0119 return { sections = [section] }; 0120 }