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

Unified Diff: third_party/google_input_tools/src/chrome/os/statistics.js

Issue 1013263002: Update Google Input Tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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: third_party/google_input_tools/src/chrome/os/statistics.js
diff --git a/third_party/google_input_tools/src/chrome/os/statistics.js b/third_party/google_input_tools/src/chrome/os/statistics.js
index d08a0040e71053419d5831e5b0e4ad387e20e0f7..26fc3f52a2a74ee7f7be4f420259c4c177ec9397 100644
--- a/third_party/google_input_tools/src/chrome/os/statistics.js
+++ b/third_party/google_input_tools/src/chrome/os/statistics.js
@@ -87,6 +87,40 @@ Statistics.prototype.charactersBetweenBackspaces_ = 0;
/**
+ * Maximum pause duration in milliseconds.
+ *
+ * @private {number}
+ * @const
+ */
+Statistics.prototype.MAX_PAUSE_DURATION_ = 3000;
+
+
+/**
+ * Minimum words typed before committing the WPM statistic.
+ *
+ * @private {number}
+ * @const
+ */
+Statistics.prototype.MIN_WORDS_FOR_WPM_ = 10;
+
+
+/**
+ * Timestamp of last activity.
+ *
+ * @private {number}
+ */
+Statistics.prototype.lastActivityTimeStamp_ = 0;
+
+
+/**
+ * Time spent typing.
+ *
+ * @private {number}
+ */
+Statistics.prototype.typingDuration_ = 0;
+
+
+/**
* Whether recording for physical keyboard specially.
*
* @private {boolean}
@@ -111,6 +145,14 @@ Statistics.prototype.charactersCommitted_ = 0;
/**
+ * The number of characters to ignore when calculating WPM.
+ *
+ * @private {number}
+ */
+Statistics.prototype.droppedKeys_ = 0;
+
+
+/**
* Sets whether recording for physical keyboard.
*
* @param {boolean} isPhysicalKeyboard .
@@ -175,11 +217,20 @@ Statistics.prototype.recordSessionEnd = function() {
// excudes the focus loss-gain on the new tab page from being counted.
if (this.charactersCommitted_ > 0) {
this.recordValue('InputMethod.VirtualKeyboard.CharactersCommitted',
- this.charactersCommitted_, 16384, 50);
- // TODO: Add WPM metrics.
+ this.charactersCommitted_, 16384, 50);
+ var words = (this.charactersCommitted_ - this.droppedKeys_) / 5;
+ if (this.typingDuration_ > 0 && words > this.MIN_WORDS_FOR_WPM_) {
+ // Milliseconds to minutes.
+ var minutes = this.typingDuration_ / 60000;
+ this.recordValue('InputMethod.VirtualKeyboard.WordsPerMinute',
+ Math.round(words / minutes), 100, 100);
+ }
}
+ this.droppedKeys_ = 0;
this.charactersCommitted_ = 0;
this.lastCommitLength_ = 0;
+ this.typingDuration_ = 0;
+ this.lastActivityTimeStamp_ = 0;
};
@@ -363,6 +414,19 @@ Statistics.prototype.recordValue = function(
* Records a key down.
*/
Statistics.prototype.recordCharacterKey = function() {
+ var now = Date.now();
+ if (this.lastActivityTimeStamp_) {
+ if (now < (this.lastActivityTimeStamp_ + this.MAX_PAUSE_DURATION_)) {
+ this.typingDuration_ += (now - this.lastActivityTimeStamp_);
+ } else {
+ // Exceeded pause duration. Ignore this character.
+ this.droppedKeys_++;
+ }
+ } else {
+ // Ignore the first character in the new session.
+ this.droppedKeys_++;
+ }
+ this.lastActivityTimeStamp_ = now;
this.charactersBetweenBackspaces_++;
};

Powered by Google App Engine
This is Rietveld 408576698