Commit 7a828e24 authored by 李维's avatar 李维

fix: 调整overall的计算方式

parent 47477962
...@@ -859,7 +859,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -859,7 +859,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
// 如果有录音数据,则使用其分数 // 如果有录音数据,则使用其分数
if (lastVoice && lastVoice.result && lastVoice.questionId == this.touchData.id) { if (lastVoice && lastVoice.result && lastVoice.questionId == this.touchData.id) {
const score = lastVoice.result.overall; const score = this.calcAverageScore(lastVoice);
if (score >= 10) { if (score >= 10) {
this.onRecordSuccess(); this.onRecordSuccess();
} else { } else {
...@@ -1068,6 +1068,23 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1068,6 +1068,23 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
private calcAverageScore(data) {
const sentences = data && data.result && Array.isArray(data.result.sentences)
? data.result.sentences
: [];
if (!sentences.length) {
return Number(data && data.result && data.result.overall) || 0;
}
let totalScore = 0;
for (let i = 0; i < sentences.length; i++) {
totalScore += Number(sentences[i] && sentences[i].overall) || 0;
}
return Math.ceil(totalScore / sentences.length);
}
/** 是否需要再次尝试 */ /** 是否需要再次尝试 */
private tryAgain: boolean = false; private tryAgain: boolean = false;
...@@ -1085,7 +1102,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1085,7 +1102,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
data.questionId = this.touchData.id; data.questionId = this.touchData.id;
// 获取评分和检查单词正确性 // 获取评分和检查单词正确性
let score = data.result.overall; let score = this.calcAverageScore(data);
if (data && data.result) {
data.result.overall = score;
}
this.log("score: " + score); this.log("score: " + score);
let isSuccess = this.checkWords(data); let isSuccess = this.checkWords(data);
this.log("data: " + JSON.stringify(data)); this.log("data: " + JSON.stringify(data));
...@@ -1237,11 +1257,12 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1237,11 +1257,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
const details = [] const details = []
let totalScore = 0; let totalScore = 0;
for(let i = 0; i < voices.length; i++) { for(let i = 0; i < voices.length; i++) {
const score = this.calcAverageScore(voices[i]);
details.push({ details.push({
recorder_url: voices[i].audioUrl, recorder_url: voices[i].audioUrl,
score: voices[i].result.overall score: score
}) })
totalScore += Number.parseInt(voices[i].result.overall) || 0; totalScore += score;
} }
// 计算平均分 // 计算平均分
data.score = Math.ceil(totalScore / voices.length); data.score = Math.ceil(totalScore / voices.length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment