Commit bf82dd2b authored by Volker Krause's avatar Volker Krause
Browse files

Don't get confused by generation timestamps in boarding passes

If we find full date/time values from a different day, those are now
discarded.
parent 11f54815
......@@ -23,7 +23,6 @@
#include <QDebug>
#include <QTimeZone>
#include <array>
#include <unordered_map>
using namespace KItinerary;
......@@ -72,7 +71,7 @@ static bool isPlausibleBoardingTime(const QDateTime &boarding, const QDateTime &
return boarding < departure && boarding.secsTo(departure) <= 3600;
}
static bool isPlausibleFlightTimes(const std::array<QDateTime, 3> &times, KnowledgeDb::IataCode from, KnowledgeDb::IataCode to)
static bool isPlausibleFlightTimes(const std::vector<QDateTime> &times, KnowledgeDb::IataCode from, KnowledgeDb::IataCode to)
{
if (!isPlausibleBoardingTime(times[0], times[1])) {
return false;
......@@ -171,13 +170,25 @@ ExtractorResult GenericBoardingPassExtractor::extract(const ExtractorDocumentNod
if (airportNames.size() == 2) {
TimeFinder timeFinder;
timeFinder.find(pageText);
if (timeFinder.times().size() == 3) {
std::array<QDateTime, 3> times;
std::transform(timeFinder.times().begin(), timeFinder.times().end(), times.begin(), [departureDay](QTime t) {
return QDateTime(departureDay, t);
});
std::sort(times.begin(), times.end());
std::vector<QDateTime> times;
for (const auto &res : timeFinder.results()) {
switch (res.dateTime.type()) {
case QVariant::Time:
times.push_back(QDateTime(departureDay, res.dateTime.toTime()));
break;
case QVariant::DateTime:
if (res.dateTime.toDateTime().date() == departureDay) {
times.push_back(res.dateTime.toDateTime());
}
break;
case QVariant::Date:
default:
break;
}
}
std::sort(times.begin(), times.end());
times.erase(std::unique(times.begin(), times.end()), times.end());
if (times.size() == 3) {
// apply what we found
if (isPlausibleFlightTimes(times, from, to)) {
for (auto &res : result) {
......
......@@ -20,7 +20,7 @@ static bool isSeparator(QChar c)
void TimeFinder::find(QStringView text)
{
m_times.clear();
m_results.clear();
findTimes(text);
if (!m_results.empty()) {
findDates(text);
......@@ -100,9 +100,6 @@ void TimeFinder::findTimes(QStringView text)
hour = 0;
}
if (std::find(m_times.begin(), m_times.end(), QTime(hour, min)) == m_times.end()) {
m_times.push_back(QTime(hour, min));
}
Result result;
result.dateTime = QTime(hour, min);
result.begin = rxTimeMatch.capturedStart();
......@@ -179,11 +176,6 @@ void TimeFinder::mergeResults()
}
}
const std::vector<QTime>& TimeFinder::times() const
{
return m_times;
}
const std::vector<TimeFinder::Result>& TimeFinder::results() const
{
return m_results;
......
......@@ -21,8 +21,6 @@ class TimeFinder
public:
void find(QStringView text);
const std::vector<QTime>& times() const;
struct Result {
int begin = -1;
int end = -1;
......@@ -36,7 +34,6 @@ private:
void findDates(QStringView text);
void mergeResults();
std::vector<QTime> m_times;
std::vector<Result> m_results;
};
......
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