Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 | |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/time/time.h" | |
| 9 | 12 |
| 10 class PrefRegistrySimple; | 13 class PrefRegistrySimple; |
| 11 class PrefService; | 14 class PrefService; |
| 12 | 15 |
| 13 namespace ntp_snippets { | 16 namespace ntp_snippets { |
| 14 | 17 |
| 15 // Collects data about user usage patterns of content suggestions, computes | 18 // Collects data about user usage patterns of content suggestions, computes |
| 16 // long-term user metrics locally using pref, and reports the metrics to UMA. | 19 // long-term user metrics locally using pref, and reports the metrics to UMA. |
| 17 // TODO(jkrcal): Add classification of users based on the metrics and getters | 20 // Based on these lon-term user metrics, it classifies the user in a UserClass. |
| 18 // for the classification as well as for the metrics. | |
| 19 class UserClassifier { | 21 class UserClassifier { |
| 20 public: | 22 public: |
| 23 // Enumeration listing user classes | |
| 24 enum class UserClass { | |
| 25 OCCASIONAL_NTP_USER, | |
|
tschumann
2016/09/20 11:32:47
i wonder if 'occasional' isn't too generous.
This
jkrcal
2016/09/20 13:10:13
Done - RARE.
Replace NORMAL by ORDINARY. Have real
Marc Treib
2016/09/20 13:26:52
MODERATE?
jkrcal
2016/09/20 13:46:39
Renamed differently after an offline discussion wi
| |
| 26 NORMAL_NTP_USER, | |
| 27 FREQUENT_NTP_USER, | |
| 28 }; | |
| 29 | |
| 21 // The provided |pref_service| may be nullptr in unit-tests. | 30 // The provided |pref_service| may be nullptr in unit-tests. |
| 22 explicit UserClassifier(PrefService* pref_service); | 31 explicit UserClassifier(PrefService* pref_service); |
| 23 ~UserClassifier(); | 32 ~UserClassifier(); |
| 24 | 33 |
| 25 // Registers profile prefs for all metrics. Called from browser_prefs.cc. | 34 // Registers profile prefs for all metrics. Called from browser_prefs.cc. |
| 26 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 35 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 27 | 36 |
| 28 // When the user opens a new NTP - this indicates potential use of content | 37 // When the user opens a new NTP - this indicates potential use of content |
| 29 // suggestions. | 38 // suggestions. |
| 30 void OnNTPOpened(); | 39 void OnNTPOpened(); |
| 31 | 40 |
| 32 // When the content suggestions are shown to the user - in the current | 41 // When the content suggestions are shown to the user - in the current |
| 33 // implementation when the user scrolls below the fold. | 42 // implementation when the user scrolls below the fold. |
| 34 void OnSuggestionsShown(); | 43 void OnSuggestionsShown(); |
| 35 | 44 |
| 36 // When the user clicks on some suggestions or on some "More" button. | 45 // When the user clicks on some suggestions or on some "More" button. |
| 37 void OnSuggestionsUsed(); | 46 void OnSuggestionsUsed(); |
| 38 | 47 |
| 48 // Get the estimate average length of the interval between two successive | |
| 49 // events of the given type. | |
| 50 double GetEstimatedAvgTimeToOpenNTP() const; | |
| 51 double GetEstimatedAvgTimeToShowSuggestions() const; | |
| 52 double GetEstimatedAvgTimeToUseSuggestions() const; | |
| 53 | |
| 54 // Return the classification of the current user. | |
| 55 UserClass GetUserClass() const; | |
| 56 std::string GetUserClassDescriptionForDebugging() const; | |
| 57 | |
| 58 // Resets the classification (emulates a fresh upgrade / install). | |
| 59 void ClearClassificationForDebugging(); | |
| 60 | |
| 39 private: | 61 private: |
| 40 // The event has happened, recompute and store the metric accordingly. | 62 // For estimating the average length of the intervals between two successive |
| 41 void UpdateMetricOnEvent(const char* metric_pref_name, | 63 // event, we keep a simple frequency model, a single value that we call |
| 42 const char* last_time_pref_name); | 64 // "metric" below. |
| 65 // We track exponentially-discounted rate of the given event per hour where | |
| 66 // the continuous utility function between two successive events (e.g. opening | |
| 67 // a NTP) at times t1 < t2 is 1 / (t2-t1), i.e. intuitively the rate of this | |
| 68 // event in this time interval. | |
| 69 // See https://en.wikipedia.org/wiki/Exponential_discounting for more details. | |
| 43 | 70 |
| 44 // Compute the number of hours between two events for the given metric value | 71 enum Metric { OPEN_NTP = 0, SHOW_SUGGESTIONS, USE_SUGGESTIONS }; |
|
Marc Treib
2016/09/20 10:27:03
enum class? You're using it like "Metric::..." any
tschumann
2016/09/20 11:32:47
naming nit: these constants sound like they would
jkrcal
2016/09/20 13:10:13
Tim, done.
jkrcal
2016/09/20 13:10:14
Marc, if I make it an enum class, it forces me to
Marc Treib
2016/09/20 13:26:52
E.g. you couldn't access the members without the "
jkrcal
2016/09/20 13:46:39
Done.
| |
| 45 // assuming the events were equally distributed. | 72 static const Metric kMetrics[3]; |
|
Marc Treib
2016/09/20 10:27:03
Could you just define this in the .cc?
jkrcal
2016/09/20 13:10:13
Done. (I needed to make the Metric enum public whi
| |
| 46 double GetEstimateHoursBetweenEvents(const char* metric_pref_name); | |
| 47 | 73 |
| 48 // Returns the number of hours since the last event of the same type or | 74 // Get the estimate average length of the interval between two successive |
| 49 // DBL_MAX if there is no last event of that type. | 75 // events of the given type. |
| 50 double GetHoursSinceLastTime(const char* last_time_pref_name); | 76 double GetEstimatedAvgTime(const Metric metric) const; |
|
Marc Treib
2016/09/20 10:27:03
nit: "const Metric" doesn't do anything here - you
jkrcal
2016/09/20 13:10:13
Done.
| |
| 51 void SetLastTimeToNow(const char* last_time_pref_name); | 77 |
| 78 // The event has happened, recompute the metric accordingly. Then store and | |
| 79 // return the new value. | |
| 80 double UpdateMetricOnEvent(const Metric metric); | |
| 81 // No event has happened but we need to get up-to-date metric, recompute and | |
| 82 // return the new value. This function does not store the recomputed metric. | |
| 83 double GetUpToDateMetricValue(const Metric metric) const; | |
| 84 | |
| 85 // Returns the number of hours since the last event of the same type. | |
| 86 // If there is no last event of that type, assume it happened just now and | |
| 87 // return 0. | |
| 88 double GetHoursSinceLastTime(const Metric metric) const; | |
| 89 bool HasLastTime(const Metric metric) const; | |
| 90 void SetLastTimeToNow(const Metric metric); | |
| 91 | |
| 92 double GetMetricValue(const Metric metric) const; | |
| 93 void SetMetricValue(const Metric metric, double metric_value); | |
| 94 void ClearMetricValue(const Metric metric); | |
| 52 | 95 |
| 53 PrefService* pref_service_; | 96 PrefService* pref_service_; |
| 54 double const discount_rate_per_hour_; | |
| 55 | 97 |
| 56 DISALLOW_COPY_AND_ASSIGN(UserClassifier); | 98 DISALLOW_COPY_AND_ASSIGN(UserClassifier); |
| 57 }; | 99 }; |
| 58 | 100 |
| 59 } // namespace ntp_snippets | 101 } // namespace ntp_snippets |
| 60 | 102 |
| 61 #endif // COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ | 103 #endif // COMPONENTS_NTP_SNIPPETS_USER_CLASSIFIER_H_ |
| OLD | NEW |