| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. | |
| 2 // limitations under the License. | |
| 3 // See the License for the specific language governing permissions and | |
| 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 5 // distributed under the License is distributed on an "AS-IS" BASIS, | |
| 6 // Unless required by applicable law or agreed to in writing, software | |
| 7 // | |
| 8 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 // | |
| 10 // You may obtain a copy of the License at | |
| 11 // you may not use this file except in compliance with the License. | |
| 12 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 13 // | |
| 14 goog.provide('i18n.input.chrome.inputview.Statistics'); | |
| 15 | |
| 16 | |
| 17 | |
| 18 /** | |
| 19 * The statistics util class for input view. | |
| 20 * | |
| 21 * @constructor | |
| 22 */ | |
| 23 i18n.input.chrome.inputview.Statistics = function() { | |
| 24 }; | |
| 25 goog.addSingletonGetter(i18n.input.chrome.inputview.Statistics); | |
| 26 | |
| 27 | |
| 28 /** | |
| 29 * The current layout code. | |
| 30 * | |
| 31 * @type {string} | |
| 32 * @private | |
| 33 */ | |
| 34 i18n.input.chrome.inputview.Statistics.prototype.layoutCode_ = ''; | |
| 35 | |
| 36 | |
| 37 /** | |
| 38 * Sets the current layout code, which will be a part of the metrics name. | |
| 39 * | |
| 40 * @param {string} layoutCode . | |
| 41 */ | |
| 42 i18n.input.chrome.inputview.Statistics.prototype.setCurrentLayout = function( | |
| 43 layoutCode) { | |
| 44 this.layoutCode_ = layoutCode; | |
| 45 }; | |
| 46 | |
| 47 | |
| 48 /** | |
| 49 * Gets the target type based on the given source and target. | |
| 50 * | |
| 51 * @param {string} source . | |
| 52 * @param {string} target . | |
| 53 * @return {number} The target type number value. | |
| 54 */ | |
| 55 i18n.input.chrome.inputview.Statistics.prototype.getTargetType = function( | |
| 56 source, target) { | |
| 57 if (source == target) { | |
| 58 return 0; | |
| 59 } | |
| 60 if (!source) { | |
| 61 return 3; | |
| 62 } | |
| 63 if (target.length > source.length) { | |
| 64 return 2; | |
| 65 } | |
| 66 return 1; | |
| 67 }; | |
| 68 | |
| 69 | |
| 70 /** | |
| 71 * Records the metrics for each commit. | |
| 72 * | |
| 73 * @param {number} sourceLen The source length. | |
| 74 * @param {number} targetLen The target length. | |
| 75 * @param {number} targetIndex The target index. | |
| 76 * @param {number} targetType The target type: | |
| 77 * 0: Source; 1: Correction; 2: Completion; 3: Prediction. | |
| 78 * @param {number} triggerType The trigger type: | |
| 79 * 0: BySpace; 1: ByReset; 2: ByCandidate; 3: BySymbolOrNumber; | |
| 80 * 4: ByDoubleSpaceToPeriod. | |
| 81 */ | |
| 82 i18n.input.chrome.inputview.Statistics.prototype.recordCommit = function( | |
| 83 sourceLen, targetLen, targetIndex, targetType, triggerType) { | |
| 84 if (!this.layoutCode_) { | |
| 85 return; | |
| 86 } | |
| 87 this.recordCount_('Commit.SourceLength', sourceLen); | |
| 88 this.recordCount_('Commit.TargetLength', targetLen); | |
| 89 this.recordCount_('Commit.TargetIndex', targetIndex + 1); // 1-based index. | |
| 90 this.recordCount_('Commit.TargetType', targetType); | |
| 91 this.recordCount_('Commit.TriggerType', triggerType); | |
| 92 }; | |
| 93 | |
| 94 | |
| 95 /** | |
| 96 * Records the VK show time for current keyboard layout. | |
| 97 * | |
| 98 * @param {number} showTimeSeconds The show time in seconds. | |
| 99 */ | |
| 100 i18n.input.chrome.inputview.Statistics.prototype.recordShowTime = function( | |
| 101 showTimeSeconds) { | |
| 102 this.recordCount_('Layout.ShowTime', showTimeSeconds); | |
| 103 }; | |
| 104 | |
| 105 | |
| 106 /** | |
| 107 * Records the layout switching action. | |
| 108 * | |
| 109 * @param {string} layoutCode The layout code to be switched to. | |
| 110 */ | |
| 111 i18n.input.chrome.inputview.Statistics.prototype.recordSwitch = function( | |
| 112 layoutCode) { | |
| 113 this.recordCount_('Layout.SwitchTo.' + layoutCode, 1); | |
| 114 }; | |
| 115 | |
| 116 | |
| 117 /** | |
| 118 * Records the special key action, which is function key like BACKSPACE, ENTER, | |
| 119 * etc.. | |
| 120 * | |
| 121 * @param {string} keyCode . | |
| 122 * @param {boolean} isComposing Whether the key is pressed with composing mode. | |
| 123 */ | |
| 124 i18n.input.chrome.inputview.Statistics.prototype.recordSpecialKey = function( | |
| 125 keyCode, isComposing) { | |
| 126 var name = 'Key.' + isComposing ? 'Composing.' : '' + keyCode; | |
| 127 this.recordCount_(name, 1); | |
| 128 }; | |
| 129 | |
| 130 | |
| 131 /** | |
| 132 * Records count value to chrome UMA framework. | |
| 133 * | |
| 134 * @param {string} name . | |
| 135 * @param {number} count . | |
| 136 * @private | |
| 137 */ | |
| 138 i18n.input.chrome.inputview.Statistics.prototype.recordCount_ = function( | |
| 139 name, count) { | |
| 140 if (!this.layoutCode_) { | |
| 141 return; | |
| 142 } | |
| 143 if (chrome.metricsPrivate && chrome.metricsPrivate.recordCount) { | |
| 144 name = 'InputView.' + name + '.' + this.layoutCode_; | |
| 145 chrome.metricsPrivate.recordCount(name, count); | |
| 146 } | |
| 147 }; | |
| OLD | NEW |