@@ -31,7 +31,8 @@ public class ScoreUpdater {
3131 // start() 被调用前,也就是用户离开前,用户输入所用过的时间。
3232 private LocalTime timeIntervalLast ;
3333
34- // TODO 通过打词键入的字符数
34+ // TODO 通过打词键入的字符数,名字就胡乱取了
35+ private int charCountInWord ;
3536
3637 // TODO :退格 等
3738
@@ -44,6 +45,8 @@ public ScoreUpdater(Score score, ScoreProperties scoreProperties) {
4445 this .startTime = LocalTime .now ();
4546 timeIntervalLast = LocalTime .of (0 , 0 ); // 初始用时为0
4647
48+ this .charCountInWord = 0 ;
49+
4750 // 开启自动更新
4851 updateAutomatically ();
4952 }
@@ -140,26 +143,47 @@ public void incKeyEnterCount() {
140143 }
141144
142145 public void incTypos () {
146+ checkIt ("incTypos" );
147+
143148 score .setTypos (score .getTypos () + 1 );
144149 scoreProperties .setTypos (score .getTyposString ());
145150
146151 logger .debug ("inc typos: {}" , score .getTyposString ());
147152 }
148153
149154 public void decTypos () {
155+ checkIt ("decTypos" );
156+
150157 score .setTypos (score .getTypos () - 1 );
151158 scoreProperties .setTypos (score .getTyposString ());
152159
153160 logger .debug ("dec typos: {}" , score .getTyposString ());
154161 }
155162
163+ public void setTypos (int typos ) {
164+ checkIt ("setTypos" );
165+
166+ score .setTypos (typos );
167+ scoreProperties .setTypos (score .getTyposString ());
168+
169+ logger .debug ("set typos: {}" , score .getTyposString ());
170+ }
171+
156172 public void incBackspaceCount () {
173+ checkIt ("incBackspaceCount" );
174+
157175 score .setBackspaceCount (score .getBackspaceCount () + 1 );
158176 scoreProperties .setBackspaceCount (score .getBackspaceCountString ());
159177
160178 logger .debug ("inc BackspaceCount: {}" , score .getBackspaceCount ());
161179 }
162180
181+ public void addToCharCountInWord (int count ) {
182+ checkIt ("addToCharCountInWord" );
183+
184+ this .charCountInWord += count ;
185+ }
186+
163187 /**
164188 * 开始更新,用户开始输入
165189 */
@@ -234,8 +258,10 @@ private void updateScore() {
234258 score .setKeysEachChar (newKeysEachChar );
235259 scoreProperties .setKeysEachChar (score .getKeysEachCharString ());
236260
237- // TODO 5. 更新 打词率
238-
261+ // 5. 更新 打词比率
262+ double newRatioOfWords = charCountInWord / (double ) score .getCharactersCount ();
263+ score .setRatioOfWords (newRatioOfWords );
264+ scoreProperties .setRatioOfWords (score .getRatioOfWordsString ());
239265
240266 // TODO 6. 更新 键准
241267 }
@@ -250,14 +276,16 @@ public void reInit() {
250276
251277 this .active = false ;
252278 this .startTime = LocalTime .now ();
253- timeIntervalLast = LocalTime .of (0 , 0 );
279+ this .timeIntervalLast = LocalTime .of (0 , 0 );
280+
281+ this .charCountInWord = 0 ;
254282
255283 logger .info ("重置成绩。" );
256284 }
257285
258286
259287 /**
260- * TODO 生成收文机器人能识别的成绩字符串
288+ * 生成收文机器人能识别的成绩字符串
261289 */
262290 @ Override
263291 public String toString () {
0 commit comments