File indexing completed on 2024-05-12 04:42:56

0001 /*
0002     SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003     SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <kde@broulik.de>
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function parsePosition(response)
0008 {
0009     return {
0010         latitude = response.lat,
0011         longitude = response.lon,
0012         speed = response.groundSpeed * 1.852,
0013         heading = response.heading,
0014         altitude = response.altitude * 0.3048
0015         // TODO timestamp, temperature
0016     };
0017 }
0018 
0019 function stringToMinutes(str) { // turns "HH:mm" into minutes int.
0020     const parts = str.split(":");
0021     return parseInt(parts[0], 10) * 60 + parseInt(parts[1], 10);
0022 }
0023 
0024 function parseJourney(response)
0025 {
0026     const section = {
0027         mode = 'PublicTransport',
0028         route = {
0029             line = {
0030                 mode = 'Air',
0031                 name = response.flightNumber
0032             }
0033         },
0034         from = {
0035             identifier = { iata = response.orig.code },
0036             latitude = response.orig.lat,
0037             longitude = response.orig.lon,
0038             name = response.orig.code
0039         },
0040         to = {
0041             identifier = { iata = response.dest.code },
0042             latitude = response.dest.lat,
0043             longitude = response.dest.lon,
0044             name = response.dest.code
0045         },
0046         distance = Math.round(response.distDest * 1852),
0047         scheduledArrivalTime: response.dest.localTimeAtArrival
0048     };
0049 
0050     const elapsedMinutes = stringToMinutes(response.elapsedFlightTime);
0051     section.expectedDepartureTime = new Date(response.orig.localTime);
0052     section.expectedDepartureTime.setMinutes(section.expectedDepartureTime.getMinutes() - elapsedMinutes);
0053 
0054     const remainingMinutes = stringToMinutes(response.timeDest);
0055     section.expectedArrivalTime = new Date(response.dest.localTime);
0056     section.expectedArrivalTime.setMinutes(section.expectedArrivalTime.getMinutes() + remainingMinutes);
0057 
0058     return { sections = [section] };
0059 }