From a59914b68e5add80737a3a1d01575ac2a6597748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Mon, 10 Dec 2018 13:26:38 +0100 Subject: [PATCH] Fix counting of multiple-choice answers --- .../list-statistic.component.html | 24 ++++++++++++------- .../list-statistic.component.ts | 22 +++++++++++++---- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/app/components/shared/list-statistic/list-statistic.component.html b/src/app/components/shared/list-statistic/list-statistic.component.html index 9be304daa..5c327e230 100644 --- a/src/app/components/shared/list-statistic/list-statistic.component.html +++ b/src/app/components/shared/list-statistic/list-statistic.component.html @@ -10,29 +10,37 @@ <ng-container matColumnDef="content"> <mat-header-cell *matHeaderCellDef> {{'content.content' | translate}} </mat-header-cell> - <mat-cell *matCellDef="let cp" [ngClass]="{'positiveC' : cp.percent >= status.good, - 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, + <mat-cell *matCellDef="let cp" [ngClass]="{ + 'positiveC' : cp.percent >= status.good, + 'okayC' : cp.percent >= status.okay && cp.percent < status.good, + 'negativeC' : cp.percent < status.okay, 'emptyCC' : cp.percent < status.zero }">{{cp.content.subject}}</mat-cell> </ng-container> <ng-container matColumnDef="percentage"> <mat-header-cell *matHeaderCellDef> {{'statistic.percentage' | translate }} </mat-header-cell> - <mat-cell *matCellDef="let cp" [ngClass]="{'positiveC' : cp.percent >= status.good, - 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, + <mat-cell *matCellDef="let cp" [ngClass]="{ + 'positiveC' : cp.percent >= status.good, + 'okayC' : cp.percent >= status.okay && cp.percent < status.good, + 'negativeC' : cp.percent < status.okay, 'emptyC' : cp.percent < status.zero }">{{cp.percent.toFixed() + ' %'}}</mat-cell> </ng-container> <ng-container matColumnDef="counts"> <mat-header-cell *matHeaderCellDef> {{'statistic.total' | translate}} </mat-header-cell> - <mat-cell *matCellDef="let cp" [ngClass]="{'positiveC' : cp.percent >= status.good, - 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, + <mat-cell *matCellDef="let cp" [ngClass]="{ + 'positiveC' : cp.percent >= status.good, + 'okayC' : cp.percent >= status.okay && cp.percent < status.good, + 'negativeC' : cp.percent < status.okay, 'emptyC' : cp.percent < status.zero }">{{cp.counts}}</mat-cell> </ng-container> <ng-container matColumnDef="abstentions"> <mat-header-cell *matHeaderCellDef> {{'statistic.abstentions' | translate}} </mat-header-cell> - <mat-cell *matCellDef="let cp" [ngClass]="{'positiveC' : cp.percent >= status.good, - 'okayC' : cp.percent >= status.okay && cp.percent < status.good, 'negativeC' : cp.percent < status.okay, + <mat-cell *matCellDef="let cp" [ngClass]="{ + 'positiveC' : cp.percent >= status.good, + 'okayC' : cp.percent >= status.okay && cp.percent < status.good, + 'negativeC' : cp.percent < status.okay, 'emptyC' : cp.percent < status.zero }">{{cp.abstentions}}</mat-cell> </ng-container> 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 69a2c2f05..d9889f421 100644 --- a/src/app/components/shared/list-statistic/list-statistic.component.ts +++ b/src/app/components/shared/list-statistic/list-statistic.component.ts @@ -69,11 +69,12 @@ export class ListStatisticComponent implements OnInit { this.contentService.getAnswer(contents[i].id).subscribe(answer => { if (contents[i].multiple) { percent = this.evaluateMultiple(contents[i].options, answer.roundStatistics[0].combinatedCounts); + this.dataSource[i].counts = this.getMultipleCounts(answer.roundStatistics[0].combinatedCounts); } else { percent = this.evaluateSingle(contents[i].options, answer.roundStatistics[0].independentCounts); + this.dataSource[i].counts = this.getSingleCounts(answer.roundStatistics[0].independentCounts); } this.dataSource[i].abstentions = answer.roundStatistics[0].abstentionCount; - this.dataSource[i].counts = this.getTotalCounts(answer.roundStatistics[0].independentCounts); this.dataSource[i].percent = percent; if (percent >= 0) { this.totalP += percent; @@ -88,11 +89,24 @@ export class ListStatisticComponent implements OnInit { } } - getTotalCounts(indCounts: number[]): number { + getSingleCounts(answers: number[]): number { let total = 0; - const indLength = indCounts.length; + const indLength = answers.length; for (let i = 0; i < indLength; i++) { - total += indCounts[i]; + total += answers[i]; + } + return total; + } + + getMultipleCounts(answers: Combination[]): number { + let total = 0; + if (answers) { + const indLength = answers.length; + for (let i = 0; i < indLength; i++) { + total += answers[i].count; + } + } else { + total = -1; } return total; } -- GitLab