Commit 279d04b6 authored by Volker Krause's avatar Volker Krause
Browse files

Move flight distance/duration plausibility functions to their own file

Will be needed by the generic PDF boarding pass extractor as well.
parent 455c499c
......@@ -122,6 +122,7 @@ target_sources(KPimItinerary PRIVATE
extractorvalidator.cpp
file.cpp
flightpostprocessor.cpp
flightutil.cpp
htmldocument.cpp
jsonlddocument.cpp
locationutil.cpp
......
......@@ -7,6 +7,7 @@
#include "flightpostprocessor_p.h"
#include "extractorpostprocessor_p.h"
#include "extractorutil.h"
#include "flightutil_p.h"
#include "locationutil.h"
#include "knowledgedb/airportdb.h"
......@@ -21,11 +22,6 @@
using namespace KItinerary;
enum {
AirplaneSpeedLowerBound = 250, // km/h, turboprop aircraft, and a bit lower than average cruise speed to account for takeoff/landing
AirplaneSpeedUpperBound = 2140, // km/h, Concorde, so a bit excessive
};
Flight FlightPostProcessor::processFlight(Flight flight)
{
lookupAirportCodes(flight.departureAirport(), m_departureCodes);
......@@ -146,12 +142,6 @@ void FlightPostProcessor::pickAirportByDistance(int duration, const std::vector<
return;
}
int lowerBoundDistance = AirplaneSpeedLowerBound * (duration / 3.6);
if (duration < 3600) { // for ultra short flights the takeoff/landing overhead is so big that our expected speed range doesn't work reliable anymore
lowerBoundDistance /= 2;
}
const int upperBoundDistance = AirplaneSpeedUpperBound * (duration / 3.6);
for (auto it = codes.begin(); it != codes.end();) {
const auto destCoord = KnowledgeDb::coordinateForAirport(*it);
if (!destCoord.isValid()) {
......@@ -162,7 +152,7 @@ void FlightPostProcessor::pickAirportByDistance(int duration, const std::vector<
for (const auto startCode : startCodes) {
const auto startCoord = KnowledgeDb::coordinateForAirport(startCode);
const auto dist = LocationUtil::distance({startCoord.latitude, startCoord.longitude}, {destCoord.latitude, destCoord.longitude});
outOfRange = outOfRange && (dist > upperBoundDistance || dist < lowerBoundDistance);
outOfRange = outOfRange && !FlightUtil::isPlausibleDistanceForDuration(dist, duration);
}
if (outOfRange) {
it = codes.erase(it);
......
/*
SPDX-FileCopyrightText: 2017-2019 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "flightutil_p.h"
#include <QDebug>
using namespace KItinerary;
enum {
AirplaneSpeedLowerBound = 250, // km/h, turboprop aircraft, and a bit lower than average cruise speed to account for takeoff/landing
AirplaneSpeedUpperBound = 2140, // km/h, Concorde, so a bit excessive
};
bool FlightUtil::isPlausibleDistanceForDuration(int distance, int duration)
{
int lowerBoundDistance = AirplaneSpeedLowerBound * (duration / 3.6);
if (duration < 3600) { // for ultra short flights the takeoff/landing overhead is so big that our expected speed range doesn't work reliable anymore
lowerBoundDistance /= 2;
}
const int upperBoundDistance = AirplaneSpeedUpperBound * (duration / 3.6);
return distance < upperBoundDistance && distance > lowerBoundDistance;
}
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KITINERARY_FLIGHTUTIL_H
#define KITINERARY_FLIGHTUTIL_H
namespace KItinerary {
/** Utility functions for dealing with flights. */
namespace FlightUtil
{
/** Check whether the given distance (in meters) can be covered by a flight
* in the given time (in seconds).
*/
bool isPlausibleDistanceForDuration(int distance, int duration);
}
}
#endif // KITINERARY_FLIGHTUTIL_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment