Skip to content
This repository was archived by the owner on Mar 26, 2019. It is now read-only.

Commit 0cbfdd9

Browse files
committed
完成打词率属性
1 parent 7ba3965 commit 0cbfdd9

File tree

3 files changed

+106
-61
lines changed

3 files changed

+106
-61
lines changed

.idea/workspace.xml

Lines changed: 68 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/me/ryan/controller/TextController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public void update(KeyEvent keyEvent) {
115115
updateKeys(keyEvent);
116116

117117
// 2. 更新和文本有关的内容
118+
// TODO 只在已经上屏时, 才调用 updateText() 方法. (需要找到一个检测字符是否已经上屏的方法,)
118119
updateText();
119120
}
120121

@@ -132,7 +133,10 @@ private void updateText() {
132133

133134
if (inputLengthLast < inputLengthNow) {
134135
// 1. 更新字符数
135-
scoreUpdater.addToCharactersCount(inputLengthNow - inputLengthLast);
136+
int count = inputLengthNow - inputLengthLast;
137+
scoreUpdater.addToCharactersCount(count);
138+
// 如果字符数添加了不止一个,还要更新打词字符数
139+
136140

137141
// 2. 检测刚刚键入的字符是否敲对了
138142
for (int i = inputLengthLast; i < inputLengthNow; i++) {

src/main/java/me/ryan/model/ScoreUpdater.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)