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

0001 /*
0002     SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function toDegreeV1(val)
0007 {
0008     if (val > 80000000) {
0009         val -= 80000000;
0010         val *= -1;
0011     }
0012     return val / 1000.0;
0013 }
0014 
0015 function parseCurrentPositionV1(response)
0016 {
0017     return {
0018         latitude = toDegreeV1(response.td_id_fltdata_present_position_latitude),
0019         longitude = toDegreeV1(response.td_id_fltdata_present_position_longitude),
0020         speed = response.td_id_fltdata_ground_speed * 1.852,
0021         heading = response.td_id_fltdata_true_heading,
0022         altitude = response.td_id_fltdata_altitude * 0.3048
0023         // TODO timestamp?
0024     };
0025 }
0026 
0027 function parseCurrentPositionV2(response)
0028 {
0029     return {
0030         latitude = response.current_coordinates.latitude,
0031         longitude = response.current_coordinates.longitude,
0032         speed = response.ground_speed_knots * 1.852,
0033         heading = response.true_heading_degree,
0034         altitude = response.altitude_feet * 0.3048,
0035         timestamp = response.current_utc_date + 'T' + response.current_utc_time + 'Z'
0036     };
0037 }
0038 
0039 function parseFlightV1(response)
0040 {
0041     const section = {
0042         mode = 'PublicTransport',
0043         route = {
0044             line = {
0045                 mode = 'Air',
0046                 name = response.td_id_fltdata_flight_number
0047             }
0048         },
0049         from = {
0050             identifier = {
0051                 iata = response.td_id_fltdata_departure_baggage_id,
0052                 icao = response.td_id_fltdata_departure_id
0053             },
0054             latitude = toDegreeV1(response.td_id_fltdata_departure_latitude),
0055             longitude = toDegreeV1(response.td_id_fltdata_departure_longitude),
0056             name = response.td_id_fltdata_departure_baggage_id
0057         },
0058         to = {
0059             identifier = {
0060                 iata = response.td_id_fltdata_destination_baggage_id,
0061                 icao = response.td_id_fltdata_destination_id
0062             },
0063             latitude = toDegreeV1(response.td_id_fltdata_destination_latitude),
0064             longitude = toDegreeV1(response.td_id_fltdata_destination_longitude),
0065             name = response.td_id_fltdata_destination_baggage_id
0066         },
0067         distance = (Math.max(response.td_id_fltdata_distance_from_origin, response.td_id_fltdata_distance_traveled) + response.td_id_fltdata_distance_to_destination) * 1852
0068         // TODO times?
0069     };
0070     return { sections = [section] };
0071 }
0072 
0073 function parseFlightV2(response)
0074 {
0075     const section = {
0076         mode = 'PublicTransport',
0077         route = {
0078             line = {
0079                 mode = 'Air',
0080                 name = response.flight_number
0081             }
0082         },
0083         from = {
0084             identifier = {
0085                 iata = response.departure_iata,
0086                 icao = response.departure_icao
0087             },
0088             latitude = response.departure_coordinates.latitude,
0089             longitude = response.departure_coordinates.longitude,
0090             name = response.departure_iata
0091         },
0092         to = {
0093             identifier = {
0094                 iata = response.destination_iata,
0095                 icao = response.destination_icao
0096             },
0097             latitude = response.destination_coordinates.latitude,
0098             longitude = response.destination_coordinates.longitude,
0099             name = response.destination_iata
0100         },
0101         distance = (Math.max(response.distance_from_departure_nautical_miles, response.distance_from_departure_nautical_miles) + response.distance_to_destination_nautical_miles) * 1852,
0102         expectedDepartureTime = response.takeoff_time_utc,
0103         expectedArrivalTime = response.current_utc_date + 'T' + response.estimated_arrival_time_utc + ':00' // this is called "utc", but it is local time...
0104     };
0105     return { sections = [section] };
0106 }