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

Unified Diff: components/ntp_snippets/user_classifier.h

Issue 2346263002: Extending the UserClassifier to actually support classification. (Closed)
Patch Set: Marc's comments Created 4 years, 3 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/user_classifier.h
diff --git a/components/ntp_snippets/user_classifier.h b/components/ntp_snippets/user_classifier.h
index 3314884606f42b125937584ed468d285b0c3ad1d..48f5d16f9961b5133a69e81dbfbf4b4823d5a2ce 100644
--- a/components/ntp_snippets/user_classifier.h
+++ b/components/ntp_snippets/user_classifier.h
@@ -5,7 +5,10 @@
#ifndef COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_
#define COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_
+#include <string>
+
#include "base/macros.h"
+#include "base/time/time.h"
class PrefRegistrySimple;
class PrefService;
@@ -14,10 +17,16 @@ namespace ntp_snippets {
// Collects data about user usage patterns of content suggestions, computes
// long-term user metrics locally using pref, and reports the metrics to UMA.
-// TODO(jkrcal): Add classification of users based on the metrics and getters
-// for the classification as well as for the metrics.
+// Based on these lon-term user metrics, it classifies the user in a UserClass.
class UserClassifier {
public:
+ // Enumeration listing user classes
+ enum class UserClass {
+ OCCASIONAL_NTP_USER,
+ NORMAL_NTP_USER,
+ FREQUENT_NTP_USER,
+ };
+
// The provided |pref_service| may be nullptr in unit-tests.
explicit UserClassifier(PrefService* pref_service);
~UserClassifier();
@@ -36,22 +45,45 @@ class UserClassifier {
// When the user clicks on some suggestions or on some "More" button.
void OnSuggestionsUsed();
- private:
- // The event has happened, recompute and store the metric accordingly.
- void UpdateMetricOnEvent(const char* metric_pref_name,
- const char* last_time_pref_name);
+ // Get the estimate average length of the interval between two successive
+ // events of the given type.
+ double GetEstimatedAvgTimeToOpenNTP() const;
+ double GetEstimatedAvgTimeToShowSuggestions() const;
+ double GetEstimatedAvgTimeToUseSuggestions() const;
- // Compute the number of hours between two events for the given metric value
- // assuming the events were equally distributed.
- double GetEstimateHoursBetweenEvents(const char* metric_pref_name);
+ // Return the classification of the current user.
+ UserClass GetUserClass() const;
+ std::string GetUserClassDescriptionForDebugging() const;
- // Returns the number of hours since the last event of the same type or
- // DBL_MAX if there is no last event of that type.
- double GetHoursSinceLastTime(const char* last_time_pref_name);
+ // Resets the classification (emulates a fresh upgrade / install).
+ void ClearClassificationForDebugging();
+
+ private:
+ // For estimating the average length of the intervals between two successive
+ // event, we keep a simple frequency model, a single value that we call
Marc Treib 2016/09/20 10:27:02 s/event/events/
jkrcal 2016/09/20 13:10:13 Done.
+ // "metric" below.
+ // We track exponentially-discounted rate of the given event per hour where
+ // the continuous utility function between two successive events (e.g. opening
+ // a NTP) at times t1 < t2 is 1 / (t2-t1), i.e. intuitively the rate of this
+ // event in this time interval.
+ // See https://en.wikipedia.org/wiki/Exponential_discounting for more details.
+
+ // The event has happened, recompute the metric accordingly. Then store and
+ // return the new value.
+ double UpdateMetricOnEvent(const char* metric_pref_name,
+ const char* last_time_pref_name);
+ // No event has happened but we need to get up-to-date metric, recompute and
+ // return the new value. This function does not store the recomputed metric.
+ double GetUpToDateMetricValue(const char* metric_pref_name,
+ const char* last_time_pref_name) const;
+
+ // Returns the number of hours since the last event of the same type.
+ // If there is no last event of that type, assume it happened just now and
+ // return 0.
+ double GetHoursSinceLastTime(const char* last_time_pref_name) const;
void SetLastTimeToNow(const char* last_time_pref_name);
PrefService* pref_service_;
- double const discount_rate_per_hour_;
DISALLOW_COPY_AND_ASSIGN(UserClassifier);
};

Powered by Google App Engine
This is Rietveld 408576698