From 4c82857eae92adb83a6d94d8af2bf00e4ac5200f Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 18 Apr 2017 20:17:06 +0300 Subject: [PATCH 1/3] [core] local ads place page button --- indexer/CMakeLists.txt | 1 + indexer/ftypes_mapping.hpp | 70 +++++++++++++++++++ indexer/ftypes_matcher.hpp | 1 - indexer/indexer.pro | 2 +- map/framework.cpp | 17 ++++- map/local_ads_manager.cpp | 12 ++++ map/local_ads_manager.hpp | 11 ++- map/place_page_info.cpp | 2 + map/place_page_info.hpp | 14 ++++ partners_api/ads_base.cpp | 51 ++------------ partners_api/ads_base.hpp | 7 +- .../indexer/indexer.xcodeproj/project.pbxproj | 4 ++ 12 files changed, 137 insertions(+), 55 deletions(-) create mode 100644 indexer/ftypes_mapping.hpp diff --git a/indexer/CMakeLists.txt b/indexer/CMakeLists.txt index e3f074ff67..8dd95d83c2 100644 --- a/indexer/CMakeLists.txt +++ b/indexer/CMakeLists.txt @@ -70,6 +70,7 @@ set( features_offsets_table.hpp features_vector.cpp features_vector.hpp + ftypes_mapping.cpp ftypes_matcher.cpp ftypes_matcher.hpp geometry_coding.cpp diff --git a/indexer/ftypes_mapping.hpp b/indexer/ftypes_mapping.hpp new file mode 100644 index 0000000000..715afc8e9d --- /dev/null +++ b/indexer/ftypes_mapping.hpp @@ -0,0 +1,70 @@ +#pragma once + +#include "indexer/classificator.hpp" +#include "indexer/feature_data.hpp" + +#include +#include +#include +#include +#include + +namespace ftypes +{ +template +class Matcher +{ +public: + typename Container::const_iterator + Find(feature::TypesHolder const & types) const + { + for (auto const t : types) + { + for (auto level = ftype::GetLevel(t); level; --level) + { + auto truncatedType = t; + ftype::TruncValue(truncatedType, level); + auto const it = m_mapping.find(truncatedType); + + if (it != m_mapping.cend()) + return it; + } + } + + return m_mapping.cend(); + } + + bool IsValid(typename Container::const_iterator it) const + { + return it != m_mapping.cend(); + } + + bool Contains(feature::TypesHolder const & types) const + { + return IsValid(Find(types)); + } + + template + void Append(std::vector> const & types, Args ... args) + { + for (auto const & type : types) + { +#if defined(DEBUG) + feature::TypesHolder holder; + holder.Assign(classif().GetTypeByPath(type)); + ASSERT(Find(holder) == m_mapping.cend(), ("This type already exists", type)); +#endif + m_mapping.emplace(classif().GetTypeByPath(type), std::forward(args)...); + } + } + +private: + Container m_mapping; +}; + +template +using HashMap = Matcher>; + +template +using HashSet = Matcher>; +} // namespace ftypes diff --git a/indexer/ftypes_matcher.hpp b/indexer/ftypes_matcher.hpp index 763d8eeca4..2c42cd1f22 100644 --- a/indexer/ftypes_matcher.hpp +++ b/indexer/ftypes_matcher.hpp @@ -15,7 +15,6 @@ class FeatureType; namespace ftypes { - class BaseChecker { size_t const m_level; diff --git a/indexer/indexer.pro b/indexer/indexer.pro index 87345a9f12..2dfa56dbc6 100644 --- a/indexer/indexer.pro +++ b/indexer/indexer.pro @@ -97,6 +97,7 @@ HEADERS += \ feature_visibility.hpp \ features_offsets_table.hpp \ features_vector.hpp \ + ftypes_mapping.hpp \ ftypes_matcher.hpp \ geometry_coding.hpp \ geometry_serialization.hpp \ @@ -134,7 +135,6 @@ HEADERS += \ types_mapping.hpp \ unique_index.hpp \ - OTHER_FILES += drules_struct.proto SOURCES += drules_struct.pb.cc diff --git a/map/framework.cpp b/map/framework.cpp index 4abd9a1a4d..5b427920e2 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -415,9 +415,6 @@ Framework::Framework(FrameworkParams const & params) }) , m_lastReportedCountry(kInvalidCountryId) { - if (!params.m_disableLocalAds) - m_localAdsManager.Startup(); - m_startBackgroundTime = my::Timer::LocalTime(); // Restore map style before classificator loading @@ -451,6 +448,9 @@ Framework::Framework(FrameworkParams const & params) m_model.SetOnMapDeregisteredCallback(bind(&Framework::OnMapDeregistered, this, _1)); LOG(LDEBUG, ("Classificator initialized")); + if (!params.m_disableLocalAds) + m_localAdsManager.Startup(); + m_displayedCategories = make_unique(GetDefaultCategories()); // To avoid possible races - init country info getter once in constructor. @@ -932,6 +932,17 @@ void Framework::FillInfoFromFeatureType(FeatureType const & ft, place_page::Info info.m_localizedWifiString = m_stringsBundle.GetString("wifi"); info.m_localizedRatingString = m_stringsBundle.GetString("place_page_booking_rating"); + + if (m_localAdsManager.IsSupportedType(info.GetTypes())) + { + info.m_localAdsStatus = m_localAdsManager.Contains(ft.GetID()) + ? place_page::LocalAdsStatus::Customer + : place_page::LocalAdsStatus::Candidate; + } + else + { + info.m_localAdsStatus = place_page::LocalAdsStatus::Unavailable; + } } void Framework::FillApiMarkInfo(ApiMarkPoint const & api, place_page::Info & info) const diff --git a/map/local_ads_manager.cpp b/map/local_ads_manager.cpp index 1443cdf7c5..801fca7c63 100644 --- a/map/local_ads_manager.cpp +++ b/map/local_ads_manager.cpp @@ -8,6 +8,7 @@ #include "drape_frontend/drape_engine.hpp" #include "drape_frontend/visual_params.hpp" +#include "indexer/feature_data.hpp" #include "indexer/scales.hpp" #include "platform/http_client.hpp" @@ -141,6 +142,11 @@ std::vector SerializeLocalAdsToJSON(std::list const & return result; } #endif + +void FillExcludeTypes(ftypes::HashSet & excludeTypes) +{ + excludeTypes.Append({{"amenity", "bench"}}); +} } // namespace LocalAdsManager::LocalAdsManager(GetMwmsByRectFn const & getMwmsByRectFn, @@ -176,6 +182,7 @@ void LocalAdsManager::Startup() m_thread = threads::SimpleThread(&LocalAdsManager::ThreadRoutine, this); m_statistics.Startup(); + FillExcludeTypes(m_excludeTypes); } void LocalAdsManager::Teardown() @@ -449,3 +456,8 @@ bool LocalAdsManager::Contains(FeatureID const & featureId) const std::lock_guard lock(m_featuresCacheMutex); return m_featuresCache.find(featureId) != m_featuresCache.cend(); } + +bool LocalAdsManager::IsSupportedType(feature::TypesHolder const & types) const +{ + return !m_excludeTypes.Contains(types); +} diff --git a/map/local_ads_manager.hpp b/map/local_ads_manager.hpp index 97ac0c6958..cf6f801c9a 100644 --- a/map/local_ads_manager.hpp +++ b/map/local_ads_manager.hpp @@ -9,6 +9,7 @@ #include "geometry/rect2d.hpp" #include "geometry/screenbase.hpp" +#include "indexer/ftypes_mapping.hpp" #include "indexer/index.hpp" #include "indexer/mwm_set.hpp" @@ -24,7 +25,12 @@ namespace df { class DrapeEngine; -} // namespace df +} + +namespace feature +{ +class TypesHolder; +} class LocalAdsManager final { @@ -51,6 +57,7 @@ public: local_ads::Statistics const & GetStatistics() const { return m_statistics; } bool Contains(FeatureID const & featureId) const; + bool IsSupportedType(feature::TypesHolder const & types) const; private: enum class RequestType @@ -97,4 +104,6 @@ private: std::set m_featuresCache; mutable std::mutex m_featuresCacheMutex; + + ftypes::HashSet m_excludeTypes; }; diff --git a/map/place_page_info.cpp b/map/place_page_info.cpp index dbae446838..eed0db0662 100644 --- a/map/place_page_info.cpp +++ b/map/place_page_info.cpp @@ -215,4 +215,6 @@ bool Info::IsReachableByTaxi() const void Info::SetMercator(m2::PointD const & mercator) { m_mercator = mercator; } vector Info::GetRawTypes() const { return m_types.ToObjectNames(); } string const & Info::GetBookingSearchUrl() const { return m_bookingSearchUrl; } +LocalAdsStatus Info::GetLocalAdsStatus() const { return m_localAdsStatus; } +string const & Info::GetLocalAdsUrl() const { return m_localAdsUrl; } } // namespace place_page diff --git a/map/place_page_info.hpp b/map/place_page_info.hpp index 83098bfa5d..6681303a6d 100644 --- a/map/place_page_info.hpp +++ b/map/place_page_info.hpp @@ -32,6 +32,13 @@ enum class SponsoredType Geochat }; +enum class LocalAdsStatus +{ + Unavailable, + Candidate, + Customer +}; + class Info : public osm::MapObject { public: @@ -100,6 +107,10 @@ public: string const & GetBookingSearchUrl() const; + LocalAdsStatus GetLocalAdsStatus() const; + + string const & GetLocalAdsUrl() const; + /// Comes from API, shared links etc. string m_customName; /// If not empty, bookmark is bound to this place page. @@ -148,5 +159,8 @@ public: string m_bookingSearchUrl; /// Ads source. ads::Engine * m_adsEngine = nullptr; + + LocalAdsStatus m_localAdsStatus = LocalAdsStatus::Unavailable; + string m_localAdsUrl; }; } // namespace place_page diff --git a/partners_api/ads_base.cpp b/partners_api/ads_base.cpp index 0bb98c0483..0f8633b9b3 100644 --- a/partners_api/ads_base.cpp +++ b/partners_api/ads_base.cpp @@ -5,29 +5,6 @@ #include -namespace -{ -template -typename Container::const_iterator -FindType(feature::TypesHolder const & types, Container const & cont) -{ - for (auto const t : types) - { - for (auto level = ftype::GetLevel(t); level; --level) - { - auto truncatedType = t; - ftype::TruncValue(truncatedType, level); - auto const it = cont.find(truncatedType); - - if (it != cont.end()) - return it; - } - } - - return cont.cend(); -} -} // namespace - namespace ads { Container::Container() { AppendExcludedTypes({{"sponsored", "booking"}}); } @@ -35,30 +12,12 @@ Container::Container() { AppendExcludedTypes({{"sponsored", "booking"}}); } void Container::AppendEntry(std::vector> const & types, std::string const & id) { - for (auto const & type : types) - { -#if defined(DEBUG) - feature::TypesHolder holder; - holder.Assign(classif().GetTypeByPath(type)); - ASSERT(FindType(holder, m_typesToBanners) == m_typesToBanners.cend(), - ("Banner id for this type already exists", type)); -#endif - m_typesToBanners.emplace(classif().GetTypeByPath(type), id); - } + m_typesToBanners.Append(types, id); } void Container::AppendExcludedTypes(std::vector> const & types) { - for (auto const & type : types) - { -#if defined(DEBUG) - feature::TypesHolder holder; - holder.Assign(classif().GetTypeByPath(type)); - ASSERT(FindType(holder, m_excludedTypes) == m_excludedTypes.cend(), - ("Excluded banner type already exists")); -#endif - m_excludedTypes.emplace(classif().GetTypeByPath(type)); - } + m_excludedTypes.Append(types); } void Container::AppendSupportedCountries(std::vector const & countries) @@ -75,7 +34,7 @@ bool Container::HasBanner(feature::TypesHolder const & types, return false; } - return FindType(types, m_excludedTypes) == m_excludedTypes.cend(); + return !m_excludedTypes.Contains(types); } std::string Container::GetBannerId(feature::TypesHolder const & types, @@ -84,8 +43,8 @@ std::string Container::GetBannerId(feature::TypesHolder const & types, if (!HasBanner(types, countryId)) return {}; - auto const it = FindType(types, m_typesToBanners); - if (it != m_typesToBanners.cend()) + auto const it = m_typesToBanners.Find(types); + if (m_typesToBanners.IsValid(it)) return it->second; return GetBannerIdForOtherTypes(); diff --git a/partners_api/ads_base.hpp b/partners_api/ads_base.hpp index 69e228f35a..023439b43e 100644 --- a/partners_api/ads_base.hpp +++ b/partners_api/ads_base.hpp @@ -1,12 +1,13 @@ #pragma once +#include "indexer/ftypes_mapping.hpp" + #include "storage/index.hpp" #include "base/macros.hpp" #include #include -#include #include #include @@ -51,8 +52,8 @@ protected: void AppendSupportedCountries(std::vector const & countries); private: - std::unordered_map m_typesToBanners; - std::unordered_set m_excludedTypes; + ftypes::HashMap m_typesToBanners; + ftypes::HashSet m_excludedTypes; // All countries are supported when empty. std::unordered_set m_supportedCountries; diff --git a/xcode/indexer/indexer.xcodeproj/project.pbxproj b/xcode/indexer/indexer.xcodeproj/project.pbxproj index 721d9382d8..71ca52b3b3 100644 --- a/xcode/indexer/indexer.xcodeproj/project.pbxproj +++ b/xcode/indexer/indexer.xcodeproj/project.pbxproj @@ -58,6 +58,7 @@ 3D51BC421D5E4D3800F1FA8D /* libgenerator.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D51BC381D5E4C4300F1FA8D /* libgenerator.a */; }; 3D51BC431D5E4E2B00F1FA8D /* test_mwm_set.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56C74C2D1C749E8100B71B9F /* test_mwm_set.hpp */; }; 3D51BC451D5E4EBF00F1FA8D /* libsearch_tests_support.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D51BC441D5E4EBF00F1FA8D /* libsearch_tests_support.a */; }; + 3D74ABBC1EA67C1E0063A898 /* ftypes_mapping.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D74ABBB1EA67C1E0063A898 /* ftypes_mapping.hpp */; }; 3D928F671D50F9FE001670E0 /* index_helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D928F651D50F9FE001670E0 /* index_helpers.cpp */; }; 3D928F681D50F9FE001670E0 /* index_helpers.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D928F661D50F9FE001670E0 /* index_helpers.hpp */; }; 45C108B11E9CFE41000FE1F6 /* polyline_point_to_int64_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45C108AF1E9CFE3E000FE1F6 /* polyline_point_to_int64_test.cpp */; }; @@ -275,6 +276,7 @@ 3D51BC3E1D5E4C8800F1FA8D /* librouting.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = librouting.a; path = "../../../omim-xcode-build/Debug/librouting.a"; sourceTree = ""; }; 3D51BC401D5E4CFA00F1FA8D /* libtess2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtess2.a; path = "../../../omim-xcode-build/Debug/libtess2.a"; sourceTree = ""; }; 3D51BC441D5E4EBF00F1FA8D /* libsearch_tests_support.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libsearch_tests_support.a; path = "../../../omim-xcode-build/Debug/libsearch_tests_support.a"; sourceTree = ""; }; + 3D74ABBB1EA67C1E0063A898 /* ftypes_mapping.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ftypes_mapping.hpp; sourceTree = ""; }; 3D928F651D50F9FE001670E0 /* index_helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = index_helpers.cpp; sourceTree = ""; }; 3D928F661D50F9FE001670E0 /* index_helpers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = index_helpers.hpp; sourceTree = ""; }; 45C108AF1E9CFE3E000FE1F6 /* polyline_point_to_int64_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = polyline_point_to_int64_test.cpp; sourceTree = ""; }; @@ -637,6 +639,7 @@ 6753409C1A3F53CB00A0A8C3 /* indexer */ = { isa = PBXGroup; children = ( + 3D74ABBB1EA67C1E0063A898 /* ftypes_mapping.hpp */, 3D928F651D50F9FE001670E0 /* index_helpers.cpp */, 3D928F661D50F9FE001670E0 /* index_helpers.hpp */, 34664CEE1D49FEC1003D7096 /* altitude_loader.cpp */, @@ -818,6 +821,7 @@ 56C74C251C749E4700B71B9F /* search_string_utils.hpp in Headers */, 6753410C1A3F540F00A0A8C3 /* drawing_rule_def.hpp in Headers */, 675341001A3F540F00A0A8C3 /* cell_id.hpp in Headers */, + 3D74ABBC1EA67C1E0063A898 /* ftypes_mapping.hpp in Headers */, 670D04AD1B0BA8580013A7AC /* interval_index_101.hpp in Headers */, 67BC92F51D21476500A4A378 /* string_slice.hpp in Headers */, 675341271A3F540F00A0A8C3 /* features_vector.hpp in Headers */, From 8dcb02460fe20964065f298a4f92973c97d25b4d Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Wed, 19 Apr 2017 18:20:15 +0300 Subject: [PATCH 2/3] review fixes --- indexer/ftypes_mapping.hpp | 17 +-- map/CMakeLists.txt | 1 + map/framework.cpp | 15 ++- map/local_ads_manager.cpp | 24 +++- map/local_ads_manager.hpp | 7 +- map/local_ads_supported_types.cpp | 170 ++++++++++++++++++++++++ map/map.pro | 1 + map/place_page_info.hpp | 4 +- partners_api/ads_base.cpp | 13 +- partners_api/ads_base.hpp | 13 +- partners_api/rb_ads.cpp | 2 +- xcode/map/map.xcodeproj/project.pbxproj | 4 + 12 files changed, 236 insertions(+), 35 deletions(-) create mode 100644 map/local_ads_supported_types.cpp diff --git a/indexer/ftypes_mapping.hpp b/indexer/ftypes_mapping.hpp index 715afc8e9d..32dfb36008 100644 --- a/indexer/ftypes_mapping.hpp +++ b/indexer/ftypes_mapping.hpp @@ -15,8 +15,9 @@ template class Matcher { public: - typename Container::const_iterator - Find(feature::TypesHolder const & types) const + using ConstIterator = typename Container::const_iterator; + + ConstIterator Find(feature::TypesHolder const & types) const { for (auto const t : types) { @@ -34,7 +35,7 @@ public: return m_mapping.cend(); } - bool IsValid(typename Container::const_iterator it) const + bool IsValid(ConstIterator it) const { return it != m_mapping.cend(); } @@ -44,8 +45,8 @@ public: return IsValid(Find(types)); } - template - void Append(std::vector> const & types, Args ... args) + template + void Append(TypesPaths const & types, Args const & ... args) { for (auto const & type : types) { @@ -54,7 +55,7 @@ public: holder.Assign(classif().GetTypeByPath(type)); ASSERT(Find(holder) == m_mapping.cend(), ("This type already exists", type)); #endif - m_mapping.emplace(classif().GetTypeByPath(type), std::forward(args)...); + m_mapping.emplace(classif().GetTypeByPath(type), args...); } } @@ -63,8 +64,8 @@ private: }; template -using HashMap = Matcher>; +using HashMapMatcher = Matcher>; template -using HashSet = Matcher>; +using HashSetMatcher = Matcher>; } // namespace ftypes diff --git a/map/CMakeLists.txt b/map/CMakeLists.txt index 0d1b3f62c0..47a7e2eb54 100644 --- a/map/CMakeLists.txt +++ b/map/CMakeLists.txt @@ -45,6 +45,7 @@ set( gps_tracker.hpp local_ads_manager.cpp local_ads_manager.hpp + local_ads_supported_types.cpp mwm_tree.cpp mwm_tree.hpp mwm_url.cpp diff --git a/map/framework.cpp b/map/framework.cpp index 5b427920e2..fa70941677 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -935,13 +935,20 @@ void Framework::FillInfoFromFeatureType(FeatureType const & ft, place_page::Info if (m_localAdsManager.IsSupportedType(info.GetTypes())) { - info.m_localAdsStatus = m_localAdsManager.Contains(ft.GetID()) - ? place_page::LocalAdsStatus::Customer - : place_page::LocalAdsStatus::Candidate; + if (m_localAdsManager.Contains(ft.GetID())) + { + info.m_localAdsStatus = place_page::LocalAdsStatus::Customer; + info.m_localAdsUrl = m_localAdsManager.GetShowStatisticUrl(); + } + else + { + info.m_localAdsStatus = place_page::LocalAdsStatus::Candidate; + info.m_localAdsUrl = m_localAdsManager.GetStartCompanyUrl(); + } } else { - info.m_localAdsStatus = place_page::LocalAdsStatus::Unavailable; + info.m_localAdsStatus = place_page::LocalAdsStatus::NotAvailable; } } diff --git a/map/local_ads_manager.cpp b/map/local_ads_manager.cpp index 801fca7c63..d9c157dc07 100644 --- a/map/local_ads_manager.cpp +++ b/map/local_ads_manager.cpp @@ -36,6 +36,10 @@ std::string const kServerUrl = LOCAL_ADS_SERVER_URL; std::string const kCampaignFile = "local_ads_campaigns.dat"; std::string const kLocalAdsSymbolsFile = "local_ads_symbols.txt"; auto constexpr kWWanUpdateTimeout = std::chrono::hours(12); +// Dummy +std::string const kStartCompanyUrl = "https://maps.me"; +// Dummy +std::string const kShowStatisticUrl = "https://github.com/mapsme/omim/graphs/commit-activity"; void SerializeCampaign(FileWriter & writer, std::string const & countryName, LocalAdsManager::Timestamp const & ts, @@ -142,11 +146,6 @@ std::vector SerializeLocalAdsToJSON(std::list const & return result; } #endif - -void FillExcludeTypes(ftypes::HashSet & excludeTypes) -{ - excludeTypes.Append({{"amenity", "bench"}}); -} } // namespace LocalAdsManager::LocalAdsManager(GetMwmsByRectFn const & getMwmsByRectFn, @@ -179,10 +178,11 @@ void LocalAdsManager::Startup() return; m_isRunning = true; } + FillSupportedTypes(); + m_thread = threads::SimpleThread(&LocalAdsManager::ThreadRoutine, this); m_statistics.Startup(); - FillExcludeTypes(m_excludeTypes); } void LocalAdsManager::Teardown() @@ -459,5 +459,15 @@ bool LocalAdsManager::Contains(FeatureID const & featureId) const bool LocalAdsManager::IsSupportedType(feature::TypesHolder const & types) const { - return !m_excludeTypes.Contains(types); + return m_supportedTypes.Contains(types); +} + +std::string const & LocalAdsManager::GetStartCompanyUrl() const +{ + return kStartCompanyUrl; +} + +std::string const & LocalAdsManager::GetShowStatisticUrl() const +{ + return kShowStatisticUrl; } diff --git a/map/local_ads_manager.hpp b/map/local_ads_manager.hpp index cf6f801c9a..565b2f3aa0 100644 --- a/map/local_ads_manager.hpp +++ b/map/local_ads_manager.hpp @@ -59,6 +59,9 @@ public: bool Contains(FeatureID const & featureId) const; bool IsSupportedType(feature::TypesHolder const & types) const; + std::string const & GetStartCompanyUrl() const; + std::string const & GetShowStatisticUrl() const; + private: enum class RequestType { @@ -78,6 +81,8 @@ private: void UpdateFeaturesCache(df::CustomSymbols const & symbols); + void FillSupportedTypes(); + GetMwmsByRectFn m_getMwmsByRectFn; GetMwmIdByName m_getMwmIdByNameFn; @@ -105,5 +110,5 @@ private: std::set m_featuresCache; mutable std::mutex m_featuresCacheMutex; - ftypes::HashSet m_excludeTypes; + ftypes::HashSetMatcher m_supportedTypes; }; diff --git a/map/local_ads_supported_types.cpp b/map/local_ads_supported_types.cpp new file mode 100644 index 0000000000..18eb30e1df --- /dev/null +++ b/map/local_ads_supported_types.cpp @@ -0,0 +1,170 @@ +#include "map/local_ads_manager.hpp" + +#include + +void LocalAdsManager::FillSupportedTypes() +{ + m_supportedTypes.Append>>( + {{"amenity", "atm"}, + {"amenity", "bank"}, + {"amenity", "bar"}, + {"amenity", "bbq"}, + {"amenity", "bicycle_parking"}, + {"amenity", "bicycle_rental"}, + {"amenity", "brothel"}, + {"amenity", "bureau_de_change"}, + {"amenity", "cafe"}, + {"amenity", "car_rental"}, + {"amenity", "car_sharing"}, + {"amenity", "car_wash"}, + {"amenity", "casino"}, + {"amenity", "charging_station"}, + {"amenity", "childcare"}, + {"amenity", "cinema"}, + {"amenity", "clinic"}, + {"amenity", "college"}, + {"amenity", "community_centre"}, + {"amenity", "courthouse"}, + {"amenity", "dentist"}, + {"amenity", "doctors"}, + {"amenity", "fast_food"}, + {"amenity", "fuel"}, + {"amenity", "grave_yard"}, + {"amenity", "hospital"}, + {"amenity", "hunting_stand"}, + {"amenity", "kindergarten"}, + {"amenity", "library"}, + {"amenity", "marketplace"}, + {"amenity", "nightclub"}, + {"amenity", "parking"}, + {"amenity", "pharmacy"}, + {"amenity", "post_office"}, + {"amenity", "pub"}, + {"amenity", "public_bookcase"}, + {"amenity", "recycling"}, + {"amenity", "restaurant"}, + {"amenity", "school"}, + {"amenity", "shelter"}, + {"amenity", "taxi"}, + {"amenity", "telephone"}, + {"amenity", "theatre"}, + {"amenity", "toilets"}, + {"amenity", "townhall"}, + {"amenity", "university"}, + {"amenity", "vending_machine"}, + {"amenity", "veterinary"}, + {"amenity", "waste_disposal"}, + + {"craft", "brewery"}, + {"craft", "carpenter"}, + {"craft", "electrician"}, + {"craft", "gardener"}, + {"craft", "hvac"}, + {"craft", "metal_construction"}, + {"craft", "painter"}, + {"craft", "photographer"}, + {"craft", "plumber"}, + {"craft", "shoemaker"}, + {"craft", "tailor"}, + + {"historic", "castle"}, + {"historic", "museum"}, + {"historic", "ship"}, + + {"office", "company"}, + {"office", "estate_agent"}, + {"office", "government"}, + {"office", "lawyer"}, + {"office", "telecommunication"}, + + {"shop", "alcohol"}, + {"shop", "bakery"}, + {"shop", "beauty"}, + {"shop", "beverages"}, + {"shop", "bicycle"}, + {"shop", "bookmaker"}, + {"shop", "books"}, + {"shop", "butcher"}, + {"shop", "car"}, + {"shop", "car_parts"}, + {"shop", "car_repair"}, + {"shop", "chemist"}, + {"shop", "clothes"}, + {"shop", "computer"}, + {"shop", "confectionery"}, + {"shop", "convenience"}, + {"shop", "copyshop"}, + {"shop", "cosmetics"}, + {"shop", "department_store"}, + {"shop", "doityourself"}, + {"shop", "dry_cleaning"}, + {"shop", "electronics"}, + {"shop", "florist"}, + {"shop", "furniture"}, + {"shop", "garden_centre"}, + {"shop", "gift"}, + {"shop", "greengrocer"}, + {"shop", "hairdresser"}, + {"shop", "hardware"}, + {"shop", "jewelry"}, + {"shop", "kiosk"}, + {"shop", "laundry"}, + {"shop", "mall"}, + {"shop", "mobile_phone"}, + {"shop", "optician"}, + {"shop", "outdoor"}, + {"shop", "pet"}, + {"shop", "photo"}, + {"shop", "seafood"}, + {"shop", "shoes"}, + {"shop", "sports"}, + {"shop", "supermarket"}, + {"shop", "ticket"}, + {"shop", "toys"}, + {"shop", "travel_agency"}, + {"shop", "tyres"}, + {"shop", "wine"}, + + {"sponsored", "booking"}, + + {"sport", "american_football"}, + {"sport", "archery"}, + {"sport", "athletics"}, + {"sport", "australian_football"}, + {"sport", "baseball"}, + {"sport", "basketball"}, + {"sport", "bowls"}, + {"sport", "cricket"}, + {"sport", "curling"}, + {"sport", "diving"}, + {"sport", "equestrian"}, + {"sport", "football"}, + {"sport", "golf"}, + {"sport", "gymnastics"}, + {"sport", "handball"}, + {"sport", "multi"}, + {"sport", "scuba_diving"}, + {"sport", "shooting"}, + {"sport", "skiing"}, + {"sport", "soccer"}, + {"sport", "swimming"}, + {"sport", "tennis"}, + + {"tourism", "alpine_hut"}, + {"tourism", "apartment"}, + {"tourism", "artwork"}, + {"tourism", "attraction"}, + {"tourism", "camp_site"}, + {"tourism", "caravan_site"}, + {"tourism", "chalet"}, + {"tourism", "guest_house"}, + {"tourism", "hostel"}, + {"tourism", "hotel"}, + {"tourism", "information", "office"}, + {"tourism", "motel"}, + {"tourism", "museum"}, + {"tourism", "picnic_site"}, + {"tourism", "resort"}, + {"tourism", "viewpoint"}, + {"tourism", "zoo"}}); +} diff --git a/map/map.pro b/map/map.pro index a2f5626dbb..9254108a8f 100644 --- a/map/map.pro +++ b/map/map.pro @@ -56,6 +56,7 @@ SOURCES += \ gps_track_storage.cpp \ gps_tracker.cpp \ local_ads_manager.cpp \ + local_ads_supported_types.cpp \ mwm_tree.cpp \ mwm_url.cpp \ place_page_info.cpp \ diff --git a/map/place_page_info.hpp b/map/place_page_info.hpp index 6681303a6d..40f9d87dec 100644 --- a/map/place_page_info.hpp +++ b/map/place_page_info.hpp @@ -34,7 +34,7 @@ enum class SponsoredType enum class LocalAdsStatus { - Unavailable, + NotAvailable, Candidate, Customer }; @@ -160,7 +160,7 @@ public: /// Ads source. ads::Engine * m_adsEngine = nullptr; - LocalAdsStatus m_localAdsStatus = LocalAdsStatus::Unavailable; + LocalAdsStatus m_localAdsStatus = LocalAdsStatus::NotAvailable; string m_localAdsUrl; }; } // namespace place_page diff --git a/partners_api/ads_base.cpp b/partners_api/ads_base.cpp index 0f8633b9b3..7ed510c415 100644 --- a/partners_api/ads_base.cpp +++ b/partners_api/ads_base.cpp @@ -9,18 +9,20 @@ namespace ads { Container::Container() { AppendExcludedTypes({{"sponsored", "booking"}}); } -void Container::AppendEntry(std::vector> const & types, +void Container::AppendEntry(std::initializer_list> && types, std::string const & id) { - m_typesToBanners.Append(types, id); + m_typesToBanners.Append(std::move(types), id); } -void Container::AppendExcludedTypes(std::vector> const & types) +void Container::AppendExcludedTypes( + std::initializer_list> && types) { - m_excludedTypes.Append(types); + m_excludedTypes.Append(std::move(types)); } -void Container::AppendSupportedCountries(std::vector const & countries) +void Container::AppendSupportedCountries( + std::initializer_list const & countries) { m_supportedCountries.insert(countries.begin(), countries.end()); } @@ -33,7 +35,6 @@ bool Container::HasBanner(feature::TypesHolder const & types, { return false; } - return !m_excludedTypes.Contains(types); } diff --git a/partners_api/ads_base.hpp b/partners_api/ads_base.hpp index 023439b43e..d1e9b563ad 100644 --- a/partners_api/ads_base.hpp +++ b/partners_api/ads_base.hpp @@ -7,9 +7,9 @@ #include "base/macros.hpp" #include +#include #include #include -#include namespace feature { @@ -47,13 +47,14 @@ public: std::string GetSearchBannerId() const override; protected: - void AppendEntry(std::vector> const & types, std::string const & id); - void AppendExcludedTypes(std::vector> const & types); - void AppendSupportedCountries(std::vector const & countries); + void AppendEntry(std::initializer_list> && types, + std::string const & id); + void AppendExcludedTypes(std::initializer_list> && types); + void AppendSupportedCountries(std::initializer_list const & countries); private: - ftypes::HashMap m_typesToBanners; - ftypes::HashSet m_excludedTypes; + ftypes::HashMapMatcher m_typesToBanners; + ftypes::HashSetMatcher m_excludedTypes; // All countries are supported when empty. std::unordered_set m_supportedCountries; diff --git a/partners_api/rb_ads.cpp b/partners_api/rb_ads.cpp index 9d6b49948a..d2f358ae19 100644 --- a/partners_api/rb_ads.cpp +++ b/partners_api/rb_ads.cpp @@ -15,7 +15,7 @@ auto const kEntertainmentPlacementId = "9"; auto const kBuildingPlacementId = "11"; auto const kBannerIdForOtherTypes = "14"; -std::vector const kSupportedCountries = +std::initializer_list const kSupportedCountries = { "Azerbaijan Region", "Armenia", diff --git a/xcode/map/map.xcodeproj/project.pbxproj b/xcode/map/map.xcodeproj/project.pbxproj index 84124563e7..23a84f1636 100644 --- a/xcode/map/map.xcodeproj/project.pbxproj +++ b/xcode/map/map.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 34921F661BFA0A6900737D6E /* api_mark_point.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34921F611BFA0A6900737D6E /* api_mark_point.hpp */; }; 34DDA1811DBE5DF40088A609 /* libpartners_api.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 34DDA17F1DBE5DF40088A609 /* libpartners_api.a */; }; 34DDA1821DBE5DF40088A609 /* libtracking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 34DDA1801DBE5DF40088A609 /* libtracking.a */; }; + 3D74ABBE1EA76F1D0063A898 /* local_ads_supported_types.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D74ABBD1EA76F1D0063A898 /* local_ads_supported_types.cpp */; }; 45201E931CE4AC90008A4842 /* api_mark_point.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45201E921CE4AC90008A4842 /* api_mark_point.cpp */; }; 45580ABE1E2CBD5E00CD535D /* benchmark_tools.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45580ABC1E2CBD5E00CD535D /* benchmark_tools.cpp */; }; 45580ABF1E2CBD5E00CD535D /* benchmark_tools.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 45580ABD1E2CBD5E00CD535D /* benchmark_tools.hpp */; }; @@ -139,6 +140,7 @@ 34AF87EA1DBE5AD000E5E7DC /* common-release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "common-release.xcconfig"; path = "../common-release.xcconfig"; sourceTree = ""; }; 34DDA17F1DBE5DF40088A609 /* libpartners_api.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpartners_api.a; path = "/Users/igrechuhin/Repo/omim/xcode/partners_api/../../../omim-xcode-build/Debug/libpartners_api.a"; sourceTree = ""; }; 34DDA1801DBE5DF40088A609 /* libtracking.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libtracking.a; path = "/Users/igrechuhin/Repo/omim/xcode/tracking/../../../omim-xcode-build/Debug/libtracking.a"; sourceTree = ""; }; + 3D74ABBD1EA76F1D0063A898 /* local_ads_supported_types.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = local_ads_supported_types.cpp; sourceTree = ""; }; 45201E921CE4AC90008A4842 /* api_mark_point.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = api_mark_point.cpp; sourceTree = ""; }; 45580ABC1E2CBD5E00CD535D /* benchmark_tools.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = benchmark_tools.cpp; sourceTree = ""; }; 45580ABD1E2CBD5E00CD535D /* benchmark_tools.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = benchmark_tools.hpp; sourceTree = ""; }; @@ -413,6 +415,7 @@ 675345BD1A4054AD00A0A8C3 /* map */ = { isa = PBXGroup; children = ( + 3D74ABBD1EA76F1D0063A898 /* local_ads_supported_types.cpp */, 56B6EAF61EA4BAF00037D963 /* mwm_tree.cpp */, 56B6EAF71EA4BAF00037D963 /* mwm_tree.hpp */, 45580ABD1E2CBD5E00CD535D /* benchmark_tools.hpp */, @@ -620,6 +623,7 @@ 342D833A1D5233E8000D8AEA /* displacement_mode_manager.cpp in Sources */, 45201E931CE4AC90008A4842 /* api_mark_point.cpp in Sources */, 675346661A4054E800A0A8C3 /* ge0_parser.cpp in Sources */, + 3D74ABBE1EA76F1D0063A898 /* local_ads_supported_types.cpp in Sources */, 0C2B73DE1E92AB9900530BB8 /* local_ads_manager.cpp in Sources */, F6B283071C1B03320081957A /* gps_track_storage.cpp in Sources */, 6753463A1A4054E800A0A8C3 /* address_finder.cpp in Sources */, From dac491f63c86d2f18bfe4b27ef45ab78c3e42ce5 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Wed, 19 Apr 2017 18:46:11 +0300 Subject: [PATCH 3/3] local ads dummy pages --- configure.sh | 2 ++ map/local_ads_manager.cpp | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/configure.sh b/configure.sh index 93a7bd0a91..5a0c558e51 100755 --- a/configure.sh +++ b/configure.sh @@ -61,6 +61,8 @@ else #define TRAFFIC_DATA_BASE_URL "" #define LOCAL_ADS_SERVER_URL "" #define LOCAL_ADS_STATISTICS_SERVER_URL "" +#define LOCAL_ADS_START_COMPANY_PAGE_HOST "" +#define LOCAL_ADS_STATISTICS_PAGE_HOST "" ' > "$PRIVATE_HEADER" echo 'ext { spropStoreFile = "../tools/android/debug.keystore" diff --git a/map/local_ads_manager.cpp b/map/local_ads_manager.cpp index d9c157dc07..cd10055e7e 100644 --- a/map/local_ads_manager.cpp +++ b/map/local_ads_manager.cpp @@ -36,10 +36,6 @@ std::string const kServerUrl = LOCAL_ADS_SERVER_URL; std::string const kCampaignFile = "local_ads_campaigns.dat"; std::string const kLocalAdsSymbolsFile = "local_ads_symbols.txt"; auto constexpr kWWanUpdateTimeout = std::chrono::hours(12); -// Dummy -std::string const kStartCompanyUrl = "https://maps.me"; -// Dummy -std::string const kShowStatisticUrl = "https://github.com/mapsme/omim/graphs/commit-activity"; void SerializeCampaign(FileWriter & writer, std::string const & countryName, LocalAdsManager::Timestamp const & ts, @@ -464,10 +460,10 @@ bool LocalAdsManager::IsSupportedType(feature::TypesHolder const & types) const std::string const & LocalAdsManager::GetStartCompanyUrl() const { - return kStartCompanyUrl; + return LOCAL_ADS_START_COMPANY_PAGE_HOST; } std::string const & LocalAdsManager::GetShowStatisticUrl() const { - return kShowStatisticUrl; + return LOCAL_ADS_STATISTICS_PAGE_HOST; }