Commit 4146a8bd authored by Paul Dyson's avatar Paul Dyson Committed by Commit Bot

Create app_launch_event_logger_helper.

Move to a helper file some functions and constants that
will be needed for inference.

Bug: 899123
Change-Id: I5e4984fafd084abb2a3ae8ca02e42290d5f52479
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1727851Reviewed-by: default avatarTony Yeoman <tby@chromium.org>
Reviewed-by: default avatarCharles . <charleszhao@chromium.org>
Commit-Queue: Paul Dyson <pdyson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683056}
parent 193f9d89
...@@ -3424,6 +3424,8 @@ jumbo_split_static_library("ui") { ...@@ -3424,6 +3424,8 @@ jumbo_split_static_library("ui") {
"app_list/search/search_result_ranker/app_launch_data.h", "app_list/search/search_result_ranker/app_launch_data.h",
"app_list/search/search_result_ranker/app_launch_event_logger.cc", "app_list/search/search_result_ranker/app_launch_event_logger.cc",
"app_list/search/search_result_ranker/app_launch_event_logger.h", "app_list/search/search_result_ranker/app_launch_event_logger.h",
"app_list/search/search_result_ranker/app_launch_event_logger_helper.cc",
"app_list/search/search_result_ranker/app_launch_event_logger_helper.h",
"app_list/search/search_result_ranker/app_launch_predictor.cc", "app_list/search/search_result_ranker/app_launch_predictor.cc",
"app_list/search/search_result_ranker/app_launch_predictor.h", "app_list/search/search_result_ranker/app_launch_predictor.h",
"app_list/search/search_result_ranker/app_list_launch_metrics_provider.cc", "app_list/search/search_result_ranker/app_list_launch_metrics_provider.cc",
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/browser/metrics/chrome_metrics_service_client.h" #include "chrome/browser/metrics/chrome_metrics_service_client.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/app_launch_event_logger_helper.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "components/arc/arc_prefs.h" #include "components/arc/arc_prefs.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -46,38 +47,11 @@ const char AppLaunchEventLogger::kShouldSync[] = "should_sync"; ...@@ -46,38 +47,11 @@ const char AppLaunchEventLogger::kShouldSync[] = "should_sync";
namespace { namespace {
constexpr unsigned int kNumRandomAppsToLog = 25; constexpr unsigned int kNumRandomAppsToLog = 25;
const char kArcScheme[] = "arc://";
const char kExtensionSchemeWithDelimiter[] = "chrome-extension://";
constexpr base::TimeDelta kHourDuration = base::TimeDelta::FromHours(1); constexpr base::TimeDelta kHourDuration = base::TimeDelta::FromHours(1);
constexpr base::TimeDelta kDayDuration = base::TimeDelta::FromDays(1); constexpr base::TimeDelta kDayDuration = base::TimeDelta::FromDays(1);
constexpr int kMinutesInAnHour = 60; constexpr int kMinutesInAnHour = 60;
constexpr int kQuarterHoursInADay = 24 * 4; constexpr int kQuarterHoursInADay = 24 * 4;
constexpr float kTotalHoursBucketSizeMultiplier = 1.25;
constexpr std::array<chromeos::power::ml::Bucket, 2> kClickBuckets = {
{{20, 1}, {200, 10}}};
constexpr std::array<chromeos::power::ml::Bucket, 6>
kTimeSinceLastClickBuckets = {{{60, 1},
{600, 60},
{1200, 300},
{3600, 600},
{18000, 1800},
{86400, 3600}}};
// Returns the nearest bucket for |value|, where bucket sizes are determined
// exponentially, with each bucket size increasing by a factor of |base|.
// The return value is rounded to the nearest integer.
int ExponentialBucket(int value, float base) {
if (base <= 0) {
LOG(DFATAL) << "Base of exponential must be positive.";
return 0;
}
if (value <= 0) {
return 0;
}
return round(pow(base, round(log(value) / log(base))));
}
// Selects a random sample of size |sample_size| from |population|. // Selects a random sample of size |sample_size| from |population|.
std::vector<std::string> Sample(const std::vector<std::string>& population, std::vector<std::string> Sample(const std::vector<std::string>& population,
...@@ -99,18 +73,6 @@ std::vector<std::string> Sample(const std::vector<std::string>& population, ...@@ -99,18 +73,6 @@ std::vector<std::string> Sample(const std::vector<std::string>& population,
return sample; return sample;
} }
int HourOfDay(base::Time time) {
base::Time::Exploded exploded;
time.LocalExplode(&exploded);
return exploded.hour;
}
int DayOfWeek(base::Time time) {
base::Time::Exploded exploded;
time.LocalExplode(&exploded);
return exploded.day_of_week;
}
} // namespace } // namespace
AppLaunchEventLogger::AppLaunchEventLogger() AppLaunchEventLogger::AppLaunchEventLogger()
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/app_list/search/search_result_ranker/app_launch_event_logger_helper.h"
namespace app_list {
int ExponentialBucket(int value, float base) {
if (base <= 0) {
LOG(DFATAL) << "Base of exponential must be positive.";
return 0;
}
if (value <= 0) {
return 0;
}
return round(pow(base, round(log(value) / log(base))));
}
int HourOfDay(base::Time time) {
base::Time::Exploded exploded;
time.LocalExplode(&exploded);
return exploded.hour;
}
int DayOfWeek(base::Time time) {
base::Time::Exploded exploded;
time.LocalExplode(&exploded);
return exploded.day_of_week;
}
} // namespace app_list
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_SEARCH_RESULT_RANKER_APP_LAUNCH_EVENT_LOGGER_HELPER_H_
#define CHROME_BROWSER_UI_APP_LIST_SEARCH_SEARCH_RESULT_RANKER_APP_LAUNCH_EVENT_LOGGER_HELPER_H_
#include <array>
#include "base/time/time.h"
#include "chrome/browser/chromeos/power/ml/user_activity_ukm_logger_helpers.h"
namespace app_list {
const char kArcScheme[] = "arc://";
const char kExtensionSchemeWithDelimiter[] = "chrome-extension://";
constexpr float kTotalHoursBucketSizeMultiplier = 1.25;
constexpr std::array<chromeos::power::ml::Bucket, 2> kClickBuckets = {
{{20, 1}, {200, 10}}};
constexpr std::array<chromeos::power::ml::Bucket, 6>
kTimeSinceLastClickBuckets = {{{60, 1},
{600, 60},
{1200, 300},
{3600, 600},
{18000, 1800},
{86400, 3600}}};
// Returns the nearest bucket for |value|, where bucket sizes are determined
// exponentially, with each bucket size increasing by a factor of |base|.
// The return value is rounded to the nearest integer.
int ExponentialBucket(int value, float base);
int HourOfDay(base::Time time);
int DayOfWeek(base::Time time);
} // namespace app_list
#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_SEARCH_RESULT_RANKER_APP_LAUNCH_EVENT_LOGGER_HELPER_H_
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