-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DCHECKs to find the root cause of a crash in ads::GetParentSegment
- Loading branch information
Showing
19 changed files
with
274 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
vendor/bat-native-ads/src/bat/ads/internal/ad_targeting/ad_targeting_constants.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_TARGETING_AD_TARGETING_CONSTANTS_H_ | ||
#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_TARGETING_AD_TARGETING_CONSTANTS_H_ | ||
|
||
namespace ads { | ||
namespace ad_targeting { | ||
|
||
const int kTopInterestSegmentsCount = 3; | ||
const int kTopLatentInterestSegmentsCount = 3; | ||
const int kTopPurchaseIntentSegmentsCount = 3; | ||
|
||
} // namespace ad_targeting | ||
} // namespace ads | ||
|
||
#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_TARGETING_AD_TARGETING_CONSTANTS_H_ |
78 changes: 78 additions & 0 deletions
78
vendor/bat-native-ads/src/bat/ads/internal/ad_targeting/ad_targeting_util.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ads/internal/ad_targeting/ad_targeting_util.h" | ||
|
||
#include "bat/ads/internal/ad_serving/ad_targeting/models/behavioral/bandits/epsilon_greedy_bandit_model.h" | ||
#include "bat/ads/internal/ad_serving/ad_targeting/models/behavioral/purchase_intent/purchase_intent_model.h" | ||
#include "bat/ads/internal/ad_serving/ad_targeting/models/contextual/text_classification/text_classification_model.h" | ||
#include "bat/ads/internal/ad_targeting/ad_targeting_constants.h" | ||
#include "bat/ads/internal/ad_targeting/ad_targeting_user_model_info.h" | ||
#include "bat/ads/internal/segments/segments_util.h" | ||
|
||
namespace ads { | ||
namespace ad_targeting { | ||
|
||
namespace { | ||
|
||
SegmentList FilterSegments(const SegmentList& segments, const int max_count) { | ||
SegmentList top_segments; | ||
|
||
int count = 0; | ||
|
||
for (const auto& segment : segments) { | ||
if (ShouldFilterSegment(segment)) { | ||
continue; | ||
} | ||
|
||
top_segments.push_back(segment); | ||
count++; | ||
if (count == max_count) { | ||
break; | ||
} | ||
} | ||
|
||
return top_segments; | ||
} | ||
|
||
} // namespace | ||
|
||
SegmentList GetTopSegments(const SegmentList& segments, | ||
const int max_count, | ||
const bool parent_only) { | ||
if (!parent_only) { | ||
return FilterSegments(segments, max_count); | ||
} | ||
|
||
const SegmentList parent_segments = GetParentSegments(segments); | ||
return FilterSegments(parent_segments, max_count); | ||
} | ||
|
||
SegmentList GetTopSegments(const UserModelInfo& user_model, | ||
const bool parent_only) { | ||
SegmentList segments; | ||
|
||
const SegmentList interest_segments = GetTopSegments( | ||
user_model.interest_segments, kTopInterestSegmentsCount, parent_only); | ||
segments.insert(segments.end(), interest_segments.begin(), | ||
interest_segments.end()); | ||
|
||
const SegmentList latent_interest_segments = | ||
GetTopSegments(user_model.latent_interest_segments, | ||
kTopLatentInterestSegmentsCount, parent_only); | ||
segments.insert(segments.end(), latent_interest_segments.begin(), | ||
latent_interest_segments.end()); | ||
|
||
const SegmentList purchase_intent_segments = | ||
GetTopSegments(user_model.purchase_intent_segments, | ||
kTopPurchaseIntentSegmentsCount, parent_only); | ||
segments.insert(segments.end(), purchase_intent_segments.begin(), | ||
purchase_intent_segments.end()); | ||
|
||
return segments; | ||
} | ||
|
||
} // namespace ad_targeting | ||
} // namespace ads |
26 changes: 26 additions & 0 deletions
26
vendor/bat-native-ads/src/bat/ads/internal/ad_targeting/ad_targeting_util.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_TARGETING_AD_TARGETING_UTIL_H_ | ||
#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_TARGETING_AD_TARGETING_UTIL_H_ | ||
|
||
#include "bat/ads/internal/segments/segments_aliases.h" | ||
|
||
namespace ads { | ||
namespace ad_targeting { | ||
|
||
struct UserModelInfo; | ||
|
||
SegmentList GetTopSegments(const SegmentList& segments, | ||
const int max_count, | ||
const bool parent_only); | ||
|
||
SegmentList GetTopSegments(const UserModelInfo& user_model, | ||
const bool parent_only); | ||
|
||
} // namespace ad_targeting | ||
} // namespace ads | ||
|
||
#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_AD_TARGETING_AD_TARGETING_UTIL_H_ |
90 changes: 90 additions & 0 deletions
90
vendor/bat-native-ads/src/bat/ads/internal/ad_targeting/ad_targeting_util_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ads/internal/ad_targeting/ad_targeting_util.h" | ||
|
||
#include "bat/ads/internal/ad_targeting/ad_targeting_user_model_info.h" | ||
#include "bat/ads/internal/unittest_base.h" | ||
|
||
// npm run test -- brave_unit_tests --filter=BatAds* | ||
|
||
namespace ads { | ||
namespace ad_targeting { | ||
|
||
class BatAdsAdTargetingUtilTest : public UnitTestBase { | ||
protected: | ||
BatAdsAdTargetingUtilTest() = default; | ||
|
||
~BatAdsAdTargetingUtilTest() override = default; | ||
}; | ||
|
||
TEST_F(BatAdsAdTargetingUtilTest, GetTopParentChildSegments) { | ||
// Arrange | ||
UserModelInfo user_model; | ||
user_model.interest_segments = {"interest-1", "interest-2"}; | ||
user_model.latent_interest_segments = {"latent_interest-1", | ||
"latent_interest-2"}; | ||
user_model.purchase_intent_segments = {"purchase_intent-1", | ||
"purchase_intent-2"}; | ||
|
||
// Act | ||
const SegmentList segments = | ||
GetTopSegments(user_model, /* parent_only */ false); | ||
|
||
// Assert | ||
const SegmentList expected_segments = { | ||
"interest-1", "interest-2", "latent_interest-1", | ||
"latent_interest-2", "purchase_intent-1", "purchase_intent-2"}; | ||
|
||
EXPECT_EQ(expected_segments, segments); | ||
} | ||
|
||
TEST_F(BatAdsAdTargetingUtilTest, GetTopParentChildSegmentsForEmptyUserModel) { | ||
// Arrange | ||
const UserModelInfo user_model; | ||
|
||
// Act | ||
const SegmentList segments = | ||
GetTopSegments(user_model, /* parent_only */ false); | ||
|
||
// Assert | ||
EXPECT_TRUE(segments.empty()); | ||
} | ||
|
||
TEST_F(BatAdsAdTargetingUtilTest, GetTopParentSegments) { | ||
// Arrange | ||
UserModelInfo user_model; | ||
user_model.interest_segments = {"interest_1", "interest_2"}; | ||
user_model.latent_interest_segments = {"latent_interest_1", | ||
"latent_interest_2"}; | ||
user_model.purchase_intent_segments = {"purchase_intent_1", | ||
"purchase_intent_2"}; | ||
|
||
// Act | ||
const SegmentList segments = | ||
GetTopSegments(user_model, /* parent_only */ true); | ||
|
||
// Assert | ||
const SegmentList expected_segments = { | ||
"interest_1", "interest_2", "latent_interest_1", | ||
"latent_interest_2", "purchase_intent_1", "purchase_intent_2"}; | ||
|
||
EXPECT_EQ(expected_segments, segments); | ||
} | ||
|
||
TEST_F(BatAdsAdTargetingUtilTest, GetTopParentSegmentsForEmptyUserModel) { | ||
// Arrange | ||
const UserModelInfo user_model; | ||
|
||
// Act | ||
const SegmentList segments = | ||
GetTopSegments(user_model, /* parent_only */ true); | ||
|
||
// Assert | ||
EXPECT_TRUE(segments.empty()); | ||
} | ||
|
||
} // namespace ad_targeting | ||
} // namespace ads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.