Commit 9b11f7a9 authored by Volker Krause's avatar Volker Krause

Compute trip group weather forecast in the same way as the timeline does

This fixes deviations in the min/max temperature due to a larger distance
between airport and hotel for example. Or: the weather in Milan looks
slightly better for Akademy than at MXP :)
parent c3b5ea61
......@@ -73,7 +73,7 @@ private Q_SLOTS:
QVERIFY(!provider.weatherForecast({}).isValid());
const auto fc = provider.weatherForecast(mgr.tripGroup(mgr.tripGroups().at(0)));
QVERIFY(fc.isValid());
QCOMPARE(fc.minimumTemperature(), 7.78147f);
QCOMPARE(fc.minimumTemperature(), 7.74224f);
QCOMPARE(fc.maximumTemperature(), 47.4647f);
const auto countries = provider.countryInformation(mgr.tripGroup(mgr.tripGroups().at(0)), QStringLiteral("DE"));
......
......@@ -97,12 +97,18 @@ void TripGroup::store(const QString &path) const
QDateTime TripGroup::beginDateTime() const
{
if (m_elements.empty()) {
return {};
}
const auto res = m_mgr->m_resMgr->reservation(m_elements.at(0));
return KItinerary::SortUtil::startDateTime(res);
}
QDateTime TripGroup::endDateTime() const
{
if (m_elements.empty()) {
return {};
}
const auto res = m_mgr->m_resMgr->reservation(m_elements.constLast());
return KItinerary::SortUtil::endDateTime(res);
}
......@@ -33,6 +33,14 @@
using namespace KItinerary;
static GeoCoordinates geoCoordinate(const QVariant &res)
{
if (LocationUtil::isLocationChange(res)) {
return LocationUtil::geo(LocationUtil::arrivalLocation(res));
}
return LocationUtil::geo(LocationUtil::location(res));
}
TripGroupInfoProvider::TripGroupInfoProvider() = default;
TripGroupInfoProvider::~TripGroupInfoProvider() = default;
......@@ -52,14 +60,17 @@ WeatherForecast TripGroupInfoProvider::weatherForecast(const TripGroup &group) c
const auto elems = group.elements();
QVariant startRes;
QDateTime lastEndTime = group.beginDateTime();
for (const auto &resId : elems) {
const auto res = m_resMgr->reservation(resId);
if (!LocationUtil::isLocationChange(res)) {
const auto newGeo = geoCoordinate(res);
if (!newGeo.isValid()) {
continue;
}
if (startRes.isValid()) {
const auto geo = LocationUtil::geo(LocationUtil::arrivalLocation(startRes));
const auto startDt = SortUtil::endDateTime(startRes);
const auto geo = geoCoordinate(startRes);
const auto startDt = LocationUtil::isLocationChange(startRes) ? SortUtil::endDateTime(startRes) : lastEndTime;
const auto endDt = SortUtil::startDateTime(res);
if (geo.isValid() && startDt.isValid() && endDt.isValid()) {
const auto newFc = m_weatherMgr->forecast(geo.latitude(), geo.longitude(), startDt, endDt);
......@@ -69,6 +80,7 @@ WeatherForecast TripGroupInfoProvider::weatherForecast(const TripGroup &group) c
}
fc.merge(newFc);
}
lastEndTime = endDt;
}
startRes = res;
}
......
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