forked from organicmaps/organicmaps
added exclude types for facebook ads
This commit is contained in:
parent
81630606b5
commit
f16b545d12
6 changed files with 68 additions and 22 deletions
|
@ -14,7 +14,6 @@ struct Banner
|
|||
|
||||
Banner(Type t, std::string id) : m_type(t), m_bannerId(id) {}
|
||||
|
||||
|
||||
Type m_type = Type::None;
|
||||
std::string m_bannerId;
|
||||
};
|
||||
|
|
|
@ -171,6 +171,11 @@ string Info::GetApproximatePricing() const
|
|||
return result;
|
||||
}
|
||||
|
||||
bool Info::HasBanner() const
|
||||
{
|
||||
return facebook::Ads::Instance().HasBanner(m_types);
|
||||
}
|
||||
|
||||
banners::Banner Info::GetBanner() const
|
||||
{
|
||||
using namespace banners;
|
||||
|
@ -184,7 +189,6 @@ banners::Banner Info::GetBanner() const
|
|||
/// Deprecated, there was not only removed in order not to break the build.
|
||||
/// Should be removed in nearest time.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool Info::HasBanner() const { return true; }
|
||||
string Info::GetBannerTitleId() const { return {}; }
|
||||
string Info::GetBannerMessageId() const { return {}; }
|
||||
string Info::GetBannerIconId() const { return {}; }
|
||||
|
|
|
@ -79,11 +79,11 @@ public:
|
|||
/// @returns string with |kPricingSymbol| signs or empty string if it isn't booking object
|
||||
string GetApproximatePricing() const;
|
||||
|
||||
bool HasBanner() const;
|
||||
banners::Banner GetBanner() const;
|
||||
/// Deprecated, there was not only removed in order not to break the build.
|
||||
/// Should be removed in nearest time.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool HasBanner() const;
|
||||
string GetBannerTitleId() const;
|
||||
string GetBannerMessageId() const;
|
||||
string GetBannerIconId() const;
|
||||
|
|
|
@ -3,6 +3,27 @@
|
|||
#include "indexer/classificator.hpp"
|
||||
#include "indexer/feature_data.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace facebook;
|
||||
|
||||
template <typename It>
|
||||
It FindType(feature::TypesHolder const & types, It first, It last)
|
||||
{
|
||||
for (auto const t : types)
|
||||
{
|
||||
auto const it = std::find_if(first, last, [t](TypeAndlevel const & tl) {
|
||||
auto truncatedType = t;
|
||||
ftype::TruncValue(truncatedType, tl.m_level);
|
||||
return truncatedType == tl.m_type;
|
||||
});
|
||||
if (it != last)
|
||||
return it;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace facebook
|
||||
{
|
||||
Ads::Ads()
|
||||
|
@ -59,6 +80,8 @@ Ads::Ads()
|
|||
"185237551520383_1384652351578891");
|
||||
// Financial.
|
||||
AppendEntry({{"amenity", "bank"}, {"amenity", "atm"}}, "185237551520383_1384652658245527");
|
||||
|
||||
SetExcludeTypes({{"sponsored", "booking"}});
|
||||
}
|
||||
|
||||
void Ads::AppendEntry(std::vector<std::vector<std::string>> const & types, std::string const & id)
|
||||
|
@ -70,6 +93,12 @@ void Ads::AppendEntry(std::vector<std::vector<std::string>> const & types, std::
|
|||
m_typesToBanners.push_back(move(entry));
|
||||
}
|
||||
|
||||
void Ads::SetExcludeTypes(std::vector<std::vector<std::string>> const & types)
|
||||
{
|
||||
for (auto const & type : types)
|
||||
m_excludeTypes.emplace_back(classif().GetTypeByPath(type), type.size());
|
||||
}
|
||||
|
||||
// static
|
||||
Ads const & Ads::Instance()
|
||||
{
|
||||
|
@ -77,22 +106,21 @@ Ads const & Ads::Instance()
|
|||
return ads;
|
||||
}
|
||||
|
||||
bool Ads::HasBanner(feature::TypesHolder const & types) const
|
||||
{
|
||||
return FindType(types, m_excludeTypes.begin(), m_excludeTypes.end()) == m_excludeTypes.end();
|
||||
}
|
||||
|
||||
std::string Ads::GetBannerId(feature::TypesHolder const & types) const
|
||||
{
|
||||
if (!HasBanner(types))
|
||||
return {};
|
||||
|
||||
for (auto const & typesToBanner : m_typesToBanners)
|
||||
{
|
||||
for (auto const t : types)
|
||||
{
|
||||
auto const it = std::find_if(typesToBanner.m_types.begin(), typesToBanner.m_types.end(),
|
||||
[t](TypeAndlevel const & tl) {
|
||||
auto truncatedType = t;
|
||||
ftype::TruncValue(truncatedType, tl.m_level);
|
||||
return truncatedType == tl.m_type;
|
||||
});
|
||||
|
||||
if (it != typesToBanner.m_types.end())
|
||||
return typesToBanner.m_bannerId;
|
||||
}
|
||||
auto const it = FindType(types, typesToBanner.m_types.begin(), typesToBanner.m_types.end());
|
||||
if (it != typesToBanner.m_types.end())
|
||||
return typesToBanner.m_bannerId;
|
||||
}
|
||||
return kBannerIdForOtherTypes;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,14 @@ class TypesHolder;
|
|||
|
||||
namespace facebook
|
||||
{
|
||||
struct TypeAndlevel
|
||||
{
|
||||
TypeAndlevel(uint32_t type, uint32_t level) : m_type(type), m_level(level) {}
|
||||
|
||||
uint32_t m_type = 0;
|
||||
uint32_t m_level = 0;
|
||||
};
|
||||
|
||||
// Class which match feature types and facebook banner ids.
|
||||
class Ads
|
||||
{
|
||||
|
@ -20,18 +28,13 @@ public:
|
|||
|
||||
static Ads const & Instance();
|
||||
|
||||
bool HasBanner(feature::TypesHolder const & types) const;
|
||||
std::string GetBannerId(feature::TypesHolder const & types) const;
|
||||
|
||||
private:
|
||||
Ads();
|
||||
void AppendEntry(std::vector<std::vector<std::string>> const & types, std::string const & id);
|
||||
|
||||
struct TypeAndlevel
|
||||
{
|
||||
TypeAndlevel(uint32_t type, uint32_t level) : m_type(type), m_level(level) {}
|
||||
uint32_t m_type = 0;
|
||||
uint32_t m_level = 0;
|
||||
};
|
||||
void SetExcludeTypes(std::vector<std::vector<std::string>> const & types);
|
||||
|
||||
struct TypesToBannerId
|
||||
{
|
||||
|
@ -40,6 +43,7 @@ private:
|
|||
};
|
||||
|
||||
std::vector<TypesToBannerId> m_typesToBanners;
|
||||
std::vector<TypeAndlevel> m_excludeTypes;
|
||||
|
||||
DISALLOW_COPY_AND_MOVE(Ads);
|
||||
};
|
||||
|
|
|
@ -39,5 +39,16 @@ UNIT_TEST(Facebook_GetBanner)
|
|||
auto const bannerId = facebook::Ads::kBannerIdForOtherTypes;
|
||||
TEST_EQUAL(facebook::Ads::Instance().GetBannerId(holder), bannerId, ());
|
||||
}
|
||||
{
|
||||
feature::TypesHolder holder;
|
||||
holder.Assign(c.GetTypeByPath({"sponsored", "opentable"}));
|
||||
auto const bannerId = facebook::Ads::kBannerIdForOtherTypes;
|
||||
TEST_EQUAL(facebook::Ads::Instance().GetBannerId(holder), bannerId, ());
|
||||
}
|
||||
{
|
||||
feature::TypesHolder holder;
|
||||
holder.Assign(c.GetTypeByPath({"sponsored", "booking"}));
|
||||
TEST_EQUAL(facebook::Ads::Instance().GetBannerId(holder), "", ());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
|
Loading…
Add table
Reference in a new issue