From e06df9059b54420f3d6dca96d17ba729ebed132e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Mon, 3 Dec 2018 17:18:59 +0100 Subject: [PATCH] Try to fix evaluation of multiple-choice-content answers --- .../list-statistic.component.ts | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/app/components/shared/list-statistic/list-statistic.component.ts b/src/app/components/shared/list-statistic/list-statistic.component.ts index de4cd5feb..a8f51b5fc 100644 --- a/src/app/components/shared/list-statistic/list-statistic.component.ts +++ b/src/app/components/shared/list-statistic/list-statistic.component.ts @@ -50,7 +50,7 @@ export class ListStatisticComponent implements OnInit { this.dataSource[i].content = this.contents[i]; if (contents[i].format === ContentType.CHOICE) { this.contentService.getAnswer(contents[i].id).subscribe(answer => { - const percent = this.getCountCorrect(contents[i].options, answer.roundStatistics[0].independentCounts); + const percent = this.getCountCorrect(contents[i].options, answer.roundStatistics[0].independentCounts, contents[i].multiple); this.dataSource[i].percent = percent; if (percent >= 0) { console.log(percent); @@ -64,22 +64,45 @@ export class ListStatisticComponent implements OnInit { } } - getCountCorrect(options: AnswerOption[], indCounts: number[]): number { - let correctIndex; + getCountCorrect(options: AnswerOption[], indCounts: number[], multiple: boolean): number { this.correctCounts = 0; this.totalCounts = 0; const length = options.length; + let correctIndex = new Array<number>(); let res: number; - for (let i = 0; i < length; i++) { - if (options[i].points > 0) { - correctIndex = i; + if (multiple) { + let cic = 0; + let cac = 0; + let idc = 0; + for (let i = 0; i < length; i++) { + if (options[i].points > 0) { + correctIndex[cic] = i; + cic++; + } } - } - for (let i = 0; i < length; i++) { - if (i === correctIndex) { - this.correctCounts += indCounts[i]; + for (let i = 0; i < length; i++) { + if (correctIndex.includes(i)) { + cac++; + } + idc = indCounts[i]; + if (cac === cic) { + this.correctCounts += idc; + cac = 0; + } + this.totalCounts += idc; + } + } else { + for (let i = 0; i < length; i++) { + if (options[i].points > 0) { + correctIndex[0] = i; + } + } + for (let i = 0; i < length; i++) { + if (correctIndex.includes(i)) { + this.correctCounts += indCounts[i]; + } + this.totalCounts += indCounts[i]; } - this.totalCounts += indCounts[i]; } if (this.totalCounts) { res = ((this.correctCounts / this.totalCounts) * 100); -- GitLab