Commit 4e82fc86 authored by Volker Krause's avatar Volker Krause
Browse files

Only add transfers to/from favorite locations if those are reasonable close

This also avoids insanely long transfers being added for partially imported
trips.
parent c39a68b9
......@@ -331,40 +331,6 @@
"sectionHeader": "Saturday, 1/1/00",
"type": 4
},
{
"isToday": false,
"rangeType": 0,
"sectionHeader": "Saturday, 1/1/00",
"transfer": {
"@context": "http://schema.org",
"@type": "Transfer",
"alignment": "After",
"anchorTime": {
"@type": "QDateTime",
"@value": "2000-01-01T16:20:00+01:00",
"timezone": "Europe/Rome"
},
"anchorTimeDelta": 1800,
"floatingLocationType": "FavoriteLocation",
"from": {
"@type": "Location",
"latitude": 43.808799743652344,
"longitude": 11.202899932861328,
"name": "Peretola",
"type": "Place"
},
"fromName": "Peretola",
"state": "Pending",
"to": {
"@type": "Location",
"latitude": 52.51860046386719,
"longitude": 13.376299858093262,
"type": "Place"
},
"toName": "Home"
},
"type": 5
},
{
"isToday": false,
"rangeType": 2,
......
......@@ -422,19 +422,29 @@ KPublicTransport::Location TransferManager::locationFromFavorite(const FavoriteL
FavoriteLocation TransferManager::pickFavorite(const QVariant &anchoredLoc, const QString &resId, Transfer::Alignment alignment) const
{
const auto &favLocs = m_favLocModel->favoriteLocations();
if (favLocs.empty()) {
return {};
}
// TODO selection strategy:
// (1) pick the same favorite as was used before/after resId
// (2) pick the favorite closest to anchoredLoc - this can work very well if the favorites aren't close to each other
// (3) pick the first one
Q_UNUSED(anchoredLoc)
Q_UNUSED(resId)
Q_UNUSED(alignment)
if (m_favLocModel->rowCount() == 0) {
return {};
// pick the first location within a 50km distance
const auto anchordCoord = LocationUtil::geo(anchoredLoc);
const auto it = std::find_if(favLocs.begin(), favLocs.end(), [&anchordCoord](const auto &fav) {
const auto d = LocationUtil::distance(anchordCoord.latitude(), anchordCoord.longitude(), fav.latitude(), fav.longitude());
return d < 50'000;
});
if (it != favLocs.end()) {
return (*it);
}
return m_favLocModel->favoriteLocations()[0];
return {};
}
void TransferManager::addOrUpdateTransfer(Transfer &t)
......
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