diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2019-06-07 16:16:15 +0300 |
---|---|---|
committer | Maksim Andrianov <maksimandrianov1@gmail.com> | 2019-06-11 15:25:19 +0300 |
commit | 7817da0d7fa4a78cce595d7897900b9ce75fa2eb (patch) | |
tree | 50ff8e6b15735d4987202f983def9c7f240896f5 /generator | |
parent | be760427c86a6202dee140bb6ca5f09b07fff736 (diff) |
[generator][promo] The type sponsored-promo_catalog is added into cities.
Diffstat (limited to 'generator')
-rw-r--r-- | generator/CMakeLists.txt | 1 | ||||
-rw-r--r-- | generator/booking_quality_check/booking_quality_check.cpp | 8 | ||||
-rw-r--r-- | generator/emitter_country.cpp | 5 | ||||
-rw-r--r-- | generator/emitter_world.cpp | 1 | ||||
-rw-r--r-- | generator/feature_merger.cpp | 30 | ||||
-rw-r--r-- | generator/feature_processing_layers.cpp | 27 | ||||
-rw-r--r-- | generator/feature_processing_layers.hpp | 13 | ||||
-rw-r--r-- | generator/generate_info.hpp | 5 | ||||
-rw-r--r-- | generator/generator_tool/CMakeLists.txt | 2 | ||||
-rw-r--r-- | generator/generator_tool/generator_tool.cpp | 11 | ||||
-rw-r--r-- | generator/promo_catalog_cities.hpp | 57 |
11 files changed, 136 insertions, 24 deletions
diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index ef398f1541..1d7e9841ce 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -137,6 +137,7 @@ set(SRC place_node.hpp platform_helpers.cpp platform_helpers.hpp + promo_catalog_cities.hpp ratings_section_builder.cpp ratings_section_builder.hpp relation_tags.cpp diff --git a/generator/booking_quality_check/booking_quality_check.cpp b/generator/booking_quality_check/booking_quality_check.cpp index eae80da913..699824f225 100644 --- a/generator/booking_quality_check/booking_quality_check.cpp +++ b/generator/booking_quality_check/booking_quality_check.cpp @@ -107,8 +107,8 @@ base::GeoObjectId ReadDebuggedPrintedOsmId(string const & str) GenerateInfo GetGenerateInfo() { GenerateInfo info; - info.m_bookingDatafileName = FLAGS_booking; - info.m_opentableDatafileName = FLAGS_opentable; + info.m_bookingDataFilename = FLAGS_booking; + info.m_opentableDataFilename = FLAGS_opentable; info.m_osmFileName = FLAGS_osm; info.SetNodeStorageType("map"); info.SetOsmFileType("o5m"); @@ -309,13 +309,13 @@ string GetDatasetFilePath(GenerateInfo const & info); template <> string GetDatasetFilePath<BookingDataset>(GenerateInfo const & info) { - return info.m_bookingDatafileName; + return info.m_bookingDataFilename; } template <> string GetDatasetFilePath<OpentableDataset>(GenerateInfo const & info) { - return info.m_opentableDatafileName; + return info.m_opentableDataFilename; } template <typename Dataset, typename Object = typename Dataset::Object> diff --git a/generator/emitter_country.cpp b/generator/emitter_country.cpp index 6ccfc3c42f..281bdf811c 100644 --- a/generator/emitter_country.cpp +++ b/generator/emitter_country.cpp @@ -22,9 +22,10 @@ EmitterCountry::EmitterCountry(feature::GenerateInfo const & info) { m_processingChain = std::make_shared<RepresentationLayer>(m_cityBoundaryProcessor); m_processingChain->Add(std::make_shared<PrepareFeatureLayer>()); + m_processingChain->Add(std::make_shared<PromoCatalogLayer>(info.m_promoCatalogCitiesFilename)); m_processingChain->Add(std::make_shared<CityBoundaryLayer>(m_cityBoundaryProcessor)); - m_processingChain->Add(std::make_shared<BookingLayer>(info.m_bookingDatafileName, m_countryMapper)); - m_processingChain->Add(std::make_shared<OpentableLayer>(info.m_opentableDatafileName, m_countryMapper)); + m_processingChain->Add(std::make_shared<BookingLayer>(info.m_bookingDataFilename, m_countryMapper)); + m_processingChain->Add(std::make_shared<OpentableLayer>(info.m_opentableDataFilename, m_countryMapper)); m_processingChain->Add(std::make_shared<CountryMapperLayer>(m_countryMapper)); if (info.m_emitCoasts) diff --git a/generator/emitter_world.cpp b/generator/emitter_world.cpp index c46a9c5da5..4ded6c347f 100644 --- a/generator/emitter_world.cpp +++ b/generator/emitter_world.cpp @@ -22,6 +22,7 @@ EmitterWorld::EmitterWorld(feature::GenerateInfo const & info) { m_processingChain = std::make_shared<RepresentationLayer>(m_cityBoundaryProcessor); m_processingChain->Add(std::make_shared<PrepareFeatureLayer>()); + m_processingChain->Add(std::make_shared<PromoCatalogLayer>(info.m_promoCatalogCitiesFilename)); m_processingChain->Add(std::make_shared<CityBoundaryLayer>(m_cityBoundaryProcessor)); m_processingChain->Add(std::make_shared<WorldAreaLayer>(m_worldMapper)); } diff --git a/generator/feature_merger.cpp b/generator/feature_merger.cpp index 546bb75bad..703d86703b 100644 --- a/generator/feature_merger.cpp +++ b/generator/feature_merger.cpp @@ -4,6 +4,8 @@ #include "indexer/feature_algo.hpp" #include "indexer/feature_visibility.hpp" +#include "indexer/ftypes_sponsored.hpp" + #include "coding/point_coding.hpp" using namespace feature; @@ -327,14 +329,18 @@ MergedFeatureBuilder1 * FeatureTypesProcessor::operator() (FeatureBuilder const namespace feature { -class IsInvisibleFn +class RemoveSolver { int m_lowScale, m_upScale; - bool m_leaveSpecialTypes; + bool m_doNotRemoveSpecialTypes; + bool m_doNotRemoveSponsoredTypes; public: - IsInvisibleFn(int lowScale, int upScale, bool leaveSpecialTypes) - : m_lowScale(lowScale), m_upScale(upScale), m_leaveSpecialTypes(leaveSpecialTypes) + RemoveSolver(int lowScale, int upScale, bool leaveSpecialTypes, bool leaveSponsoredTypes = true) + : m_lowScale(lowScale), + m_upScale(upScale), + m_doNotRemoveSpecialTypes(leaveSpecialTypes), + m_doNotRemoveSponsoredTypes(leaveSponsoredTypes) { } @@ -342,17 +348,20 @@ public: { std::pair<int, int> const range = feature::GetDrawableScaleRange(type); + if (m_doNotRemoveSponsoredTypes && ftypes::IsSponsoredChecker::Instance()(type)) + return false; // We have feature types without any drawing rules. // This case was processed before: // - feature::TypeAlwaysExists; // - FeatureBuilder::RemoveInvalidTypes; // Don't delete them here. - if (m_leaveSpecialTypes && range.first == -1) + if (m_doNotRemoveSpecialTypes && range.first == -1) { ASSERT(range.second == -1, ()); return false; } + // Remove when |type| is invisible. return (range.first == -1 || (range.first > m_upScale || range.second < m_lowScale)); } }; @@ -361,7 +370,7 @@ bool PreprocessForWorldMap(FeatureBuilder & fb) { int const upperScale = scales::GetUpperWorldScale(); - if (fb.RemoveTypesIf(IsInvisibleFn(0, upperScale, false))) + if (fb.RemoveTypesIf(RemoveSolver(0, upperScale, false))) return false; fb.RemoveNameIfInvisible(0, upperScale); @@ -371,14 +380,11 @@ bool PreprocessForWorldMap(FeatureBuilder & fb) bool PreprocessForCountryMap(FeatureBuilder & fb) { - if (fb.RemoveTypesIf(IsInvisibleFn(scales::GetUpperWorldScale() + 1, - scales::GetUpperStyleScale(), - true))) - { + using namespace scales; + + if (fb.RemoveTypesIf(RemoveSolver(GetUpperWorldScale() + 1, GetUpperStyleScale(), true))) return false; - } return true; } - } diff --git a/generator/feature_processing_layers.cpp b/generator/feature_processing_layers.cpp index 0c8aaac5e2..6f5cb44bb7 100644 --- a/generator/feature_processing_layers.cpp +++ b/generator/feature_processing_layers.cpp @@ -8,6 +8,7 @@ #include "generator/emitter_interface.hpp" #include "generator/type_helper.hpp" +#include "indexer/classificator.hpp" #include "indexer/feature_visibility.hpp" #include "indexer/ftypes_matcher.hpp" @@ -243,6 +244,32 @@ void OpentableLayer::Handle(FeatureBuilder & feature) }); } + +PromoCatalogLayer::PromoCatalogLayer(std::string const & filename) + : m_cities(promo::LoadCities(filename)) +{ +} + +void PromoCatalogLayer::Handle(FeatureBuilder & feature) +{ + if (ftypes::IsCityTownOrVillage(feature.GetTypes())) + { + auto const & ids = feature.GetOsmIds(); + + auto const found = std::any_of(ids.cbegin(), ids.cend(), [this](auto const & id) + { + return m_cities.find(id) != m_cities.cend(); + }); + + if (!found) + return; + + FeatureParams & params = feature.GetParams(); + params.AddType(classif().GetTypeByPath({"sponsored", "promo_catalog"})); + } + LayerBase::Handle(feature); +} + CountryMapperLayer::CountryMapperLayer(std::shared_ptr<CountryMapper> countryMapper) : m_countryMapper(countryMapper) {} diff --git a/generator/feature_processing_layers.hpp b/generator/feature_processing_layers.hpp index a05988a81c..8a1bfd869a 100644 --- a/generator/feature_processing_layers.hpp +++ b/generator/feature_processing_layers.hpp @@ -4,6 +4,7 @@ #include "generator/feature_generator.hpp" #include "generator/opentable_dataset.hpp" #include "generator/polygonizer.hpp" +#include "generator/promo_catalog_cities.hpp" #include "generator/world_map_generator.hpp" #include <memory> @@ -159,6 +160,18 @@ private: std::shared_ptr<CountryMapper> m_countryMapper; }; +class PromoCatalogLayer : public LayerBase +{ +public: + explicit PromoCatalogLayer(std::string const & filename); + + // LayerBase overrides: + void Handle(feature::FeatureBuilder & feature) override; + +private: + promo::Cities m_cities; +}; + // Responsibility of class CountryMapperLayer - mapping of features to countries. class CountryMapperLayer : public LayerBase { diff --git a/generator/generate_info.hpp b/generator/generate_info.hpp index 6c0d13cfba..9465203eff 100644 --- a/generator/generate_info.hpp +++ b/generator/generate_info.hpp @@ -44,8 +44,9 @@ struct GenerateInfo OsmSourceType m_osmFileType; std::string m_osmFileName; - std::string m_bookingDatafileName; - std::string m_opentableDatafileName; + std::string m_bookingDataFilename; + std::string m_opentableDataFilename; + std::string m_promoCatalogCitiesFilename; std::string m_brandsFilename; std::string m_brandsTranslationsFilename; diff --git a/generator/generator_tool/CMakeLists.txt b/generator/generator_tool/CMakeLists.txt index 6a81eca3bf..97063bdc66 100644 --- a/generator/generator_tool/CMakeLists.txt +++ b/generator/generator_tool/CMakeLists.txt @@ -22,7 +22,9 @@ omim_link_libraries( search storage editor + partners_api indexer + metrics platform geometry coding diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index e0ca667fec..bba4be7483 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -159,8 +159,10 @@ DEFINE_bool( DEFINE_bool(generate_maxspeed, false, "Generate section with maxspeed of road features."); // Sponsored-related. -DEFINE_string(booking_data, "", "Path to booking data in .tsv format."); -DEFINE_string(opentable_data, "", "Path to opentable data in .tsv format."); +DEFINE_string(booking_data, "", "Path to booking data in tsv format."); +DEFINE_string(opentable_data, "", "Path to opentable data in tsv format."); +DEFINE_string(promo_catalog_cities, "", + "Path to list geo object ids of cities which contain promo catalog in json format."); DEFINE_string(ugc_data, "", "Input UGC source database file name."); @@ -264,8 +266,9 @@ int GeneratorToolMain(int argc, char ** argv) genInfo.m_osmFileName = FLAGS_osm_file_name; genInfo.m_failOnCoasts = FLAGS_fail_on_coasts; genInfo.m_preloadCache = FLAGS_preload_cache; - genInfo.m_bookingDatafileName = FLAGS_booking_data; - genInfo.m_opentableDatafileName = FLAGS_opentable_data; + genInfo.m_bookingDataFilename = FLAGS_booking_data; + genInfo.m_opentableDataFilename = FLAGS_opentable_data; + genInfo.m_promoCatalogCitiesFilename = FLAGS_promo_catalog_cities; genInfo.m_popularPlacesFilename = FLAGS_popular_places_data; genInfo.m_brandsFilename = FLAGS_brands_data; genInfo.m_brandsTranslationsFilename = FLAGS_brands_translations_data; diff --git a/generator/promo_catalog_cities.hpp b/generator/promo_catalog_cities.hpp new file mode 100644 index 0000000000..3239156ada --- /dev/null +++ b/generator/promo_catalog_cities.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include "coding/file_reader.hpp" + +#include "base/geo_object_id.hpp" +#include "base/logging.hpp" + +#include <string> +#include <unordered_set> + +#include "3party/jansson/myjansson.hpp" + +namespace promo +{ +using Cities = std::unordered_set<base::GeoObjectId>; + +inline Cities LoadCities(std::string const & filename) +{ + std::string src; + try + { + FileReader reader(filename); + reader.ReadAsString(src); + } + catch (Reader::Exception const & e) + { + LOG(LERROR, (filename, e.Msg())); + return {}; + } + + Cities result; + try + { + base::Json root(src.c_str()); + auto const dataArray = json_object_get(root.get(), "data"); + + auto const size = json_array_size(dataArray); + + result.reserve(size); + for (size_t i = 0; i < size; ++i) + { + int64_t id = 0; + auto const obj = json_array_get(dataArray, i); + FromJSONObject(obj, "osmid", id); + + result.emplace(static_cast<uint64_t>(id)); + } + } + catch (base::Json::Exception const & e) + { + LOG(LERROR, (e.Msg())); + result.clear(); + } + + return result; +} +} // namespace promo |