Commit 08fd1eef authored by Volker Krause's avatar Volker Krause

Compute next poll time against live data, not the base schedule

parent 97eab62f
......@@ -302,32 +302,38 @@ void LiveDataManager::updateDepartureData(const KPublicTransport::Departure &dep
emit departureUpdated(resId);
}
bool LiveDataManager::hasDeparted(const QString &resId, const QVariant &res) const
QDateTime LiveDataManager::departureTime(const QString &resId, const QVariant &res) const
{
const auto now = QDateTime::currentDateTime();
if (JsonLd::isA<TrainTrip>(res)) {
const auto &dep = m_departures.value(resId).change;
if (dep.hasExpectedDepartureTime()) {
return dep.expectedDepartureTime() < now;
return dep.expectedDepartureTime();
}
}
return SortUtil::startDateTime(res) < now;
return SortUtil::startDateTime(res);
}
bool LiveDataManager::hasArrived(const QString &resId, const QVariant &res) const
QDateTime LiveDataManager::arrivalTime(const QString &resId, const QVariant &res) const
{
const auto now = QDateTime::currentDateTime();
if (JsonLd::isA<TrainTrip>(res)) {
const auto &arr = m_arrivals.value(resId).change;
if (arr.hasExpectedArrivalTime()) {
return arr.expectedArrivalTime() < now;
return arr.expectedArrivalTime();
}
}
return SortUtil::endtDateTime(res) < now;
return SortUtil::endtDateTime(res);
}
bool LiveDataManager::hasDeparted(const QString &resId, const QVariant &res) const
{
return departureTime(resId, res) < QDateTime::currentDateTime();
}
bool LiveDataManager::hasArrived(const QString &resId, const QVariant &res) const
{
return arrivalTime(resId, res) < QDateTime::currentDateTime();
}
void LiveDataManager::loadPublicTransportData(const QString &prefix, QHash<QString, TrainChange> &data) const
......@@ -499,16 +505,14 @@ int LiveDataManager::nextPollTimeForReservation(const QString& resId) const
const auto res = m_resMgr->reservation(resId);
const auto now = QDateTime::currentDateTime();
auto dist = now.secsTo(SortUtil::startDateTime(res));
auto dist = now.secsTo(departureTime(resId, res));
if (dist < 0) {
dist = now.secsTo(SortUtil::endtDateTime(res));
dist = now.secsTo(arrivalTime(resId, res));
}
if (dist < 0) {
return std::numeric_limits<int>::max();
}
// TODO consider delayed but still pending departures/arrivals too
const auto it = std::lower_bound(std::begin(pollIntervalTable), std::end(pollIntervalTable), dist, [](const auto &lhs, const auto rhs) {
return lhs.distance < rhs;
});
......
Markdown is supported
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