From 1e20743f0a61e78c7f3a609c4762f41fb6c6896b Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 31 Jul 2018 19:26:52 +0300 Subject: [PATCH] [indexer] popularity for place page --- indexer/CMakeLists.txt | 2 ++ indexer/popularity_loader.cpp | 32 ++++++++++++++++++++++++++++++++ indexer/popularity_loader.hpp | 27 +++++++++++++++++++++++++++ map/framework.cpp | 2 ++ map/framework.hpp | 3 +++ map/place_page_info.hpp | 5 +++++ 6 files changed, 71 insertions(+) create mode 100644 indexer/popularity_loader.cpp create mode 100644 indexer/popularity_loader.hpp diff --git a/indexer/CMakeLists.txt b/indexer/CMakeLists.txt index 1de418b156..e5ced6748c 100644 --- a/indexer/CMakeLists.txt +++ b/indexer/CMakeLists.txt @@ -97,6 +97,8 @@ set( map_style.hpp mwm_set.cpp mwm_set.hpp + popularity_loader.cpp + popularity_loader.hpp postcodes_matcher.cpp # it's in indexer due to editor which is in indexer and depends on postcodes_marcher postcodes_matcher.hpp # it's in indexer due to editor which is in indexer and depends on postcodes_marcher rank_table.cpp diff --git a/indexer/popularity_loader.cpp b/indexer/popularity_loader.cpp new file mode 100644 index 0000000000..14ffd700bd --- /dev/null +++ b/indexer/popularity_loader.cpp @@ -0,0 +1,32 @@ +#include "indexer/popularity_loader.hpp" + +#include "indexer/data_source.hpp" +#include "indexer/feature.hpp" + +#include "defines.hpp" + +CachingPopularityLoader::CachingPopularityLoader(DataSource const & dataSource) + : m_dataSource(dataSource) +{ +} + +uint8_t CachingPopularityLoader::Get(FeatureID const & featureId) const +{ + auto const handle = m_dataSource.GetMwmHandleById(featureId.m_mwmId); + + if (!handle.IsAlive()) + return {}; + + auto it = m_deserializers.find(featureId.m_mwmId); + + if (it == m_deserializers.end()) + { + auto rankTable = + search::RankTable::Load(handle.GetValue()->m_cont, POPULARITY_RANKS_FILE_TAG); + + auto const result = m_deserializers.emplace(featureId.m_mwmId, std::move(rankTable)); + it = result.first; + } + + return it->second->Get(featureId.m_index); +} diff --git a/indexer/popularity_loader.hpp b/indexer/popularity_loader.hpp new file mode 100644 index 0000000000..e6f941fed8 --- /dev/null +++ b/indexer/popularity_loader.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "indexer/mwm_set.hpp" +#include "indexer/rank_table.hpp" + +#include "base/macros.hpp" + +#include +#include +#include + +class DataSource; +struct FeatureID; + +// *NOTE* This class IS NOT thread-safe. +class CachingPopularityLoader +{ +public: + explicit CachingPopularityLoader(DataSource const & dataSource); + uint8_t Get(FeatureID const & featureId) const; + +private: + DataSource const & m_dataSource; + mutable std::map> m_deserializers; + + DISALLOW_COPY(CachingPopularityLoader); +}; diff --git a/map/framework.cpp b/map/framework.cpp index f45feb8d05..62ff6e1a94 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -387,6 +387,7 @@ Framework::Framework(FrameworkParams const & params) m_drapeEngine->SetDisplacementMode(mode); }) , m_lastReportedCountry(kInvalidCountryId) + , m_popularityLoader(m_model.GetDataSource()) { m_startBackgroundTime = my::Timer::LocalTime(); @@ -909,6 +910,7 @@ void Framework::FillInfoFromFeatureType(FeatureType & ft, place_page::Info & inf auto const latlon = MercatorBounds::ToLatLon(feature::GetCenter(ft)); ASSERT(m_taxiEngine, ()); info.SetReachableByTaxiProviders(m_taxiEngine->GetProvidersAtPos(latlon)); + info.SetPopularity(m_popularityLoader.Get(ft.GetID())); } void Framework::FillApiMarkInfo(ApiMarkPoint const & api, place_page::Info & info) const diff --git a/map/framework.hpp b/map/framework.hpp index d2f916309b..c7c3beec1c 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -38,6 +38,7 @@ #include "indexer/data_source.hpp" #include "indexer/data_source_helpers.hpp" #include "indexer/map_style.hpp" +#include "indexer/popularity_loader.hpp" #include "search/city_finder.hpp" #include "search/displayed_categories.hpp" @@ -522,6 +523,8 @@ private: void OnUpdateGpsTrackPointsCallback(vector> && toAdd, pair const & toRemove); + CachingPopularityLoader m_popularityLoader; + public: using TSearchRequest = search::QuerySaver::TSearchRequest; diff --git a/map/place_page_info.hpp b/map/place_page_info.hpp index d3c1628daa..a357d232a8 100644 --- a/map/place_page_info.hpp +++ b/map/place_page_info.hpp @@ -217,6 +217,9 @@ public: boost::optional GetHotelType() const { return m_hotelType; } + void SetPopularity(uint8_t popularity) { m_popularity = popularity; } + uint8_t GetPopularity() const { return m_popularity; } + private: std::string FormatSubtitle(bool withType) const; void GetPrefferedNames(std::string & primaryName, std::string & secondaryName) const; @@ -303,6 +306,8 @@ private: feature::TypesHolder m_sortedTypes; boost::optional m_hotelType; + + uint8_t m_popularity = 0; }; namespace rating