[traffic] Use MWM ID for Coloring map, now that we have a single DataSource

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-05-13 00:49:53 +03:00
parent d7facd5732
commit fafec070c9
2 changed files with 10 additions and 16 deletions

View File

@@ -404,7 +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 * 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. * structures to accept a TraFF message ID (string) rather than an integer.
*/ */
void TrafficManager::DecodeMessage(traffxml::TraffMessage & message, std::map<std::string, void TrafficManager::DecodeMessage(traffxml::TraffMessage & message, std::map<MwmSet::MwmId,
traffic::TrafficInfo::Coloring> & trafficCache) traffic::TrafficInfo::Coloring> & trafficCache)
{ {
if (message.m_location) if (message.m_location)
@@ -460,7 +460,6 @@ void TrafficManager::DecodeMessage(traffxml::TraffMessage & message, std::map<st
for (size_t i = 0; i < paths.size(); i++) for (size_t i = 0; i < paths.size(); i++)
for (size_t j = 0; j < paths[i].m_path.size(); j++) for (size_t j = 0; j < paths[i].m_path.size(); j++)
{ {
std::string countryName = paths[i].m_path[j].GetFeatureId().m_mwmId.GetInfo()->GetCountryName();
auto fid = paths[i].m_path[j].GetFeatureId().m_index; auto fid = paths[i].m_path[j].GetFeatureId().m_index;
auto segment = paths[i].m_path[j].GetSegId(); auto segment = paths[i].m_path[j].GetSegId();
uint8_t direction = paths[i].m_path[j].IsForward() ? uint8_t direction = paths[i].m_path[j].IsForward() ?
@@ -504,7 +503,7 @@ void TrafficManager::DecodeMessage(traffxml::TraffMessage & message, std::map<st
*/ */
} }
// TODO process all TrafficImpact fields and determine the speed group based on that // TODO process all TrafficImpact fields and determine the speed group based on that
trafficCache[countryName][traffic::TrafficInfo::RoadSegmentId(fid, segment, direction)] = sg; trafficCache[paths[i].m_path[j].GetFeatureId().m_mwmId][traffic::TrafficInfo::RoadSegmentId(fid, segment, direction)] = sg;
} }
} }
} }
@@ -548,16 +547,11 @@ void TrafficManager::ThreadRoutine()
LOG(LINFO, (m_messageCache.size(), "message(s) in cache")); LOG(LINFO, (m_messageCache.size(), "message(s) in cache"));
/* /*
* Map between country names and their colorings. * Map between MWM IDs and their colorings.
* TODO use MwmId as map keys:
* As long as we dont/cant use the frameworks `DataSource` instance for the OpenLR decoder,
* `MwmId` instances from the decoder will not match those from the framework because of the
* way the identity operator is currently implemented (comparing `MwmInfo` instances rather than
* their contents). The ultimate goal is to do matching based on `MwmId`s, but that requires
* either running the OpenLR decoder off the shared `DataSource` or changing the way `MwmInfo`
* comparison works, eitehr of which may come with regressions and needs to be tested.
*/ */
std::map<std::string, traffic::TrafficInfo::Coloring> allMwmColoring; //TODO should we use std::map<MwmSet::MwmId, std::shared_ptr<const traffic::TrafficInfo::Coloring>> ?
// TODO store mwm/segment/speed group map with each message, build allMwmColoring on the fly
std::map<MwmSet::MwmId, traffic::TrafficInfo::Coloring> allMwmColoring;
for (auto [id, message] : m_messageCache) for (auto [id, message] : m_messageCache)
{ {
LOG(LINFO, (" ", id, ":", message)); LOG(LINFO, (" ", id, ":", message));
@@ -703,7 +697,7 @@ void TrafficManager::OnTrafficRequestFailed(traffic::TrafficInfo && info)
} }
#endif #endif
void TrafficManager::OnTrafficDataUpdate(std::map<std::string, traffic::TrafficInfo::Coloring> & trafficCache) void TrafficManager::OnTrafficDataUpdate(std::map<MwmSet::MwmId, traffic::TrafficInfo::Coloring> & trafficCache)
{ {
/* /*
* Much of this code is copied and pasted together from old MWM code, with some minor adaptations: * Much of this code is copied and pasted together from old MWM code, with some minor adaptations:
@@ -716,7 +710,7 @@ void TrafficManager::OnTrafficDataUpdate(std::map<std::string, traffic::TrafficI
*/ */
ForEachActiveMwm([this, trafficCache](MwmSet::MwmId const & mwmId) { ForEachActiveMwm([this, trafficCache](MwmSet::MwmId const & mwmId) {
ASSERT(mwmId.IsAlive(), ()); ASSERT(mwmId.IsAlive(), ());
auto tcit = trafficCache.find(mwmId.GetInfo()->GetCountryName()); auto tcit = trafficCache.find(mwmId);
if (tcit != trafficCache.end()) if (tcit != trafficCache.end())
{ {
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);

View File

@@ -260,7 +260,7 @@ private:
* @param trafficCache The cache in which all decoded paths with their speed groups will be stored. * @param trafficCache The cache in which all decoded paths with their speed groups will be stored.
*/ */
void DecodeMessage(traffxml::TraffMessage & message, void DecodeMessage(traffxml::TraffMessage & message,
std::map<std::string, traffic::TrafficInfo::Coloring> & trafficCache); std::map<MwmSet::MwmId, traffic::TrafficInfo::Coloring> &trafficCache);
/** /**
* @brief Event loop for the traffic worker thread. * @brief Event loop for the traffic worker thread.
@@ -290,7 +290,7 @@ private:
* *
* @param trafficCache The new per-MWM colorings (preprocessed traffic information). * @param trafficCache The new per-MWM colorings (preprocessed traffic information).
*/ */
void OnTrafficDataUpdate(std::map<std::string, traffic::TrafficInfo::Coloring> & trafficCache); void OnTrafficDataUpdate(std::map<MwmSet::MwmId, traffic::TrafficInfo::Coloring> &trafficCache);
// TODO no longer needed // TODO no longer needed
#ifdef traffic_dead_code #ifdef traffic_dead_code