mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
[traffic] Remove obsolete code
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -103,6 +103,11 @@ boost::python::list GenerateTrafficKeys(std::string const & mwmPath)
|
|||||||
return pyhelpers::StdVectorToPythonList(result);
|
return pyhelpers::StdVectorToPythonList(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO Inherited from MWM/OM, no longer works with TraFF logic (API logic changed).
|
||||||
|
* We no longer separate keys (segments IDs) from values (their speed groups).
|
||||||
|
* See if we can refactor this into something meaningful and useful, else remove.
|
||||||
|
*/
|
||||||
std::vector<uint8_t> GenerateTrafficValues(std::vector<traffic::TrafficInfo::RoadSegmentId> const & keys,
|
std::vector<uint8_t> GenerateTrafficValues(std::vector<traffic::TrafficInfo::RoadSegmentId> const & keys,
|
||||||
boost::python::dict const & segmentMappingDict, uint8_t useTempBlock)
|
boost::python::dict const & segmentMappingDict, uint8_t useTempBlock)
|
||||||
{
|
{
|
||||||
@@ -139,6 +144,13 @@ std::vector<uint8_t> GenerateTrafficValues(std::vector<traffic::TrafficInfo::Roa
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO Inherited from MWM/OM, no longer works with TraFF logic (API logic changed).
|
||||||
|
* We no longer separate keys (segments IDs) from values (their speed groups), nor do we store
|
||||||
|
* either in binary files: Segment/speed group pairs are generated from TraFF data and cached in
|
||||||
|
* XML format (using a custom extension to TraFF).
|
||||||
|
* See if we can refactor this into something meaningful and useful, else remove.
|
||||||
|
*/
|
||||||
std::vector<uint8_t> GenerateTrafficValuesFromList(boost::python::list const & keys,
|
std::vector<uint8_t> GenerateTrafficValuesFromList(boost::python::list const & keys,
|
||||||
boost::python::dict const & segmentMappingDict)
|
boost::python::dict const & segmentMappingDict)
|
||||||
{
|
{
|
||||||
@@ -148,6 +160,13 @@ std::vector<uint8_t> GenerateTrafficValuesFromList(boost::python::list const & k
|
|||||||
return GenerateTrafficValues(keysVec, segmentMappingDict, 1 /* useTempBlock */);
|
return GenerateTrafficValues(keysVec, segmentMappingDict, 1 /* useTempBlock */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO Inherited from MWM/OM, no longer works with TraFF logic (API logic changed).
|
||||||
|
* We no longer separate keys (segments IDs) from values (their speed groups), nor do we store
|
||||||
|
* either in binary files: Segment/speed group pairs are generated from TraFF data and cached in
|
||||||
|
* XML format (using a custom extension to TraFF).
|
||||||
|
* See if we can refactor this into something meaningful and useful, else remove.
|
||||||
|
*/
|
||||||
std::vector<uint8_t> GenerateTrafficValuesFromBinary(std::vector<uint8_t> const & keysBlob,
|
std::vector<uint8_t> GenerateTrafficValuesFromBinary(std::vector<uint8_t> const & keysBlob,
|
||||||
boost::python::dict const & segmentMappingDict,
|
boost::python::dict const & segmentMappingDict,
|
||||||
uint8_t useTempBlock = 1)
|
uint8_t useTempBlock = 1)
|
||||||
@@ -201,7 +220,9 @@ BOOST_PYTHON_MODULE(pytraffic)
|
|||||||
|
|
||||||
def("load_classificator", LoadClassificator);
|
def("load_classificator", LoadClassificator);
|
||||||
def("generate_traffic_keys", GenerateTrafficKeys);
|
def("generate_traffic_keys", GenerateTrafficKeys);
|
||||||
|
// TODO obsolete, see function definition
|
||||||
def("generate_traffic_values_from_list", GenerateTrafficValuesFromList);
|
def("generate_traffic_values_from_list", GenerateTrafficValuesFromList);
|
||||||
|
// TODO obsolete, see function definition
|
||||||
def("generate_traffic_values_from_binary", GenerateTrafficValuesFromBinary,
|
def("generate_traffic_values_from_binary", GenerateTrafficValuesFromBinary,
|
||||||
(arg("keysBlob"), arg("segmentMappingDict"), arg("useTempBlock") = 1));
|
(arg("keysBlob"), arg("segmentMappingDict"), arg("useTempBlock") = 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,70 +125,6 @@ void TrafficInfo::CombineColorings(vector<TrafficInfo::RoadSegmentId> const & ke
|
|||||||
ASSERT_EQUAL(numUnexpectedKeys, 0, ());
|
ASSERT_EQUAL(numUnexpectedKeys, 0, ());
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
|
||||||
void TrafficInfo::SerializeTrafficKeys(vector<RoadSegmentId> const & keys, vector<uint8_t> & result)
|
|
||||||
{
|
|
||||||
vector<uint32_t> fids;
|
|
||||||
vector<size_t> numSegs;
|
|
||||||
vector<bool> oneWay;
|
|
||||||
for (size_t i = 0; i < keys.size();)
|
|
||||||
{
|
|
||||||
size_t j = i;
|
|
||||||
while (j < keys.size() && keys[i].m_fid == keys[j].m_fid)
|
|
||||||
++j;
|
|
||||||
|
|
||||||
bool ow = true;
|
|
||||||
for (size_t k = i; k < j; ++k)
|
|
||||||
{
|
|
||||||
if (keys[k].m_dir == RoadSegmentId::kReverseDirection)
|
|
||||||
{
|
|
||||||
ow = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto const numDirs = ow ? 1 : 2;
|
|
||||||
size_t numSegsForThisFid = j - i;
|
|
||||||
CHECK_GREATER(numDirs, 0, ());
|
|
||||||
CHECK_EQUAL(numSegsForThisFid % numDirs, 0, ());
|
|
||||||
numSegsForThisFid /= numDirs;
|
|
||||||
|
|
||||||
fids.push_back(keys[i].m_fid);
|
|
||||||
numSegs.push_back(numSegsForThisFid);
|
|
||||||
oneWay.push_back(ow);
|
|
||||||
|
|
||||||
i = j;
|
|
||||||
}
|
|
||||||
|
|
||||||
MemWriter<vector<uint8_t>> memWriter(result);
|
|
||||||
WriteToSink(memWriter, kLatestKeysVersion);
|
|
||||||
WriteVarUint(memWriter, fids.size());
|
|
||||||
|
|
||||||
{
|
|
||||||
BitWriter<decltype(memWriter)> bitWriter(memWriter);
|
|
||||||
|
|
||||||
uint32_t prevFid = 0;
|
|
||||||
for (auto const & fid : fids)
|
|
||||||
{
|
|
||||||
uint64_t const fidDiff = static_cast<uint64_t>(fid - prevFid);
|
|
||||||
bool ok = coding::GammaCoder::Encode(bitWriter, fidDiff + 1);
|
|
||||||
ASSERT(ok, ());
|
|
||||||
UNUSED_VALUE(ok);
|
|
||||||
prevFid = fid;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto const & s : numSegs)
|
|
||||||
{
|
|
||||||
bool ok = coding::GammaCoder::Encode(bitWriter, s + 1);
|
|
||||||
ASSERT(ok, ());
|
|
||||||
UNUSED_VALUE(ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto const val : oneWay)
|
|
||||||
bitWriter.Write(val ? 1 : 0, 1 /* numBits */);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void TrafficInfo::DeserializeTrafficKeys(vector<uint8_t> const & data, vector<TrafficInfo::RoadSegmentId> & result)
|
void TrafficInfo::DeserializeTrafficKeys(vector<uint8_t> const & data, vector<TrafficInfo::RoadSegmentId> & result)
|
||||||
{
|
{
|
||||||
@@ -261,53 +197,6 @@ void TrafficInfo::SerializeTrafficValues(vector<SpeedGroup> const & values, vect
|
|||||||
deflate(buf.data(), buf.size(), back_inserter(result));
|
deflate(buf.data(), buf.size(), back_inserter(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
|
||||||
void TrafficInfo::DeserializeTrafficValues(vector<uint8_t> const & data, vector<SpeedGroup> & result)
|
|
||||||
{
|
|
||||||
using Inflate = coding::ZLib::Inflate;
|
|
||||||
|
|
||||||
vector<uint8_t> decompressedData;
|
|
||||||
|
|
||||||
Inflate inflate(Inflate::Format::ZLib);
|
|
||||||
inflate(data.data(), data.size(), back_inserter(decompressedData));
|
|
||||||
|
|
||||||
MemReaderWithExceptions memReader(decompressedData.data(), decompressedData.size());
|
|
||||||
ReaderSource<decltype(memReader)> src(memReader);
|
|
||||||
|
|
||||||
auto const version = ReadPrimitiveFromSource<uint8_t>(src);
|
|
||||||
CHECK_EQUAL(version, kLatestValuesVersion, ("Unsupported version of traffic keys."));
|
|
||||||
|
|
||||||
auto const n = ReadVarUint<uint32_t>(src);
|
|
||||||
result.resize(n);
|
|
||||||
BitReader<decltype(src)> bitReader(src);
|
|
||||||
for (size_t i = 0; i < static_cast<size_t>(n); ++i)
|
|
||||||
{
|
|
||||||
// SpeedGroup's values fit into 3 bits.
|
|
||||||
result[i] = static_cast<SpeedGroup>(bitReader.Read(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT_EQUAL(src.Size(), 0, ());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TrafficInfo::UpdateTrafficData(vector<SpeedGroup> const & values)
|
|
||||||
{
|
|
||||||
m_coloring.clear();
|
|
||||||
|
|
||||||
if (m_keys.size() != values.size())
|
|
||||||
{
|
|
||||||
LOG(LWARNING, ("The number of received traffic values does not correspond to the number of keys:", m_keys.size(),
|
|
||||||
"keys", values.size(), "values."));
|
|
||||||
m_availability = Availability::NoData;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < m_keys.size(); ++i)
|
|
||||||
if (values[i] != SpeedGroup::Unknown)
|
|
||||||
m_coloring.emplace(m_keys[i], values[i]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
string DebugPrint(TrafficInfo::RoadSegmentId const & id)
|
string DebugPrint(TrafficInfo::RoadSegmentId const & id)
|
||||||
{
|
{
|
||||||
string const dir = id.m_dir == TrafficInfo::RoadSegmentId::kForwardDirection ? "Forward" : "Backward";
|
string const dir = id.m_dir == TrafficInfo::RoadSegmentId::kForwardDirection ? "Forward" : "Backward";
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Extracts RoadSegmentIds from an MWM and stores them in a sorted order.
|
* @brief Extracts RoadSegmentIds from an MWM and stores them in a sorted order.
|
||||||
* @param mwmPath Path to the MWM file
|
* @param mwmPath Path to the MWM file
|
||||||
|
*
|
||||||
|
* @todo We don’t need this any longer as the API has been reworked: We no longer separate keys
|
||||||
|
* (segment IDs) from values (their speed groups) and no longer have a use case for retrieving a
|
||||||
|
* list of all possible segment IDs – rather, we decode TraFF messages into segments, or have a
|
||||||
|
* cached list of the segments affected by a particular message. However, pytraffic still has some
|
||||||
|
* references to this function. We need to clean those up first, then we can delete this function.
|
||||||
*/
|
*/
|
||||||
static void ExtractTrafficKeys(std::string const & mwmPath, std::vector<RoadSegmentId> & result);
|
static void ExtractTrafficKeys(std::string const & mwmPath, std::vector<RoadSegmentId> & result);
|
||||||
|
|
||||||
@@ -150,15 +156,14 @@ public:
|
|||||||
// Serializes the keys of the coloring map to |result|.
|
// Serializes the keys of the coloring map to |result|.
|
||||||
// The keys are road segments ids which do not change during
|
// The keys are road segments ids which do not change during
|
||||||
// an mwm's lifetime so there's no point in downloading them every time.
|
// an mwm's lifetime so there's no point in downloading them every time.
|
||||||
// todo(@m) Document the format.
|
/*
|
||||||
static void SerializeTrafficKeys(std::vector<RoadSegmentId> const & keys, std::vector<uint8_t> & result);
|
* TODO We don’t need these any longer as the format is obsolete, but pytraffic still has some
|
||||||
|
* references to these. We need to clean those up first, then we can delete these functions.
|
||||||
|
*/
|
||||||
static void DeserializeTrafficKeys(std::vector<uint8_t> const & data, std::vector<RoadSegmentId> & result);
|
static void DeserializeTrafficKeys(std::vector<uint8_t> const & data, std::vector<RoadSegmentId> & result);
|
||||||
|
|
||||||
static void SerializeTrafficValues(std::vector<SpeedGroup> const & values, std::vector<uint8_t> & result);
|
static void SerializeTrafficValues(std::vector<SpeedGroup> const & values, std::vector<uint8_t> & result);
|
||||||
|
|
||||||
static void DeserializeTrafficValues(std::vector<uint8_t> const & data, std::vector<SpeedGroup> & result);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief Result of the last request to the server.
|
* @brief Result of the last request to the server.
|
||||||
@@ -175,11 +180,6 @@ private:
|
|||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
friend void UnitTest_TrafficInfo_UpdateTrafficData();
|
|
||||||
|
|
||||||
// Updates the coloring and changes the availability status if needed.
|
|
||||||
bool UpdateTrafficData(std::vector<SpeedGroup> const & values);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The mapping from feature segments to speed groups (see speed_groups.hpp).
|
* @brief The mapping from feature segments to speed groups (see speed_groups.hpp).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -37,7 +37,11 @@ protected:
|
|||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
/// @todo Need TRAFFIC_DATA_BASE_URL for this test.
|
/*
|
||||||
|
* TODO Inherited from MWM/OM, no longer works with TraFF logic (API logic changed).
|
||||||
|
* Leaving it here for now, maybe we can derive some TraFF tests from it.
|
||||||
|
* This tests retrieval of traffic information from the server.
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
UNIT_TEST(TrafficInfo_RemoteFile)
|
UNIT_TEST(TrafficInfo_RemoteFile)
|
||||||
{
|
{
|
||||||
@@ -69,6 +73,13 @@ UNIT_TEST(TrafficInfo_RemoteFile)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO Inherited from MWM/OM, no longer works with TraFF logic (API logic changed).
|
||||||
|
* Leaving it here for now, maybe we can derive some TraFF tests from it.
|
||||||
|
* This tests serialization of traffic data to files and reading it back, results should be
|
||||||
|
* identical and satisfy whatever constraints there are in the app.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
UNIT_TEST(TrafficInfo_Serialization)
|
UNIT_TEST(TrafficInfo_Serialization)
|
||||||
{
|
{
|
||||||
TrafficInfo::Coloring coloring = {
|
TrafficInfo::Coloring coloring = {
|
||||||
@@ -114,7 +125,14 @@ UNIT_TEST(TrafficInfo_Serialization)
|
|||||||
TEST_EQUAL(values, deserializedValues, ());
|
TEST_EQUAL(values, deserializedValues, ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO Inherited from MWM/OM, no longer works with TraFF logic (API logic changed).
|
||||||
|
* Leaving it here for now, maybe we can derive some TraFF tests from it.
|
||||||
|
* This tests processing of updated traffic data.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
UNIT_TEST(TrafficInfo_UpdateTrafficData)
|
UNIT_TEST(TrafficInfo_UpdateTrafficData)
|
||||||
{
|
{
|
||||||
vector<TrafficInfo::RoadSegmentId> const keys = {
|
vector<TrafficInfo::RoadSegmentId> const keys = {
|
||||||
@@ -147,4 +165,5 @@ UNIT_TEST(TrafficInfo_UpdateTrafficData)
|
|||||||
for (size_t i = 0; i < keys.size(); ++i)
|
for (size_t i = 0; i < keys.size(); ++i)
|
||||||
TEST_EQUAL(info.GetSpeedGroup(keys[i]), values2[i], ());
|
TEST_EQUAL(info.GetSpeedGroup(keys[i]), values2[i], ());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
} // namespace traffic
|
} // namespace traffic
|
||||||
|
|||||||
Reference in New Issue
Block a user