[traffic] Store colorings with message and build global coloring from that

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-05-14 19:22:50 +03:00
parent fafec070c9
commit 7107314e2f
4 changed files with 56 additions and 4 deletions

View File

@@ -404,8 +404,7 @@ void TrafficManager::InitializeDataSources(std::vector<FrozenDataSource> & dataS
* If we batch-decode segments, we need to fix the [partner] segment IDs in the segment and path
* structures to accept a TraFF message ID (string) rather than an integer.
*/
void TrafficManager::DecodeMessage(traffxml::TraffMessage & message, std::map<MwmSet::MwmId,
traffic::TrafficInfo::Coloring> & trafficCache)
void TrafficManager::DecodeMessage(traffxml::TraffMessage & message)
{
if (message.m_location)
{
@@ -503,7 +502,7 @@ void TrafficManager::DecodeMessage(traffxml::TraffMessage & message, std::map<Mw
*/
}
// TODO process all TrafficImpact fields and determine the speed group based on that
trafficCache[paths[i].m_path[j].GetFeatureId().m_mwmId][traffic::TrafficInfo::RoadSegmentId(fid, segment, direction)] = sg;
message.m_decoded[paths[i].m_path[j].GetFeatureId().m_mwmId][traffic::TrafficInfo::RoadSegmentId(fid, segment, direction)] = sg;
}
}
}
@@ -555,7 +554,10 @@ void TrafficManager::ThreadRoutine()
for (auto [id, message] : m_messageCache)
{
LOG(LINFO, (" ", id, ":", message));
DecodeMessage(message, allMwmColoring);
DecodeMessage(message);
// store message coloring in AllMwmColoring
// TODO do this in a later pass...?
traffxml::MergeMultiMwmColoring(message.m_decoded, allMwmColoring);
}
// set new coloring for MWMs

View File

@@ -13,4 +13,5 @@ omim_add_library(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME}
pugixml
coding
)

View File

@@ -268,6 +268,30 @@ uint32_t GuessDnp(openlr::LocationReferencePoint & p1, openlr::LocationReference
return doe * 1.19f + 0.5f;
}
void MergeMultiMwmColoring(MultiMwmColoring & delta, MultiMwmColoring & target)
{
// for each mwm in delta
for (auto [mwmId, coloring] : delta)
// if target contains mwm
if (auto target_it = target.find(mwmId); target_it != target.end())
// for each segment in delta[mwm] (coloring)
for (auto [rsid, sg] : coloring)
// if target[mwm] contains segment
if (auto c_it = target_it->second.find(rsid) ; c_it != target_it->second.end())
{
// if delta overrules target (target is Unknown, delta is TempBlock or delta is slower than target)
if ((sg == traffic::SpeedGroup::TempBlock)
|| (c_it->second == traffic::SpeedGroup::Unknown) || (sg < c_it->second))
target_it->second[rsid] = sg;
}
else
// if target[mwm] does not contain segment, add speed group
target_it->second[rsid] = sg;
else
// if target does not contain mwm, add coloring
target[mwmId] = coloring;
}
/*
string DebugPrint(LinearSegmentSource source)
{

View File

@@ -5,10 +5,14 @@
#include "geometry/latlon.hpp"
#include "geometry/point2d.hpp"
#include "indexer/mwm_set.hpp"
#include "openlr/openlr_model.hpp"
#include "traffic/speed_groups.hpp"
#include "traffic/traffic_info.hpp"
#include <map>
#include <string>
#include <vector>
@@ -271,6 +275,11 @@ struct TraffEvent
// TODO supplementary information
};
/**
* @brief Global mapping from feature segments to speed groups, across all MWMs.
*/
using MultiMwmColoring = std::map<MwmSet::MwmId, std::map<traffic::TrafficInfo::RoadSegmentId, traffic::SpeedGroup>>;
struct TraffMessage
{
/**
@@ -299,6 +308,7 @@ struct TraffMessage
std::optional<TraffLocation> m_location;
std::vector<TraffEvent> m_events;
std::vector<std::string> m_replaces;
MultiMwmColoring m_decoded;
};
using TraffFeed = std::vector<TraffMessage>;
@@ -317,6 +327,21 @@ using TraffFeed = std::vector<TraffMessage>;
*/
uint32_t GuessDnp(openlr::LocationReferencePoint & p1, openlr::LocationReferencePoint & p2);
/**
* @brief Merges the contents of one `MultiMwmColoring` into another.
*
* After this function returns, `target` will hold the union of the entries it had prior to the
* function call and the entries from `delta`.
*
* In case of conflict, the more restrictive speed group wins. That is, `TempBlock` overrides
* everything else, `Unknown` never overrides anything else, and among `G0` to `G5`, the lowest
* group wins.
*
* @param delta Contains the entries to be added.
* @param target Receives the added entries.
*/
void MergeMultiMwmColoring(MultiMwmColoring &delta, MultiMwmColoring & target);
std::string DebugPrint(IsoTime time);
std::string DebugPrint(Directionality directionality);
std::string DebugPrint(Ramps ramps);