Skip to content

Commit 83557c3

Browse files
authored
Change per recipient stats to use email as key (#12123)
1 parent a34c936 commit 83557c3

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/web/app/components/question-types/question-statistics/question-statistics-calculation/rubric-question-statistics-calculation.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,28 @@ export class RubricQuestionStatisticsCalculation
9898

9999
// calculate per recipient stats
100100
for (const response of this.responses) {
101-
this.perRecipientStatsMap[response.recipient] = this.perRecipientStatsMap[response.recipient] || {
102-
recipientName: response.recipient,
103-
recipientEmail: response.recipientEmail,
104-
recipientTeam: response.recipientTeam,
105-
answers: JSON.parse(JSON.stringify(emptyAnswers)),
106-
answersSum: [],
107-
percentages: [],
108-
percentagesAverage: [],
109-
weightsAverage: [],
110-
subQuestionTotalChosenWeight: this.subQuestions.map(() => 0),
111-
subQuestionWeightAverage: [],
112-
};
101+
this.perRecipientStatsMap[response.recipientEmail || response.recipient] =
102+
this.perRecipientStatsMap[
103+
response.recipientEmail || response.recipient
104+
] || {
105+
recipientName: response.recipient,
106+
recipientEmail: response.recipientEmail,
107+
recipientTeam: response.recipientTeam,
108+
answers: JSON.parse(JSON.stringify(emptyAnswers)),
109+
answersSum: [],
110+
percentages: [],
111+
percentagesAverage: [],
112+
weightsAverage: [],
113+
subQuestionTotalChosenWeight: this.subQuestions.map(() => 0),
114+
subQuestionWeightAverage: [],
115+
};
113116
for (let i: number = 0; i < response.responseDetails.answer.length; i += 1) {
114117
const subAnswer: number = response.responseDetails.answer[i];
115118
if (subAnswer === RUBRIC_ANSWER_NOT_CHOSEN) {
116119
continue;
117120
}
118-
this.perRecipientStatsMap[response.recipient].answers[i][subAnswer] += 1;
119-
this.perRecipientStatsMap[response.recipient].subQuestionTotalChosenWeight[i] +=
121+
this.perRecipientStatsMap[response.recipientEmail || response.recipient].answers[i][subAnswer] += 1;
122+
this.perRecipientStatsMap[response.recipientEmail || response.recipient].subQuestionTotalChosenWeight[i] +=
120123
+this.weights[i][subAnswer].toFixed(5);
121124
}
122125
}

src/web/app/components/question-types/question-statistics/test-data/rubricQuestionResponses.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
}
5959
],
6060
"expectedStatsMap": {
61-
"Alice": {
61+
6262
"answers": [
6363
[1, 1], [1, 1], [2, 0]
6464
],
@@ -76,7 +76,7 @@
7676
"overallWeightedSum": 2.8,
7777
"overallWeightAverage": 0.47
7878
},
79-
"Bob": {
79+
8080
"answers": [
8181
[2, 0], [1, 1], [2, 0]
8282
],

0 commit comments

Comments
 (0)