diff --git a/libs/traffic/pytraffic/bindings.cpp b/libs/traffic/pytraffic/bindings.cpp index b2278e500..e6c197f8b 100644 --- a/libs/traffic/pytraffic/bindings.cpp +++ b/libs/traffic/pytraffic/bindings.cpp @@ -103,6 +103,11 @@ boost::python::list GenerateTrafficKeys(std::string const & mwmPath) 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 GenerateTrafficValues(std::vector const & keys, boost::python::dict const & segmentMappingDict, uint8_t useTempBlock) { @@ -139,6 +144,13 @@ std::vector GenerateTrafficValues(std::vector GenerateTrafficValuesFromList(boost::python::list const & keys, boost::python::dict const & segmentMappingDict) { @@ -148,6 +160,13 @@ std::vector GenerateTrafficValuesFromList(boost::python::list const & k 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 GenerateTrafficValuesFromBinary(std::vector const & keysBlob, boost::python::dict const & segmentMappingDict, uint8_t useTempBlock = 1) @@ -201,7 +220,9 @@ BOOST_PYTHON_MODULE(pytraffic) def("load_classificator", LoadClassificator); def("generate_traffic_keys", GenerateTrafficKeys); + // TODO obsolete, see function definition def("generate_traffic_values_from_list", GenerateTrafficValuesFromList); + // TODO obsolete, see function definition def("generate_traffic_values_from_binary", GenerateTrafficValuesFromBinary, (arg("keysBlob"), arg("segmentMappingDict"), arg("useTempBlock") = 1)); } diff --git a/libs/traffic/traffic_info.cpp b/libs/traffic/traffic_info.cpp index a036851bd..e6bb11b7a 100644 --- a/libs/traffic/traffic_info.cpp +++ b/libs/traffic/traffic_info.cpp @@ -125,70 +125,6 @@ void TrafficInfo::CombineColorings(vector const & ke ASSERT_EQUAL(numUnexpectedKeys, 0, ()); } -// static -void TrafficInfo::SerializeTrafficKeys(vector const & keys, vector & result) -{ - vector fids; - vector numSegs; - vector 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> memWriter(result); - WriteToSink(memWriter, kLatestKeysVersion); - WriteVarUint(memWriter, fids.size()); - - { - BitWriter bitWriter(memWriter); - - uint32_t prevFid = 0; - for (auto const & fid : fids) - { - uint64_t const fidDiff = static_cast(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 void TrafficInfo::DeserializeTrafficKeys(vector const & data, vector & result) { @@ -261,53 +197,6 @@ void TrafficInfo::SerializeTrafficValues(vector const & values, vect deflate(buf.data(), buf.size(), back_inserter(result)); } -// static -void TrafficInfo::DeserializeTrafficValues(vector const & data, vector & result) -{ - using Inflate = coding::ZLib::Inflate; - - vector decompressedData; - - Inflate inflate(Inflate::Format::ZLib); - inflate(data.data(), data.size(), back_inserter(decompressedData)); - - MemReaderWithExceptions memReader(decompressedData.data(), decompressedData.size()); - ReaderSource src(memReader); - - auto const version = ReadPrimitiveFromSource(src); - CHECK_EQUAL(version, kLatestValuesVersion, ("Unsupported version of traffic keys.")); - - auto const n = ReadVarUint(src); - result.resize(n); - BitReader bitReader(src); - for (size_t i = 0; i < static_cast(n); ++i) - { - // SpeedGroup's values fit into 3 bits. - result[i] = static_cast(bitReader.Read(3)); - } - - ASSERT_EQUAL(src.Size(), 0, ()); -} - -bool TrafficInfo::UpdateTrafficData(vector 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 const dir = id.m_dir == TrafficInfo::RoadSegmentId::kForwardDirection ? "Forward" : "Backward"; diff --git a/libs/traffic/traffic_info.hpp b/libs/traffic/traffic_info.hpp index 3c606b82e..8e1776135 100644 --- a/libs/traffic/traffic_info.hpp +++ b/libs/traffic/traffic_info.hpp @@ -126,6 +126,12 @@ public: /** * @brief Extracts RoadSegmentIds from an MWM and stores them in a sorted order. * @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 & result); @@ -150,15 +156,14 @@ public: // Serializes the keys of the coloring map to |result|. // 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. - // todo(@m) Document the format. - static void SerializeTrafficKeys(std::vector const & keys, std::vector & 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 const & data, std::vector & result); static void SerializeTrafficValues(std::vector const & values, std::vector & result); - static void DeserializeTrafficValues(std::vector const & data, std::vector & result); - private: /** * @brief Result of the last request to the server. @@ -175,11 +180,6 @@ private: Error, }; - friend void UnitTest_TrafficInfo_UpdateTrafficData(); - - // Updates the coloring and changes the availability status if needed. - bool UpdateTrafficData(std::vector const & values); - /** * @brief The mapping from feature segments to speed groups (see speed_groups.hpp). */ diff --git a/libs/traffic/traffic_tests/traffic_info_test.cpp b/libs/traffic/traffic_tests/traffic_info_test.cpp index 003ef0c97..b638f5dc0 100644 --- a/libs/traffic/traffic_tests/traffic_info_test.cpp +++ b/libs/traffic/traffic_tests/traffic_info_test.cpp @@ -37,7 +37,11 @@ protected: }; } // 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) { @@ -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) { TrafficInfo::Coloring coloring = { @@ -114,7 +125,14 @@ UNIT_TEST(TrafficInfo_Serialization) 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) { vector const keys = { @@ -147,4 +165,5 @@ UNIT_TEST(TrafficInfo_UpdateTrafficData) for (size_t i = 0; i < keys.size(); ++i) TEST_EQUAL(info.GetSpeedGroup(keys[i]), values2[i], ()); } +*/ } // namespace traffic