[taxi] places

This commit is contained in:
Arsentiy Milchakov 2018-04-10 13:41:59 +03:00 committed by Roman Kuznetsov
parent 4e7762504b
commit 590bc06d18
20 changed files with 526 additions and 238 deletions

View file

@ -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/

View file

@ -61,6 +61,15 @@ public:
});
}
template <typename T>
void operator()(std::unordered_set<T> const & dest, char const * name = nullptr)
{
NewScopeWith(my::NewJSONArray(), name, [this, &dest] {
for (auto const & v : dest)
(*this)(v);
});
}
template <typename R>
void operator()(R const & r, char const * name = nullptr)
{
@ -173,6 +182,29 @@ public:
RestoreContext(context);
}
template <typename T>
void operator()(std::unordered_set<T> & 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 <typename R>
void operator()(R & r, char const * name = nullptr)
{

View file

@ -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": []
}
}

View file

@ -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": []
}
}

View file

@ -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": []
}
}

View file

@ -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 = "<group>"; };
34FE5A6D1F18F30F00BCA729 /* TrafficButtonArea.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrafficButtonArea.swift; sourceTree = "<group>"; };
3DDB4BC31DAB98F000F4D021 /* libpartners_api.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpartners_api.a; path = "../../../omim-xcode-build/Debug-iphonesimulator/libpartners_api.a"; sourceTree = "<group>"; };
3DF9C22A207CC14A00DA0793 /* taxi_places */ = {isa = PBXFileReference; lastKnownFileType = folder; name = taxi_places; path = ../../data/taxi_places; sourceTree = "<group>"; };
4501B1922077C35A001B9173 /* resources-xxxhdpi_clear */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-xxxhdpi_clear"; path = "../../data/resources-xxxhdpi_clear"; sourceTree = "<group>"; };
4501B1932077C35A001B9173 /* resources-xxxhdpi_dark */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "resources-xxxhdpi_dark"; path = "../../data/resources-xxxhdpi_dark"; sourceTree = "<group>"; };
450703081E9E6CF000E8C029 /* local_ads_symbols.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = local_ads_symbols.txt; path = ../../data/local_ads_symbols.txt; sourceTree = "<group>"; };
@ -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 */,

View file

@ -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

View file

@ -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

View file

@ -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));
};

View file

@ -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 <vector>
namespace taxi
{
class PlacesTest
{
public:
static void TestIntersections()
{
using places::Loader;
std::vector<taxi::SupportedPlaces> 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

View file

@ -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

View file

@ -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 <functional>
@ -53,11 +54,10 @@ using ApiPtr = std::unique_ptr<ApiBase>;
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

View file

@ -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<ProviderUrl> urls /* = {} */)
{
AddApi<yandex::Api>(urls, Provider::Type::Yandex, places::kYandexEnabledPlaces, {{}});
AddApi<uber::Api>(urls, Provider::Type::Uber, {{}}, places::kUberDisabledPlaces);
AddApi<maxim::Api>(urls, Provider::Type::Maxim, places::kMaximEnabledPlaces, {{}});
AddApi<yandex::Api>(urls, Provider::Type::Yandex);
AddApi<uber::Api>(urls, Provider::Type::Uber);
AddApi<maxim::Api>(urls, Provider::Type::Maxim);
}
void Engine::SetDelegate(std::unique_ptr<Delegate> delegate) { m_delegate = std::move(delegate); }
@ -229,8 +229,7 @@ bool Engine::IsEnabledAtPos(Provider::Type type, m2::PointD const & point) const
}
template <typename ApiType>
void Engine::AddApi(std::vector<ProviderUrl> const & urls, Provider::Type type,
Places const & enabled, Places const & disabled)
void Engine::AddApi(std::vector<ProviderUrl> 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<ProviderUrl> const & urls, Provider::Type type,
});
if (it != urls.cend())
m_apis.emplace_back(type, my::make_unique<ApiType>(it->m_url), enabled, disabled);
m_apis.emplace_back(type, my::make_unique<ApiType>(it->m_url));
else
m_apis.emplace_back(type, my::make_unique<ApiType>(), enabled, disabled);
m_apis.emplace_back(type, my::make_unique<ApiType>());
}
} // namespace taxi

View file

@ -91,8 +91,7 @@ private:
bool IsEnabledAtPos(Provider::Type type, m2::PointD const & point) const;
template <typename ApiType>
void AddApi(std::vector<ProviderUrl> const & urls, Provider::Type type, Places const & enabled,
Places const & disabled);
void AddApi(std::vector<ProviderUrl> const & urls, Provider::Type type);
std::vector<ApiItem> m_apis;

View file

@ -4,13 +4,6 @@
namespace taxi
{
Places::Places(std::vector<Country> const & countries,
std::unordered_set<storage::TCountryId> const & mwmIds)
: m_countries(countries)
, m_mwmIds(mwmIds)
{
}
bool Places::IsCountriesEmpty() const { return m_countries.empty(); }
bool Places::IsMwmsEmpty() const { return m_mwmIds.empty(); }

View file

@ -2,6 +2,10 @@
#include "storage/index.hpp"
#include "coding/serdes_json.hpp"
#include "base/visitor.hpp"
#include <string>
#include <unordered_set>
#include <vector>
@ -11,22 +15,35 @@ namespace taxi
class Places
{
public:
friend class PlacesTest;
struct Country
{
storage::TCountryId m_id;
std::vector<std::string> m_cities;
};
Places(std::vector<Country> const & countries,
std::unordered_set<storage::TCountryId> 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<Country> m_countries;
std::unordered_set<storage::TCountryId> 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

View file

@ -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

View file

@ -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

View file

@ -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 <string>
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

View file

@ -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 = "<group>"; };
3DF01C2A20652462005DDF8C /* taxi_places.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = taxi_places.cpp; sourceTree = "<group>"; };
3DF01C2B20652463005DDF8C /* taxi_places.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = taxi_places.hpp; sourceTree = "<group>"; };
3DF01C2C20652463005DDF8C /* taxi_places_constants.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = taxi_places_constants.hpp; sourceTree = "<group>"; };
3DF9C218207CAC3000DA0793 /* taxi_places_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = taxi_places_tests.cpp; sourceTree = "<group>"; };
3DF9C21A207CAC3B00DA0793 /* taxi_places_loader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = taxi_places_loader.cpp; sourceTree = "<group>"; };
3DF9C21B207CAC3B00DA0793 /* taxi_places_loader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = taxi_places_loader.hpp; sourceTree = "<group>"; };
3DFEBF831EF82BEA00317D5C /* viator_api.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = viator_api.cpp; sourceTree = "<group>"; };
3DFEBF841EF82BEA00317D5C /* viator_api.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = viator_api.hpp; sourceTree = "<group>"; };
3DFEBF871EF82C1300317D5C /* viator_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = viator_tests.cpp; sourceTree = "<group>"; };
@ -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 */,