Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ad categories should be calculated based upon segment name and top level of segment name #2111

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions vendor/bat-native-ads/src/bat/ads/internal/bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "bat/ads/internal/static_values.h"

#include "base/strings/string_util.h"
#include "base/strings/string_split.h"
#include "base/time/time.h"

using std::placeholders::_1;
Expand Down Expand Up @@ -117,29 +118,9 @@ std::unique_ptr<BundleState> Bundle::GenerateFromCatalog(

// Creative Sets
for (const auto& creative_set : campaign.creative_sets) {
// Segments
std::vector<std::string> hierarchy = {};
for (const auto& segment : creative_set.segments) {
auto name = base::ToLowerASCII(segment.name);

if (std::find(hierarchy.begin(), hierarchy.end(), name)
!= hierarchy.end()) {
continue;
}

hierarchy.push_back(name);
}

if (hierarchy.empty()) {
BLOG(ERROR) << "creativeSet segments are empty";
return nullptr;
}

std::string category = base::JoinString(hierarchy, "-");

auto top_level = hierarchy.front();
uint64_t entries = 0;

// Creatives
for (const auto& creative : creative_set.creatives) {
AdInfo ad_info;
ad_info.creative_set_id = creative_set.creative_set_id;
Expand All @@ -155,22 +136,43 @@ std::unique_ptr<BundleState> Bundle::GenerateFromCatalog(
ad_info.notification_url = creative.payload.target_url;
ad_info.uuid = creative.creative_instance_id;

if (categories.find(category) == categories.end()) {
categories.insert({category, {}});
}
categories.at(category).push_back(ad_info);
entries++;

if (categories.find(top_level) == categories.end()) {
categories.insert({top_level, {}});
// Segments
for (const auto& segment : creative_set.segments) {
auto segment_name = base::ToLowerASCII(segment.name);

std::vector<std::string> segment_name_hierarchy =
base::SplitString(segment_name, "-", base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);

if (segment_name_hierarchy.empty()) {
BLOG(WARNING) << "creativeSet id " << creative_set.creative_set_id
<< " has an invalid segment name";

continue;
}

if (categories.find(segment_name) == categories.end()) {
categories.insert({segment_name, {}});
}
categories.at(segment_name).push_back(ad_info);
entries++;

auto top_level_segment_name = segment_name_hierarchy.front();
if (top_level_segment_name != segment_name) {
if (categories.find(top_level_segment_name) == categories.end()) {
categories.insert({top_level_segment_name, {}});
}
categories.at(top_level_segment_name).push_back(ad_info);
entries++;
}
}
categories.at(top_level).push_back(ad_info);
entries++;
}

if (entries == 0) {
BLOG(ERROR) << "creativeSet creatives are empty";
return nullptr;
BLOG(WARNING) << "creativeSet id " << creative_set.creative_set_id
<< " has an invalid creative";

continue;
}
}
}
Expand Down