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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
2 // limitations under the License. 2 // limitations under the License.
3 // See the License for the specific language governing permissions and 3 // See the License for the specific language governing permissions and
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 // distributed under the License is distributed on an "AS-IS" BASIS, 5 // distributed under the License is distributed on an "AS-IS" BASIS,
6 // Unless required by applicable law or agreed to in writing, software 6 // Unless required by applicable law or agreed to in writing, software
7 // 7 //
8 // http://www.apache.org/licenses/LICENSE-2.0 8 // http://www.apache.org/licenses/LICENSE-2.0
9 // 9 //
10 // You may obtain a copy of the License at 10 // You may obtain a copy of the License at
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 /** 81 /**
82 * Number of characters entered between each backspace. 82 * Number of characters entered between each backspace.
83 * 83 *
84 * @private {number} 84 * @private {number}
85 */ 85 */
86 Statistics.prototype.charactersBetweenBackspaces_ = 0; 86 Statistics.prototype.charactersBetweenBackspaces_ = 0;
87 87
88 88
89 /** 89 /**
90 * Maximum pause duration in milliseconds.
91 *
92 * @private {number}
93 * @const
94 */
95 Statistics.prototype.MAX_PAUSE_DURATION_ = 3000;
96
97
98 /**
99 * Minimum words typed before committing the WPM statistic.
100 *
101 * @private {number}
102 * @const
103 */
104 Statistics.prototype.MIN_WORDS_FOR_WPM_ = 10;
105
106
107 /**
108 * Timestamp of last activity.
109 *
110 * @private {number}
111 */
112 Statistics.prototype.lastActivityTimeStamp_ = 0;
113
114
115 /**
116 * Time spent typing.
117 *
118 * @private {number}
119 */
120 Statistics.prototype.typingDuration_ = 0;
121
122
123 /**
90 * Whether recording for physical keyboard specially. 124 * Whether recording for physical keyboard specially.
91 * 125 *
92 * @private {boolean} 126 * @private {boolean}
93 */ 127 */
94 Statistics.prototype.isPhysicalKeyboard_ = false; 128 Statistics.prototype.isPhysicalKeyboard_ = false;
95 129
96 130
97 /** 131 /**
98 * The length of the last text commit. 132 * The length of the last text commit.
99 * 133 *
100 * @private {number} 134 * @private {number}
101 */ 135 */
102 Statistics.prototype.lastCommitLength_ = 0; 136 Statistics.prototype.lastCommitLength_ = 0;
103 137
104 138
105 /** 139 /**
106 * The number of characters typed in this session. 140 * The number of characters typed in this session.
107 * 141 *
108 * @private {number} 142 * @private {number}
109 */ 143 */
110 Statistics.prototype.charactersCommitted_ = 0; 144 Statistics.prototype.charactersCommitted_ = 0;
111 145
112 146
113 /** 147 /**
148 * The number of characters to ignore when calculating WPM.
149 *
150 * @private {number}
151 */
152 Statistics.prototype.droppedKeys_ = 0;
153
154
155 /**
114 * Sets whether recording for physical keyboard. 156 * Sets whether recording for physical keyboard.
115 * 157 *
116 * @param {boolean} isPhysicalKeyboard . 158 * @param {boolean} isPhysicalKeyboard .
117 */ 159 */
118 Statistics.prototype.setPhysicalKeyboard = function(isPhysicalKeyboard) { 160 Statistics.prototype.setPhysicalKeyboard = function(isPhysicalKeyboard) {
119 this.isPhysicalKeyboard_ = isPhysicalKeyboard; 161 this.isPhysicalKeyboard_ = isPhysicalKeyboard;
120 }; 162 };
121 163
122 164
123 /** 165 /**
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 210
169 211
170 /** 212 /**
171 * Records that the controller session ended. 213 * Records that the controller session ended.
172 */ 214 */
173 Statistics.prototype.recordSessionEnd = function() { 215 Statistics.prototype.recordSessionEnd = function() {
174 // Do not record cases where we gain and immediately lose focus. This also 216 // Do not record cases where we gain and immediately lose focus. This also
175 // excudes the focus loss-gain on the new tab page from being counted. 217 // excudes the focus loss-gain on the new tab page from being counted.
176 if (this.charactersCommitted_ > 0) { 218 if (this.charactersCommitted_ > 0) {
177 this.recordValue('InputMethod.VirtualKeyboard.CharactersCommitted', 219 this.recordValue('InputMethod.VirtualKeyboard.CharactersCommitted',
178 this.charactersCommitted_, 16384, 50); 220 this.charactersCommitted_, 16384, 50);
179 // TODO: Add WPM metrics. 221 var words = (this.charactersCommitted_ - this.droppedKeys_) / 5;
222 if (this.typingDuration_ > 0 && words > this.MIN_WORDS_FOR_WPM_) {
223 // Milliseconds to minutes.
224 var minutes = this.typingDuration_ / 60000;
225 this.recordValue('InputMethod.VirtualKeyboard.WordsPerMinute',
226 Math.round(words / minutes), 100, 100);
227 }
180 } 228 }
229 this.droppedKeys_ = 0;
181 this.charactersCommitted_ = 0; 230 this.charactersCommitted_ = 0;
182 this.lastCommitLength_ = 0; 231 this.lastCommitLength_ = 0;
232 this.typingDuration_ = 0;
233 this.lastActivityTimeStamp_ = 0;
183 }; 234 };
184 235
185 236
186 /** 237 /**
187 * Records the metrics for each commit. 238 * Records the metrics for each commit.
188 * 239 *
189 * @param {string} source . 240 * @param {string} source .
190 * @param {string} target . 241 * @param {string} target .
191 * @param {number} targetIndex The target index. 242 * @param {number} targetIndex The target index.
192 * @param {number} triggerType The trigger type: 243 * @param {number} triggerType The trigger type:
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 'buckets': bucketCount 407 'buckets': bucketCount
357 }, count); 408 }, count);
358 } 409 }
359 }; 410 };
360 411
361 412
362 /** 413 /**
363 * Records a key down. 414 * Records a key down.
364 */ 415 */
365 Statistics.prototype.recordCharacterKey = function() { 416 Statistics.prototype.recordCharacterKey = function() {
417 var now = Date.now();
418 if (this.lastActivityTimeStamp_) {
419 if (now < (this.lastActivityTimeStamp_ + this.MAX_PAUSE_DURATION_)) {
420 this.typingDuration_ += (now - this.lastActivityTimeStamp_);
421 } else {
422 // Exceeded pause duration. Ignore this character.
423 this.droppedKeys_++;
424 }
425 } else {
426 // Ignore the first character in the new session.
427 this.droppedKeys_++;
428 }
429 this.lastActivityTimeStamp_ = now;
366 this.charactersBetweenBackspaces_++; 430 this.charactersBetweenBackspaces_++;
367 }; 431 };
368 432
369 433
370 /** 434 /**
371 * Records a backspace. 435 * Records a backspace.
372 */ 436 */
373 Statistics.prototype.recordBackspace = function() { 437 Statistics.prototype.recordBackspace = function() {
374 // Ignore multiple backspaces typed in succession. 438 // Ignore multiple backspaces typed in succession.
375 if (this.charactersBetweenBackspaces_ > 0) { 439 if (this.charactersBetweenBackspaces_ > 0) {
376 this.recordValue( 440 this.recordValue(
377 'InputMethod.VirtualKeyboard.CharactersBetweenBackspaces', 441 'InputMethod.VirtualKeyboard.CharactersBetweenBackspaces',
378 this.charactersBetweenBackspaces_, 4096, 50); 442 this.charactersBetweenBackspaces_, 4096, 50);
379 } 443 }
380 this.charactersBetweenBackspaces_ = 0; 444 this.charactersBetweenBackspaces_ = 0;
381 }; 445 };
382 }); // goog.scope 446 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698