Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Unified Diff: components/ntp_snippets/category_rankers/click_based_category_ranker.cc

Issue 2889153003: [NTP::SectionOrder] Add ranker section to snippets internals. (Closed)
Patch Set: jkrcal@ nit. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/category_rankers/click_based_category_ranker.cc
diff --git a/components/ntp_snippets/category_rankers/click_based_category_ranker.cc b/components/ntp_snippets/category_rankers/click_based_category_ranker.cc
index 62e2ad711b5f9475092defaf73dc32517fe1b9a7..1b060e63eb63ee260554978376a591e0b2198452 100644
--- a/components/ntp_snippets/category_rankers/click_based_category_ranker.cc
+++ b/components/ntp_snippets/category_rankers/click_based_category_ranker.cc
@@ -10,6 +10,7 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "base/values.h"
#include "components/ntp_snippets/category_rankers/constant_category_ranker.h"
#include "components/ntp_snippets/content_suggestions_metrics.h"
@@ -131,6 +132,14 @@ base::Optional<Category> GetPromotedCategoryFromVariations() {
return Category::FromIDValue(category_id);
}
+std::string GetOptionalCategoryAsString(
+ const base::Optional<Category>& optional_category) {
+ if (optional_category.has_value()) {
+ return base::IntToString(optional_category->id());
+ }
+ return "None";
+}
+
} // namespace
ClickBasedCategoryRanker::ClickBasedCategoryRanker(
@@ -264,6 +273,46 @@ void ClickBasedCategoryRanker::InsertCategoryAfterIfNecessary(
/*after=*/true);
}
+std::vector<CategoryRanker::DebugDataItem>
+ClickBasedCategoryRanker::GetDebugData() {
+ std::vector<CategoryRanker::DebugDataItem> result;
+ result.push_back(
+ CategoryRanker::DebugDataItem("Type", "ClickBasedCategoryRanker"));
+
+ std::string initial_order_type;
+ CategoryOrderChoice choice = GetSelectedCategoryOrder();
+ if (choice == CategoryOrderChoice::GENERAL) {
+ initial_order_type = "GENERAL";
+ }
+ if (choice == CategoryOrderChoice::EMERGING_MARKETS_ORIENTED) {
+ initial_order_type = "EMERGING_MARKETS_ORIENTED;";
+ }
+ result.push_back(
+ CategoryRanker::DebugDataItem("Initial order type", initial_order_type));
+
+ std::vector<std::string> category_strings;
+ for (const auto& ranked_category : ordered_categories_) {
+ category_strings.push_back(base::ReplaceStringPlaceholders(
+ "($1; $2)",
+ {base::IntToString(ranked_category.category.id()),
+ base::IntToString(ranked_category.clicks)},
+ /*offsets=*/nullptr));
+ }
+ result.push_back(
+ CategoryRanker::DebugDataItem("Current order (with click counts)",
+ base::JoinString(category_strings, ", ")));
+
+ result.push_back(CategoryRanker::DebugDataItem(
+ "Actual promoted category",
+ GetOptionalCategoryAsString(promoted_category_)));
+
+ result.push_back(CategoryRanker::DebugDataItem(
+ "Raw promoted category from variations",
+ GetOptionalCategoryAsString(GetPromotedCategoryFromVariations())));
+
+ return result;
+}
+
void ClickBasedCategoryRanker::OnSuggestionOpened(Category category) {
if (!ContainsCategory(category)) {
LOG(DFATAL) << "The category with ID " << category.id()

Powered by Google App Engine
This is Rietveld 408576698