From 590bc06d181eaae9a6ad1ab735f7b1e2213dd112 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 10 Apr 2018 13:41:59 +0300 Subject: [PATCH] [taxi] places --- android/script/replace_links.bat | 3 + coding/serdes_json.hpp | 32 +++ data/taxi_places/maxim.json | 39 ++++ data/taxi_places/uber.json | 85 ++++++++ data/taxi_places/yandex.json | 134 +++++++++++++ iphone/Maps/Maps.xcodeproj/project.pbxproj | 4 + partners_api/CMakeLists.txt | 3 +- .../partners_api_tests/CMakeLists.txt | 1 + .../partners_api_tests/taxi_engine_tests.cpp | 24 ++- .../partners_api_tests/taxi_places_tests.cpp | 68 +++++++ partners_api/taxi_base.cpp | 26 +-- partners_api/taxi_base.hpp | 9 +- partners_api/taxi_engine.cpp | 15 +- partners_api/taxi_engine.hpp | 3 +- partners_api/taxi_places.cpp | 7 - partners_api/taxi_places.hpp | 23 ++- partners_api/taxi_places_constants.hpp | 186 ------------------ partners_api/taxi_places_loader.cpp | 62 ++++++ partners_api/taxi_places_loader.hpp | 26 +++ .../partners_api.xcodeproj/project.pbxproj | 14 +- 20 files changed, 526 insertions(+), 238 deletions(-) create mode 100644 data/taxi_places/maxim.json create mode 100644 data/taxi_places/uber.json create mode 100644 data/taxi_places/yandex.json create mode 100644 partners_api/partners_api_tests/taxi_places_tests.cpp delete mode 100644 partners_api/taxi_places_constants.hpp create mode 100644 partners_api/taxi_places_loader.cpp create mode 100644 partners_api/taxi_places_loader.hpp diff --git a/android/script/replace_links.bat b/android/script/replace_links.bat index c42217cab9..1c76f10a9d 100644 --- a/android/script/replace_links.bat +++ b/android/script/replace_links.bat @@ -25,6 +25,9 @@ cp ../data/types.txt assets/ cp ../data/unicode_blocks.txt assets/ cp ../data/opening_hours_how_to_edit.html assets/ cp ../data/ugc_types.csv assets/ +cp ../data/taxi_places/maxim.json assets/ +cp ../data/taxi_places/uber.json assets/ +cp ../data/taxi_places/yandex.json assets/ cp -r ../data/resources-hdpi_dark/ assets/ cp -r ../data/resources-hdpi_clear/ assets/ diff --git a/coding/serdes_json.hpp b/coding/serdes_json.hpp index 9fa9ca40c5..98b213c456 100644 --- a/coding/serdes_json.hpp +++ b/coding/serdes_json.hpp @@ -61,6 +61,15 @@ public: }); } + template + void operator()(std::unordered_set const & dest, char const * name = nullptr) + { + NewScopeWith(my::NewJSONArray(), name, [this, &dest] { + for (auto const & v : dest) + (*this)(v); + }); + } + template void operator()(R const & r, char const * name = nullptr) { @@ -173,6 +182,29 @@ public: RestoreContext(context); } + template + void operator()(std::unordered_set & dest, char const * name = nullptr) + { + json_t * context = SaveContext(name); + + if (!json_is_array(m_json)) + MYTHROW(my::Json::Exception, ("The field", name, "must contain a json array.")); + + T tmp; + size_t size = json_array_size(m_json); + dest.reserve(size); + for (size_t index = 0; index < size; ++index) + { + json_t * context = SaveContext(); + m_json = json_array_get(context, index); + (*this)(tmp); + dest.insert(tmp); + RestoreContext(context); + } + + RestoreContext(context); + } + template void operator()(R & r, char const * name = nullptr) { diff --git a/data/taxi_places/maxim.json b/data/taxi_places/maxim.json new file mode 100644 index 0000000000..5792029925 --- /dev/null +++ b/data/taxi_places/maxim.json @@ -0,0 +1,39 @@ +{ + "enabled": { + "countries": [ + { + "id": "Azerbaijan Region", + "cities": [ "Baku" ] + }, + { + "id": "Belarus", + "cities": [ "Baranovichi", "Mahilyow" ] + }, + { + "id": "Bulgaria", + "cities": [ "Varna", "Plovdiv", "Sofia" ] + }, + { + "id": "Georgia Region", + "cities": [ "Batumi", "Gori", "Zugdidi", "Kutaisi", "Poti" ] + }, + { + "id": "Kazakhstan", + "cities": [ "Kokshetau", "Semey", "Temirtau", "Oskemen" ] + } + ], + "mwms": [ + "Belarus_Brest Region", + "Belarus_Vitebsk Region", + "Ukraine_Poltava Oblast", + "Ukraine_Donetsk Oblast", + "Ukraine_Sumy Oblast", + "Ukraine_Cherkasy Oblast", + "Ukraine_Chernihiv Oblast" + ] + }, + "disabled": { + "countries": [], + "mwms": [] + } +} diff --git a/data/taxi_places/uber.json b/data/taxi_places/uber.json new file mode 100644 index 0000000000..eb24a70edb --- /dev/null +++ b/data/taxi_places/uber.json @@ -0,0 +1,85 @@ +{ + "enabled": { + "countries": [ + {"id": "Argentina","cities": []}, + {"id": "Australia","cities": []}, + {"id": "Austria","cities": []}, + {"id": "Bahrain","cities": []}, + {"id": "Bangladesh","cities": []}, + {"id": "Belgium","cities": []}, + {"id": "Bolivia","cities": []}, + {"id": "Brazil","cities": []}, + {"id": "Cambodia","cities": []}, + {"id": "Canada","cities": []}, + {"id": "Chile","cities": []}, + {"id": "People's Republic of China","cities": []}, + {"id": "Colombia","cities": []}, + {"id": "Costa Rica","cities": []}, + {"id": "Croatia","cities": []}, + {"id": "Czech Republic","cities": []}, + {"id": "Denmark","cities": []}, + {"id": "Dominican Republic","cities": []}, + {"id": "Ecuador","cities": []}, + {"id": "Egypt","cities": []}, + {"id": "El Salvador","cities": []}, + {"id": "Estonia","cities": []}, + {"id": "Finland","cities": []}, + {"id": "France","cities": []}, + {"id": "Germany","cities": []}, + {"id": "Ghana","cities": []}, + {"id": "Greece","cities": []}, + {"id": "Guatemala","cities": []}, + {"id": "Hungary","cities": []}, + {"id": "India","cities": []}, + {"id": "Indonesia","cities": []}, + {"id": "Ireland","cities": []}, + {"id": "Israel Region","cities": []}, + {"id": "Italy","cities": []}, + {"id": "Japan","cities": []}, + {"id": "Jordan","cities": []}, + {"id": "Kenya","cities": []}, + {"id": "South Korea","cities": []}, + {"id": "Lebanon","cities": []}, + {"id": "Lithuania","cities": []}, + {"id": "Malaysia","cities": []}, + {"id": "Mexico","cities": []}, + {"id": "Morocco","cities": []}, + {"id": "Myanmar","cities": []}, + {"id": "Netherlands","cities": []}, + {"id": "New Zealand","cities": []}, + {"id": "Nigeria","cities": []}, + {"id": "Norway","cities": []}, + {"id": "Pakistan","cities": []}, + {"id": "Panama","cities": []}, + {"id": "Peru","cities": []}, + {"id": "Philippines","cities": []}, + {"id": "Poland","cities": []}, + {"id": "Portugal","cities": []}, + {"id": "Qatar","cities": []}, + {"id": "Romania","cities": []}, + {"id": "Saudi Arabia","cities": []}, + {"id": "Singapore","cities": []}, + {"id": "South Africa","cities": []}, + {"id": "Spain","cities": []}, + {"id": "Sri Lanka","cities": []}, + {"id": "Sweden","cities": []}, + {"id": "Switzerland","cities": []}, + {"id": "Taiwan","cities": []}, + {"id": "Tanzania","cities": []}, + {"id": "Thailand","cities": []}, + {"id": "Trinidad and Tobago","cities": []}, + {"id": "Turkey","cities": []}, + {"id": "Uganda","cities": []}, + {"id": "United Arab Emirates","cities": []}, + {"id": "United Kingdom","cities": []}, + {"id": "United States of America","cities": []}, + {"id": "Uruguay","cities": []}, + {"id": "Vietnam","cities": []} + ], + "mwms": [] + }, + "disabled": { + "countries": [], + "mwms": [] + } +} diff --git a/data/taxi_places/yandex.json b/data/taxi_places/yandex.json new file mode 100644 index 0000000000..43c0769195 --- /dev/null +++ b/data/taxi_places/yandex.json @@ -0,0 +1,134 @@ +{ + "enabled": { + "countries": [ + { + "id": "Georgia Region", + "cities": [ + "Rustavi", + "Tbilisi" + ] + }, + { + "id": "Kazakhstan", + "cities": [ + "Aktau", + "Aktobe", + "Almaty", + "Astana", + "Atyrau", + "Karaganda", + "Kostanay", + "Kyzylorda", + "Pavlodar", + "Petropavlovsk", + "Taraz", + "Turkestan", + "Oral", + "Ust-Kamenogorsk", + "Shymkent" + ] + } + ], + "mwms": [ + "Armenia", + "Belarus_Homiel Region", + "Belarus_Minsk Region", + "Kyrgyzstan", + "Latvia", + "Moldova", + "Russia_Altai Krai", + "Russia_Amur Oblast", + "Russia_Arkhangelsk Oblast_Central", + "Russia_Arkhangelsk Oblast_North", + "Russia_Astrakhan Oblast", + "Russia_Bashkortostan", + "Russia_Belgorod Oblast", + "Russia_Bryansk Oblast", + "Russia_Buryatia", + "Russia_Vladimir Oblast", + "Russia_Volgograd Oblast", + "Russia_Vologda Oblast", + "Russia_Voronezh Oblast", + "Russia_Republic of Dagestan", + "Russia_Zabaykalsky Krai", + "Russia_Ivanovo Oblast", + "Russia_Irkutsk Oblast", + "Russia_Kabardino-Balkaria", + "Russia_Kaliningrad Oblast", + "Russia_Kaluga Oblast", + "Russia_Karachay-Cherkessia", + "Russia_Republic of Karelia_North", + "Russia_Republic of Karelia_South", + "Russia_Kemerov Oblast", + "Russia_Kirov Oblast", + "Russia_Komi Republic", + "Russia_Kostroma Oblast", + "Russia_Krasnodar Krai", + "Russia_Krasnoyarsk Krai_North", + "Russia_Krasnoyarsk Krai_South", + "Russia_Kurgan Oblast", + "Russia_Kursk Oblast", + "Russia_Leningradskaya Oblast_Karelsky", + "Russia_Leningradskaya Oblast_Southeast", + "Russia_Lipetsk Oblast", + "Russia_Magadan Oblast", + "Russia_Mari El", + "Russia_Republic of Mordovia", + "Russia_Moscow", + "Russia_Moscow Oblast_East", + "Russia_Moscow Oblast_West", + "Russia_Murmansk Oblast", + "Russia_Nizhny Novgorod Oblast", + "Russia_Novgorod Oblast", + "Russia_Novosibirsk Oblast", + "Russia_Omsk Oblast", + "Russia_Orenburg Oblast", + "Russia_Oryol Oblast", + "Russia_Penza Oblast", + "Russia_Perm Krai_North", + "Russia_Perm Krai_South", + "Russia_Primorsky Krai", + "Russia_Pskov Oblast", + "Russia_Krasnodar Krai_Adygeya", + "Russia_Ingushetia", + "Russia_Republic of Kalmykia", + "Russia_Tuva", + "Russia_Khakassia", + "Russia_Rostov Oblast", + "Russia_Ryazan Oblast", + "Russia_Samara Oblast", + "Russia_Saint Petersburg", + "Russia_Saratov Oblast", + "Russia_Sakha Republic", + "Russia_Sakhalin Oblast", + "Russia_Sverdlovsk Oblast_Ekaterinburg", + "Russia_Sverdlovsk Oblast_North", + "Russia_North Ossetia-Alania", + "Russia_Smolensk Oblast", + "Russia_Stavropol Krai", + "Russia_Tambov Oblast", + "Russia_Tatarstan", + "Russia_Tver Oblast", + "Russia_Tomsk Oblast", + "Russia_Tula Oblast", + "Russia_Tyumen Oblast", + "Russia_Udmurt Republic", + "Russia_Ulyanovsk Oblast", + "Russia_Khabarovsk Krai", + "Russia_Yugra_Khanty", + "Russia_Chelyabinsk Oblast", + "Russia_Chuvashia", + "Russia_Yamalo-Nenets Autonomous Okrug", + "Russia_Yaroslavl Oblast", + "Ukraine_Dnipropetrovsk Oblast", + "Ukraine_Kyiv Oblast", + "Ukraine_Lviv Oblast", + "Ukraine_Odessa Oblast", + "Ukraine_Kharkiv Oblast" + ] + }, + "disabled": { + "countries": [], + "mwms": [] + } +} diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index f85aef668c..e72cee124f 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -340,6 +340,7 @@ 34F73FA31E08300E00AC1FD6 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 34F73FA11E08300E00AC1FD6 /* Images.xcassets */; }; 34F742321E0834F400AC1FD6 /* UIViewController+Navigation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 34F742301E0834F400AC1FD6 /* UIViewController+Navigation.mm */; }; 34FE5A6F1F18F30F00BCA729 /* TrafficButtonArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34FE5A6D1F18F30F00BCA729 /* TrafficButtonArea.swift */; }; + 3DF9C22B207CC14A00DA0793 /* taxi_places in Resources */ = {isa = PBXBuildFile; fileRef = 3DF9C22A207CC14A00DA0793 /* taxi_places */; }; 4501B1942077C35A001B9173 /* resources-xxxhdpi_clear in Resources */ = {isa = PBXBuildFile; fileRef = 4501B1922077C35A001B9173 /* resources-xxxhdpi_clear */; }; 4501B1952077C35A001B9173 /* resources-xxxhdpi_dark in Resources */ = {isa = PBXBuildFile; fileRef = 4501B1932077C35A001B9173 /* resources-xxxhdpi_dark */; }; 4554B6EC1E55F0EF0084017F /* drules_proto_vehicle_clear.bin in Resources */ = {isa = PBXBuildFile; fileRef = 4554B6E81E55F02B0084017F /* drules_proto_vehicle_clear.bin */; }; @@ -1264,6 +1265,7 @@ 34FE4C441BCC013500066718 /* MWMMapWidgets.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMMapWidgets.mm; sourceTree = ""; }; 34FE5A6D1F18F30F00BCA729 /* TrafficButtonArea.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrafficButtonArea.swift; sourceTree = ""; }; 3DDB4BC31DAB98F000F4D021 /* libpartners_api.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpartners_api.a; path = "../../../omim-xcode-build/Debug-iphonesimulator/libpartners_api.a"; sourceTree = ""; }; + 3DF9C22A207CC14A00DA0793 /* taxi_places */ = {isa = PBXFileReference; lastKnownFileType = folder; name = taxi_places; path = ../../data/taxi_places; sourceTree = ""; }; 4501B1922077C35A001B9173 /* resources-xxxhdpi_clear */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-xxxhdpi_clear"; path = "../../data/resources-xxxhdpi_clear"; sourceTree = ""; }; 4501B1932077C35A001B9173 /* resources-xxxhdpi_dark */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-xxxhdpi_dark"; path = "../../data/resources-xxxhdpi_dark"; sourceTree = ""; }; 450703081E9E6CF000E8C029 /* local_ads_symbols.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = local_ads_symbols.txt; path = ../../data/local_ads_symbols.txt; sourceTree = ""; }; @@ -3923,6 +3925,7 @@ 671182DF1C7F0DD400CB8177 /* packed_polygons_obsolete.bin */, FA85F632145DDDC20090E1A0 /* packed_polygons.bin */, 451950391B7A3E070085DA05 /* patterns.txt */, + 3DF9C22A207CC14A00DA0793 /* taxi_places */, 4A23D1571B8B4DD700D4EB6F /* resources-6plus_clear */, 4A7D89C11B2EBF3B00AC843E /* resources-6plus_dark */, A367C93A1B17334800E2B6E7 /* resources-default */, @@ -4205,6 +4208,7 @@ F6E2FE011E097BA00083EBEC /* MWMOpeningHoursClosedSpanTableViewCell.xib in Resources */, F6E2FE071E097BA00083EBEC /* MWMOpeningHoursDaysSelectorTableViewCell.xib in Resources */, F6A806531FDAE51600D4D26F /* DiscoveryViatorCollectionHolderCell.xib in Resources */, + 3DF9C22B207CC14A00DA0793 /* taxi_places in Resources */, F6E2FE0D1E097BA00083EBEC /* MWMOpeningHoursDeleteScheduleTableViewCell.xib in Resources */, F6E2FE161E097BA00083EBEC /* MWMOpeningHoursTimeSelectorTableViewCell.xib in Resources */, F6E2FE1C1E097BA00083EBEC /* MWMOpeningHoursTimeSpanTableViewCell.xib in Resources */, diff --git a/partners_api/CMakeLists.txt b/partners_api/CMakeLists.txt index a637047845..65197ef904 100644 --- a/partners_api/CMakeLists.txt +++ b/partners_api/CMakeLists.txt @@ -33,7 +33,8 @@ set( taxi_engine.hpp taxi_places.cpp taxi_places.hpp - taxi_places_constants.hpp + taxi_places_loader.cpp + taxi_places_loader.hpp taxi_provider.hpp uber_api.cpp uber_api.hpp diff --git a/partners_api/partners_api_tests/CMakeLists.txt b/partners_api/partners_api_tests/CMakeLists.txt index adc97a6073..c005e0736d 100644 --- a/partners_api/partners_api_tests/CMakeLists.txt +++ b/partners_api/partners_api_tests/CMakeLists.txt @@ -12,6 +12,7 @@ set( mopub_tests.cpp rb_tests.cpp taxi_engine_tests.cpp + taxi_places_tests.cpp uber_tests.cpp viator_tests.cpp yandex_tests.cpp diff --git a/partners_api/partners_api_tests/taxi_engine_tests.cpp b/partners_api/partners_api_tests/taxi_engine_tests.cpp index 6fd3469c25..ecc7a7a1c2 100644 --- a/partners_api/partners_api_tests/taxi_engine_tests.cpp +++ b/partners_api/partners_api_tests/taxi_engine_tests.cpp @@ -25,7 +25,7 @@ public: storage::TCountriesVec GetCountryIds(m2::PointD const & point) override { return {"Belarus"}; } std::string GetCityName(m2::PointD const & point) override { return "Minsk"; } - storage::TCountryId GetMwmId(m2::PointD const & point) override { return {}; } + storage::TCountryId GetMwmId(m2::PointD const & point) override { return "Belarus_Minsk Region"; } }; class UkraineOdessaDelegate : public taxi::Delegate @@ -34,7 +34,10 @@ public: storage::TCountriesVec GetCountryIds(m2::PointD const & point) override { return {"Ukraine"}; } std::string GetCityName(m2::PointD const & point) override { return "Odessa"; } - storage::TCountryId GetMwmId(m2::PointD const & point) override { return {}; } + storage::TCountryId GetMwmId(m2::PointD const & point) override + { + return "Ukraine_Odessa Oblast"; + } }; class UkraineMariupolDelegate : public taxi::Delegate @@ -43,7 +46,10 @@ public: storage::TCountriesVec GetCountryIds(m2::PointD const & point) override { return {"Ukraine"}; } std::string GetCityName(m2::PointD const & point) override { return "Mariupol"; } - storage::TCountryId GetMwmId(m2::PointD const & point) override { return {}; } + storage::TCountryId GetMwmId(m2::PointD const & point) override + { + return "Ukraine_Donetsk Oblast"; + } }; class BulgariaSofiaDelegate : public taxi::Delegate @@ -219,10 +225,10 @@ UNIT_CLASS_TEST(AsyncGuiThread, TaxiEngine_ResultMaker) testing::Notify(); }; - auto const successNotPossibleCallback = - [&reqId, &providers](taxi::ProvidersContainer const & products, uint64_t const requestId) { - TEST(false, ("successNotPossibleCallback", requestId)); - }; + auto const successNotPossibleCallback = [](taxi::ProvidersContainer const & products, + uint64_t const requestId) { + TEST(false, ("successNotPossibleCallback", requestId)); + }; auto const errorCallback = [&reqId, &errors](taxi::ErrorsContainer const e, uint64_t const requestId) { @@ -231,8 +237,8 @@ UNIT_CLASS_TEST(AsyncGuiThread, TaxiEngine_ResultMaker) testing::Notify(); }; - auto const errorNotPossibleCallback = [&reqId](taxi::ErrorsContainer const errors, - uint64_t const requestId) { + auto const errorNotPossibleCallback = [](taxi::ErrorsContainer const errors, + uint64_t const requestId) { TEST(false, ("errorNotPossibleCallback", requestId, errors)); }; diff --git a/partners_api/partners_api_tests/taxi_places_tests.cpp b/partners_api/partners_api_tests/taxi_places_tests.cpp new file mode 100644 index 0000000000..a2378b54ce --- /dev/null +++ b/partners_api/partners_api_tests/taxi_places_tests.cpp @@ -0,0 +1,68 @@ +#include "testing/testing.hpp" + +#include "partners_api/taxi_places.hpp" +#include "partners_api/taxi_places_loader.hpp" +#include "partners_api/taxi_provider.hpp" + +#include + +namespace taxi +{ +class PlacesTest +{ +public: + static void TestIntersections() + { + using places::Loader; + + std::vector places = {Loader::LoadFor(Provider::Type::Maxim), + Loader::LoadFor(Provider::Type::Uber), + Loader::LoadFor(Provider::Type::Yandex)}; + + for (size_t i = 0; i < places.size(); ++i) + { + for (size_t j = 0; j < places.size(); ++j) + { + if (i == j) + continue; + + FindIdenticalPlaces(places[i].m_enabledPlaces, places[j].m_enabledPlaces); + FindIdenticalPlaces(places[i].m_disabledPlaces, places[j].m_disabledPlaces); + } + } + } + +private: + static void FindIdenticalPlaces(taxi::Places const & lhs, taxi::Places const & rhs) + { + for (auto const & country : lhs.m_countries) + { + if (country.m_cities.empty()) + { + auto const countryIt = + std::find_if(rhs.m_countries.cbegin(), rhs.m_countries.cend(), + [&country](Places::Country const & c) { return c.m_id == country.m_id; }); + + TEST(countryIt == rhs.m_countries.cend(), (*countryIt)); + } + else + { + for (auto const & city : country.m_cities) + { + TEST(!rhs.Has(country.m_id, city), (country.m_id, city)); + } + } + } + + for (auto it = lhs.m_mwmIds.begin(); it != lhs.m_mwmIds.end(); ++it) + { + TEST(!rhs.Has(*it), (*it)); + } + } +}; +} // namespace taxi + +namespace +{ +UNIT_TEST(TaxiPlaces_Intersections) { taxi::PlacesTest::TestIntersections(); } +} // namespace diff --git a/partners_api/taxi_base.cpp b/partners_api/taxi_base.cpp index 99ddf5d55f..fd6cc9dfc4 100644 --- a/partners_api/taxi_base.cpp +++ b/partners_api/taxi_base.cpp @@ -21,12 +21,14 @@ bool ApiItem::AreAllCountriesDisabled(storage::TCountriesVec const & countryIds, if (countryIds.empty()) return true; - if (m_disabledPlaces.IsCountriesEmpty()) + auto const & disabled = m_places.m_disabledPlaces; + + if (disabled.IsCountriesEmpty()) return false; bool isCountryDisabled = true; for (auto const & countryId : countryIds) - isCountryDisabled = isCountryDisabled && m_disabledPlaces.Has(countryId, city); + isCountryDisabled = isCountryDisabled && disabled.Has(countryId, city); return isCountryDisabled; } @@ -37,12 +39,14 @@ bool ApiItem::IsAnyCountryEnabled(storage::TCountriesVec const & countryIds, if (countryIds.empty()) return false; - if (m_enabledPlaces.IsCountriesEmpty()) - return true; + auto const & enabled = m_places.m_enabledPlaces; + + if (enabled.IsCountriesEmpty()) + return false; for (auto const & countryId : countryIds) { - if (m_enabledPlaces.Has(countryId, city)) + if (enabled.Has(countryId, city)) return true; } @@ -51,23 +55,19 @@ bool ApiItem::IsAnyCountryEnabled(storage::TCountriesVec const & countryIds, bool ApiItem::IsMwmDisabled(storage::TCountryId const & mwmId) const { + auto const & disabled = m_places.m_disabledPlaces; if (mwmId.empty()) return false; - if (m_disabledPlaces.IsMwmsEmpty()) - return false; - - return m_disabledPlaces.Has(mwmId); + return disabled.Has(mwmId); } bool ApiItem::IsMwmEnabled(storage::TCountryId const & mwmId) const { + auto const & enabled = m_places.m_enabledPlaces; if (mwmId.empty()) return false; - if (m_enabledPlaces.IsMwmsEmpty()) - return true; - - return m_enabledPlaces.Has(mwmId); + return enabled.Has(mwmId); } } // namespace taxi diff --git a/partners_api/taxi_base.hpp b/partners_api/taxi_base.hpp index f0434a4261..d4ca51890d 100644 --- a/partners_api/taxi_base.hpp +++ b/partners_api/taxi_base.hpp @@ -1,6 +1,7 @@ #pragma once #include "partners_api/taxi_places.hpp" +#include "partners_api/taxi_places_loader.hpp" #include "partners_api/taxi_provider.hpp" #include @@ -53,11 +54,10 @@ using ApiPtr = std::unique_ptr; struct ApiItem { - ApiItem(Provider::Type type, ApiPtr && api, Places const & enabled, Places const & disabled) + ApiItem(Provider::Type type, ApiPtr && api) : m_type(type) , m_api(std::move(api)) - , m_enabledPlaces(enabled) - , m_disabledPlaces(disabled) + , m_places(places::Loader::LoadFor(type)) { } @@ -71,7 +71,6 @@ struct ApiItem Provider::Type m_type; ApiPtr m_api; - Places m_enabledPlaces; - Places m_disabledPlaces; + SupportedPlaces m_places; }; } // namespace taxi diff --git a/partners_api/taxi_engine.cpp b/partners_api/taxi_engine.cpp index aac1b8a1f3..eaa4c8f924 100644 --- a/partners_api/taxi_engine.cpp +++ b/partners_api/taxi_engine.cpp @@ -1,6 +1,6 @@ #include "partners_api/taxi_engine.hpp" #include "partners_api/maxim_api.hpp" -#include "partners_api/taxi_places_constants.hpp" +#include "partners_api/taxi_places_loader.hpp" #include "partners_api/uber_api.hpp" #include "partners_api/yandex_api.hpp" @@ -115,9 +115,9 @@ void ResultMaker::DecrementRequestCount() // Engine ----------------------------------------------------------------------------------------- Engine::Engine(std::vector urls /* = {} */) { - AddApi(urls, Provider::Type::Yandex, places::kYandexEnabledPlaces, {{}}); - AddApi(urls, Provider::Type::Uber, {{}}, places::kUberDisabledPlaces); - AddApi(urls, Provider::Type::Maxim, places::kMaximEnabledPlaces, {{}}); + AddApi(urls, Provider::Type::Yandex); + AddApi(urls, Provider::Type::Uber); + AddApi(urls, Provider::Type::Maxim); } void Engine::SetDelegate(std::unique_ptr delegate) { m_delegate = std::move(delegate); } @@ -229,8 +229,7 @@ bool Engine::IsEnabledAtPos(Provider::Type type, m2::PointD const & point) const } template -void Engine::AddApi(std::vector const & urls, Provider::Type type, - Places const & enabled, Places const & disabled) +void Engine::AddApi(std::vector const & urls, Provider::Type type) { auto const it = std::find_if(urls.cbegin(), urls.cend(), [type](ProviderUrl const & item) { @@ -238,8 +237,8 @@ void Engine::AddApi(std::vector const & urls, Provider::Type type, }); if (it != urls.cend()) - m_apis.emplace_back(type, my::make_unique(it->m_url), enabled, disabled); + m_apis.emplace_back(type, my::make_unique(it->m_url)); else - m_apis.emplace_back(type, my::make_unique(), enabled, disabled); + m_apis.emplace_back(type, my::make_unique()); } } // namespace taxi diff --git a/partners_api/taxi_engine.hpp b/partners_api/taxi_engine.hpp index 851f83f8e1..1265ba94e4 100644 --- a/partners_api/taxi_engine.hpp +++ b/partners_api/taxi_engine.hpp @@ -91,8 +91,7 @@ private: bool IsEnabledAtPos(Provider::Type type, m2::PointD const & point) const; template - void AddApi(std::vector const & urls, Provider::Type type, Places const & enabled, - Places const & disabled); + void AddApi(std::vector const & urls, Provider::Type type); std::vector m_apis; diff --git a/partners_api/taxi_places.cpp b/partners_api/taxi_places.cpp index db83b0fb36..03fb5e6156 100644 --- a/partners_api/taxi_places.cpp +++ b/partners_api/taxi_places.cpp @@ -4,13 +4,6 @@ namespace taxi { -Places::Places(std::vector const & countries, - std::unordered_set const & mwmIds) - : m_countries(countries) - , m_mwmIds(mwmIds) -{ -} - bool Places::IsCountriesEmpty() const { return m_countries.empty(); } bool Places::IsMwmsEmpty() const { return m_mwmIds.empty(); } diff --git a/partners_api/taxi_places.hpp b/partners_api/taxi_places.hpp index 9630db9e85..882edd718e 100644 --- a/partners_api/taxi_places.hpp +++ b/partners_api/taxi_places.hpp @@ -2,6 +2,10 @@ #include "storage/index.hpp" +#include "coding/serdes_json.hpp" + +#include "base/visitor.hpp" + #include #include #include @@ -11,22 +15,35 @@ namespace taxi class Places { public: + friend class PlacesTest; + struct Country { storage::TCountryId m_id; std::vector m_cities; - }; - Places(std::vector const & countries, - std::unordered_set const & mwmIds = {}); + DECLARE_VISITOR_AND_DEBUG_PRINT(Country, visitor(m_id, "id"), visitor(m_cities, "cities")) + }; bool IsCountriesEmpty() const; bool IsMwmsEmpty() const; bool Has(storage::TCountryId const & id, std::string const & city) const; bool Has(storage::TCountryId const & mwmId) const; + DECLARE_VISITOR_AND_DEBUG_PRINT(Places, visitor(m_countries, "countries"), + visitor(m_mwmIds, "mwms")) + private: std::vector m_countries; std::unordered_set m_mwmIds; }; + +struct SupportedPlaces +{ + Places m_enabledPlaces; + Places m_disabledPlaces; + + DECLARE_VISITOR_AND_DEBUG_PRINT(SupportedPlaces, visitor(m_enabledPlaces, "enabled"), + visitor(m_disabledPlaces, "disabled")) +}; } // namespace taxi diff --git a/partners_api/taxi_places_constants.hpp b/partners_api/taxi_places_constants.hpp deleted file mode 100644 index 564c9beed2..0000000000 --- a/partners_api/taxi_places_constants.hpp +++ /dev/null @@ -1,186 +0,0 @@ -#pragma once - -#include "partners_api/taxi_places.hpp" - -namespace taxi -{ -namespace places -{ -// Places which are enabled for yandex taxi and at the same time are disabled for uber taxi. -Places const kUberDisabledPlaces = { - {{"Armenia", {}}, - {"Azerbaijan Region", {"Baku"}}, - {"Belarus", {}}, - {"Bulgaria", {"Varna", "Plovdiv", "Sofia"}}, - {"Georgia Region", {}}, - {"Kazakhstan", {}}, - {"Russian Federation", {}}, - {"Ukraine", {}}, - {"Moldova", {}}, - {"Iran", - {"`Abbas", "Ardabil", "Ahvaz", "Bandar", "Borujerd", "Qods", "Gorgan", "Dezful", - "Zahedan", "Eslamshahr", "Isfahan", "Qazvin", "Kashan", "Karaj", "Kerman", "Kermanshah", - "Qom", "Malard", "Mashhad", "Rasht", "Sari", "Tabriz", "Tehran", "Urmia", - "Hamedan", "Khorramabad", "Shiraz", "Arak", "Yazd"}}}}; - -Places const kYandexEnabledPlaces = { - {{"Armenia", {"Vanadzor", "Gyumri", "Yerevan"}}, - {"Belarus", {"Minsk"}}, - {"Georgia Region", {"Rustavi", "Tbilisi"}}, - {"Kazakhstan", - {"Aktau", "Aktobe", "Almaty", "Astana", "Atyrau", "Karaganda", "Kostanay", "Kyzylorda", - "Pavlodar", "Petropavlovsk", "Semipalatinsk", "Taraz", "Turkestan", "Oral", - "Ust-Kamenogorsk", "Shymkent"}}, - {"Ukraine", {"Dnipro", "Kyiv", "Lviv", "Odessa", "Kharkiv"}}, - {"Moldova", {"Kishinev"}}, - {"Russian Federation", - {"Anapa", - "Aprelevka", - "Arzamas", - "Arkhangelsk", - "Astrakhan", - "Balakovo", - "Balashikha", - "Barnaul", - "Belgorod", - "Blagoveshchensk", - "Bryansk", - "Vidnoye", - "Vladivostok", - "Vladikavkaz", - "Vladimir", - "Volgograd", - "Volgodonsk", - "Vologda", - "Voronezh", - "Gelendzhik", - "Golitsyno", - "Dedovsk", - "Dzerzhinsky", - "Dmitrov", - "Dolgoprudny", - "Domodedovo", - "Dubna", - "Yekaterinburg", - "Zheleznogorsk", - "Zheleznodorozhny", - "Zhukovsky", - "Zelenograd", - "Ivanovo", - "Ivanteyevka", - "Izhevsk", - "Irkutsk", - "Yoshkar-Ola", - "Kazan", - "Kaliningrad", - "Kaluga", - "Kamensk-Uralsky", - "Kashira", - "Kemerovo", - "Kirov", - "Kislovodsk", - "Kolomna", - "Komsomolsk-on-Amur", - "Korolyov", - "Kotelniki", - "Krasnogorsk", - "Krasnodar", - "Krasnoznamensk", - "Krasnoyarsk", - "Kurgan", - "Kursk", - "Lipetsk", - "Lobnya", - "Lytkarino", - "Lyubertsy", - "Magnitogorsk", - "Makhachkala", - "Mozhaisk", - "Moscow", - "Murmansk", - "Mytishchi", - "Naberezhnye Chelny", - "Nalchik", - "Naro-Fominsk", - "Nakhabino", - "Nizhnekamsk", - "Nizhny Novgorod", - "Nizhny Tagil", - "Novokuznetsk", - "Novorossiysk", - "Novosibirsk", - "Novy Urengoy", - "Noginsk", - "Noyabrsk", - "Obninsk", - "Odintsovo", - "Ozyory", - "Omsk", - "Orenburg", - "Orsk", - "Oryol", - "Penza", - "Perm", - "Petrozavodsk", - "Podolsk", - "Pushkino", - "Pyatigorsk", - "Ramenskoye", - "Reutov", - "Rostov-on-Don", - "Rybinsk", - "Ryazan", - "Samara", - "Saint Petersburg", - "Saransk", - "Saratov", - "Sergiyev Posad", - "Serpukhov", - "Smolensk", - "Sochi", - "Stavropol", - "Staraya Kupavna", - "Sterlitamak", - "Stupino", - "Surgut", - "Syzran", - "Syktyvkar", - "Taganrog", - "Tambov", - "Tver", - "Tolyatti", - "Tomsk", - "Troitsk", - "Tula", - "Tyumen", - "Ulyanovsk", - "Ufa", - "Fryazino", - "Khabarovsk", - "Khimki", - "Cheboksary", - "Chelyabinsk", - "Cherepovets", - "Chekhov", - "Chita", - "Shchyolkovo", - "Elektrostal", - "Elektrougli", - "Yaroslavl"}}}}; - -Places const kMaximEnabledPlaces = { - {{"Azerbaijan Region", {"Baku"}}, - {"Belarus", {"Baranovichi", "Brest", "Vitebsk", "Mahilyow"}}, - {"Bulgaria", {"Varna", "Plovdiv", "Sofia"}}, - {"Georgia Region", {"Batumi", "Gori", "Zugdidi", "Kutaisi", "Poti"}}, - {"Kazakhstan", - {"Aktobe", "Almaty", "Astana", "Karaganda", "Kokshetau", "Kostanay", "Petropavl", "Semey", - "Temirtau", "Oral", "Oskemen"}}, - {"Ukraine", {"Kremenchuk", "Mariupol", "Poltava", "Sumy", "Kharkiv", "Cherkasy", "Chernihiv"}}, - {"Iran", - {"`Abbas", "Ardabil", "Ahvaz", "Bandar", "Borujerd", "Qods", "Gorgan", "Dezful", - "Zahedan", "Eslamshahr", "Isfahan", "Qazvin", "Kashan", "Karaj", "Kerman", "Kermanshah", - "Qom", "Malard", "Mashhad", "Rasht", "Sari", "Tabriz", "Tehran", "Urmia", - "Hamedan", "Khorramabad", "Shiraz", "Arak", "Yazd"}}}}; -} // namespace places -} // namespace taxi diff --git a/partners_api/taxi_places_loader.cpp b/partners_api/taxi_places_loader.cpp new file mode 100644 index 0000000000..a7692f6f61 --- /dev/null +++ b/partners_api/taxi_places_loader.cpp @@ -0,0 +1,62 @@ +#include "partners_api/taxi_places_loader.hpp" + +#include "platform/platform.hpp" + +namespace taxi +{ +namespace places +{ +SupportedPlaces Loader::LoadFor(Provider::Type const type) +{ + auto const filename = GetFileNameByProvider(type); + + std::string fileData; + try + { + auto const fileReader = GetPlatform().GetReader(filename); + fileReader->ReadAsString(fileData); + } + catch (FileAbsentException const & ex) + { + LOG(LERROR, ("Exception while get reader for file:", filename, "reason:", ex.what())); + return {}; + } + catch (FileReader::Exception const & ex) + { + LOG(LERROR, ("Exception while reading file:", filename, "reason:", ex.what())); + return {}; + } + + ASSERT(!fileData.empty(), ()); + + SupportedPlaces places; + + try + { + coding::DeserializerJson des(fileData); + des(places); + } + catch (my::Json::Exception const & ex) + { + LOG(LWARNING, + ("Exception while parsing file:", filename, "reason:", ex.what(), "json:", fileData)); + return {}; + } + + return places; +} + +std::string Loader::GetFileNameByProvider(Provider::Type const type) +{ + switch (type) + { + case Provider::Type::Maxim: return "/taxi_places/maxim.json"; + case Provider::Type::Uber: return "/taxi_places/uber.json"; + case Provider::Type::Yandex: return "/taxi_places/yandex.json"; + } + + ASSERT(false, ("Provider type", type, "is not supported")); + return ""; +} +} // namespace places +} // namespace taxi diff --git a/partners_api/taxi_places_loader.hpp b/partners_api/taxi_places_loader.hpp new file mode 100644 index 0000000000..10ed83c8f6 --- /dev/null +++ b/partners_api/taxi_places_loader.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "partners_api/taxi_places.hpp" +#include "partners_api/taxi_provider.hpp" + +#include "coding/file_reader.hpp" + +#include "base/assert.hpp" +#include "base/logging.hpp" + +#include + +namespace taxi +{ +namespace places +{ +class Loader +{ +public: + static SupportedPlaces LoadFor(Provider::Type const type); + +private: + static std::string GetFileNameByProvider(Provider::Type const type); +}; +} // namespace places +} // namespace taxi diff --git a/xcode/partners_api/partners_api.xcodeproj/project.pbxproj b/xcode/partners_api/partners_api.xcodeproj/project.pbxproj index d373585ca8..2d32e04ad3 100644 --- a/xcode/partners_api/partners_api.xcodeproj/project.pbxproj +++ b/xcode/partners_api/partners_api.xcodeproj/project.pbxproj @@ -43,7 +43,8 @@ 3DBC1C551E4B14920016897F /* facebook_ads.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DBC1C531E4B14920016897F /* facebook_ads.hpp */; }; 3DF01C2D20652463005DDF8C /* taxi_places.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DF01C2A20652462005DDF8C /* taxi_places.cpp */; }; 3DF01C2E20652463005DDF8C /* taxi_places.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DF01C2B20652463005DDF8C /* taxi_places.hpp */; }; - 3DF01C2F20652463005DDF8C /* taxi_places_constants.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DF01C2C20652463005DDF8C /* taxi_places_constants.hpp */; }; + 3DF9C219207CAC3000DA0793 /* taxi_places_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DF9C218207CAC3000DA0793 /* taxi_places_tests.cpp */; }; + 3DF9C21C207CAC3B00DA0793 /* taxi_places_loader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DF9C21A207CAC3B00DA0793 /* taxi_places_loader.cpp */; }; 3DFEBF851EF82BEA00317D5C /* viator_api.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DFEBF831EF82BEA00317D5C /* viator_api.cpp */; }; 3DFEBF861EF82BEA00317D5C /* viator_api.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DFEBF841EF82BEA00317D5C /* viator_api.hpp */; }; 3DFEBF891EF82C1300317D5C /* viator_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DFEBF871EF82C1300317D5C /* viator_tests.cpp */; }; @@ -116,7 +117,9 @@ 3DBC1C531E4B14920016897F /* facebook_ads.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = facebook_ads.hpp; sourceTree = ""; }; 3DF01C2A20652462005DDF8C /* taxi_places.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = taxi_places.cpp; sourceTree = ""; }; 3DF01C2B20652463005DDF8C /* taxi_places.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = taxi_places.hpp; sourceTree = ""; }; - 3DF01C2C20652463005DDF8C /* taxi_places_constants.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = taxi_places_constants.hpp; sourceTree = ""; }; + 3DF9C218207CAC3000DA0793 /* taxi_places_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = taxi_places_tests.cpp; sourceTree = ""; }; + 3DF9C21A207CAC3B00DA0793 /* taxi_places_loader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = taxi_places_loader.cpp; sourceTree = ""; }; + 3DF9C21B207CAC3B00DA0793 /* taxi_places_loader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = taxi_places_loader.hpp; sourceTree = ""; }; 3DFEBF831EF82BEA00317D5C /* viator_api.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = viator_api.cpp; sourceTree = ""; }; 3DFEBF841EF82BEA00317D5C /* viator_api.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = viator_api.hpp; sourceTree = ""; }; 3DFEBF871EF82C1300317D5C /* viator_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = viator_tests.cpp; sourceTree = ""; }; @@ -208,7 +211,8 @@ F6B5363B1DA520B20067EEA5 /* partners_api */ = { isa = PBXGroup; children = ( - 3DF01C2C20652463005DDF8C /* taxi_places_constants.hpp */, + 3DF9C21A207CAC3B00DA0793 /* taxi_places_loader.cpp */, + 3DF9C21B207CAC3B00DA0793 /* taxi_places_loader.hpp */, 3DF01C2A20652462005DDF8C /* taxi_places.cpp */, 3DF01C2B20652463005DDF8C /* taxi_places.hpp */, 346E888F1E9D087400D4CE9B /* ads_base.cpp */, @@ -255,6 +259,7 @@ F6B536441DA521060067EEA5 /* partners_api_tests */ = { isa = PBXGroup; children = ( + 3DF9C218207CAC3000DA0793 /* taxi_places_tests.cpp */, 346E889D1E9D088200D4CE9B /* ads_engine_tests.cpp */, 3D7815751F3A14910068B6AC /* async_gui_thread.hpp */, F6B536451DA5213D0067EEA5 /* booking_tests.cpp */, @@ -328,7 +333,6 @@ 3D4E997C1FB439260025B48C /* booking_availability_params.hpp in Headers */, 3DFEBF9C1EFBFC1500317D5C /* taxi_engine.hpp in Headers */, F6B536431DA520E40067EEA5 /* uber_api.hpp in Headers */, - 3DF01C2F20652463005DDF8C /* taxi_places_constants.hpp in Headers */, 3DBC1C551E4B14920016897F /* facebook_ads.hpp in Headers */, 3DF01C2E20652463005DDF8C /* taxi_places.hpp in Headers */, BB1956E71F543D7C003ECE6C /* locals_api.hpp in Headers */, @@ -456,7 +460,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 3DF9C219207CAC3000DA0793 /* taxi_places_tests.cpp in Sources */, 3488B0371E9D11860068AFD8 /* ads_engine_tests.cpp in Sources */, + 3DF9C21C207CAC3B00DA0793 /* taxi_places_loader.cpp in Sources */, F6B5366B1DA5230C0067EEA5 /* testingmain.cpp in Sources */, F6B536671DA522D90067EEA5 /* booking_tests.cpp in Sources */, 3488B0391E9D118D0068AFD8 /* facebook_tests.cpp in Sources */,