Commit 5909a41f authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Normalize the anchor element navigation score

NavigationPredictor: Normnalize the final anchor element
prediction score to between 0.0 and 100.0. This makes it easier
for different experiment arms to change the scales of different
anchor element properties and still compare the final
anchor element score.

Bug: 891736
Change-Id: I7378fe3d8fe68cde32c6216802b077432758562a
Reviewed-on: https://chromium-review.googlesource.com/c/1259142
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarJesse Doherty <jwd@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596879}
parent cf7efa63
......@@ -38,10 +38,45 @@ struct NavigationPredictor::NavigationScore {
NavigationPredictor::NavigationPredictor(
content::RenderFrameHost* render_frame_host)
: browser_context_(
render_frame_host->GetSiteInstance()->GetBrowserContext()) {
render_frame_host->GetSiteInstance()->GetBrowserContext()),
ratio_area_scale_(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kRecordAnchorMetricsVisible,
"ratio_area_scale",
100)),
is_in_iframe_scale_(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kRecordAnchorMetricsVisible,
"is_in_iframe_scale",
0)),
is_same_host_scale_(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kRecordAnchorMetricsVisible,
"is_same_host_scale",
0)),
contains_image_scale_(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kRecordAnchorMetricsVisible,
"contains_image_scale",
50)),
is_url_incremented_scale_(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kRecordAnchorMetricsVisible,
"is_url_incremented_scale",
100)),
source_engagement_score_scale_(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kRecordAnchorMetricsVisible,
"source_engagement_score_scale",
100)),
target_engagement_score_scale_(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kRecordAnchorMetricsVisible,
"target_engagement_score_scale",
100)),
area_rank_scale_(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kRecordAnchorMetricsVisible,
"area_rank_scale",
100)),
sum_scales_(ratio_area_scale_ + is_in_iframe_scale_ +
is_same_host_scale_ + contains_image_scale_ +
is_url_incremented_scale_ + source_engagement_score_scale_ +
target_engagement_score_scale_ + area_rank_scale_) {
DCHECK(browser_context_);
DETACH_FROM_SEQUENCE(sequence_checker_);
InitializeFieldTrialMetricScales();
}
NavigationPredictor::~NavigationPredictor() {
......@@ -66,25 +101,6 @@ bool NavigationPredictor::IsValidMetricFromRenderer(
metric.source_url.SchemeIsHTTPOrHTTPS();
}
void NavigationPredictor::InitializeFieldTrialMetricScales() {
const base::Feature& feature = blink::features::kRecordAnchorMetricsVisible;
ratio_area_scale_ = base::GetFieldTrialParamByFeatureAsInt(
feature, "ratio_area_scale", ratio_area_scale_);
is_in_iframe_scale_ = base::GetFieldTrialParamByFeatureAsInt(
feature, "is_in_iframe_scale", is_in_iframe_scale_);
is_same_host_scale_ = base::GetFieldTrialParamByFeatureAsInt(
feature, "is_same_host_scale", is_same_host_scale_);
contains_image_scale_ = base::GetFieldTrialParamByFeatureAsInt(
feature, "contains_image_scale", contains_image_scale_);
is_url_incremented_scale_ = base::GetFieldTrialParamByFeatureAsInt(
feature, "is_url_incremented_scale", is_url_incremented_scale_);
source_engagement_score_scale_ = base::GetFieldTrialParamByFeatureAsInt(
feature, "source_engagement_score_scale", source_engagement_score_scale_);
target_engagement_score_scale_ = base::GetFieldTrialParamByFeatureAsInt(
feature, "target_engagement_score_scale", target_engagement_score_scale_);
area_rank_scale_ = base::GetFieldTrialParamByFeatureAsInt(
feature, "area_rank_scale", area_rank_scale_);
}
void NavigationPredictor::RecordTimingOnClick() {
base::TimeTicks current_timing = base::TimeTicks::Now();
......@@ -364,16 +380,61 @@ double NavigationPredictor::CalculateAnchorNavigationScore(
double target_engagement_score,
int area_rank,
int number_of_anchors) const {
if (sum_scales_ == 0)
return 0.0;
double max_engagement_points = GetEngagementService()->GetMaxPoints();
document_engagement_score /= max_engagement_points;
target_engagement_score /= max_engagement_points;
double area_rank_score =
(double)((number_of_anchors - area_rank)) / number_of_anchors;
DCHECK_LE(0, metrics.ratio_visible_area);
// TODO(tbansal): https://crbug.com/891719. Disable the check until the bug
// for duplicate anchor elements is fixed.
// DCHECK_GE(1, metrics.ratio_visible_area);
DCHECK_LE(0, metrics.is_in_iframe);
DCHECK_GE(1, metrics.is_in_iframe);
DCHECK_LE(0, metrics.is_same_host);
DCHECK_GE(1, metrics.is_same_host);
DCHECK_LE(0, metrics.contains_image);
DCHECK_GE(1, metrics.contains_image);
DCHECK_LE(0, metrics.is_url_incremented_by_one);
DCHECK_GE(1, metrics.is_url_incremented_by_one);
DCHECK_LE(0, document_engagement_score);
DCHECK_GE(1, document_engagement_score);
DCHECK_LE(0, target_engagement_score);
DCHECK_GE(1, target_engagement_score);
DCHECK_LE(0, area_rank_score);
DCHECK_GE(1, area_rank_score);
// TODO(chelu): https://crbug.com/850624/. Experiment with other heuristic
// algorithms for computing the anchor elements score.
return ratio_area_scale_ * metrics.ratio_visible_area +
is_same_host_scale_ * metrics.is_same_host +
contains_image_scale_ * metrics.contains_image +
is_in_iframe_scale_ * metrics.is_in_iframe +
is_url_incremented_scale_ * metrics.is_url_incremented_by_one +
source_engagement_score_scale_ * document_engagement_score +
target_engagement_score_scale_ * target_engagement_score +
area_rank_scale_ * (number_of_anchors - area_rank);
double score = ratio_area_scale_ * metrics.ratio_visible_area +
is_in_iframe_scale_ * metrics.is_in_iframe +
is_same_host_scale_ * metrics.is_same_host +
contains_image_scale_ * metrics.contains_image +
is_url_incremented_scale_ * metrics.is_url_incremented_by_one +
source_engagement_score_scale_ * document_engagement_score +
target_engagement_score_scale_ * target_engagement_score +
area_rank_scale_ * (area_rank_score);
// Normalize to 100.
score = score / sum_scales_ * 100.0;
DCHECK_LE(0.0, score);
// TODO(tbansal): https://crbug.com/891719. Disable the check until the bug
// for duplicate anchor elements is fixed.
// DCHECK_GE(100.0, score);
return score;
}
void NavigationPredictor::MaybeTakeActionOnLoad(
......
......@@ -52,10 +52,6 @@ class NavigationPredictor : public blink::mojom::AnchorElementMetricsHost {
bool IsValidMetricFromRenderer(
const blink::mojom::AnchorElementMetrics& metric) const;
// Retrieve scaling factors for each metric from Finch and save to this class.
// These scales are used to compute navigation scores.
void InitializeFieldTrialMetricScales();
// Returns site engagement service, which can be used to get site engagement
// score. Return value is guaranteed to be non-null.
SiteEngagementService* GetEngagementService() const;
......@@ -107,14 +103,17 @@ class NavigationPredictor : public blink::mojom::AnchorElementMetricsHost {
int number_of_anchors_url_incremented_ = 0;
// Scaling factors used to compute navigation scores.
int ratio_area_scale_ = 100;
int is_same_host_scale_ = 0;
int contains_image_scale_ = 0;
int is_in_iframe_scale_ = 0;
int is_url_incremented_scale_ = 0;
int source_engagement_score_scale_ = 0;
int target_engagement_score_scale_ = 0;
int area_rank_scale_ = 0;
const int ratio_area_scale_;
const int is_in_iframe_scale_;
const int is_same_host_scale_;
const int contains_image_scale_;
const int is_url_incremented_scale_;
const int source_engagement_score_scale_;
const int target_engagement_score_scale_;
const int area_rank_scale_;
// Sum of all scales. Used to normalize the final computed weight.
const int sum_scales_;
// Timing of document loaded and last click.
base::TimeTicks document_loaded_timing_;
......
......@@ -1021,7 +1021,7 @@ uploading your change for review.
<summary>
The highest navigation score of the anchor elements sent to the browser
process on a page load. This histogram is recorded when the webpage is
loaded.
loaded. Normalized to a value between 0.0 and 100.0.
</summary>
</histogram>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment