From 83557c3656d916628c76cec69cf72ed87e187afd Mon Sep 17 00:00:00 2001 From: Samuel Fang <60355570+samuelfangjw@users.noreply.github.com> Date: Thu, 23 Feb 2023 02:44:12 +0800 Subject: [PATCH] Change per recipient stats to use email as key (#12123) --- .../rubric-question-statistics-calculation.ts | 31 ++++++++++--------- .../test-data/rubricQuestionResponses.json | 4 +-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/web/app/components/question-types/question-statistics/question-statistics-calculation/rubric-question-statistics-calculation.ts b/src/web/app/components/question-types/question-statistics/question-statistics-calculation/rubric-question-statistics-calculation.ts index 7612d1a4bfb..5e5ae7d370a 100644 --- a/src/web/app/components/question-types/question-statistics/question-statistics-calculation/rubric-question-statistics-calculation.ts +++ b/src/web/app/components/question-types/question-statistics/question-statistics-calculation/rubric-question-statistics-calculation.ts @@ -98,25 +98,28 @@ export class RubricQuestionStatisticsCalculation // calculate per recipient stats for (const response of this.responses) { - this.perRecipientStatsMap[response.recipient] = this.perRecipientStatsMap[response.recipient] || { - recipientName: response.recipient, - recipientEmail: response.recipientEmail, - recipientTeam: response.recipientTeam, - answers: JSON.parse(JSON.stringify(emptyAnswers)), - answersSum: [], - percentages: [], - percentagesAverage: [], - weightsAverage: [], - subQuestionTotalChosenWeight: this.subQuestions.map(() => 0), - subQuestionWeightAverage: [], - }; + this.perRecipientStatsMap[response.recipientEmail || response.recipient] = + this.perRecipientStatsMap[ + response.recipientEmail || response.recipient + ] || { + recipientName: response.recipient, + recipientEmail: response.recipientEmail, + recipientTeam: response.recipientTeam, + answers: JSON.parse(JSON.stringify(emptyAnswers)), + answersSum: [], + percentages: [], + percentagesAverage: [], + weightsAverage: [], + subQuestionTotalChosenWeight: this.subQuestions.map(() => 0), + subQuestionWeightAverage: [], + }; for (let i: number = 0; i < response.responseDetails.answer.length; i += 1) { const subAnswer: number = response.responseDetails.answer[i]; if (subAnswer === RUBRIC_ANSWER_NOT_CHOSEN) { continue; } - this.perRecipientStatsMap[response.recipient].answers[i][subAnswer] += 1; - this.perRecipientStatsMap[response.recipient].subQuestionTotalChosenWeight[i] += + this.perRecipientStatsMap[response.recipientEmail || response.recipient].answers[i][subAnswer] += 1; + this.perRecipientStatsMap[response.recipientEmail || response.recipient].subQuestionTotalChosenWeight[i] += +this.weights[i][subAnswer].toFixed(5); } } diff --git a/src/web/app/components/question-types/question-statistics/test-data/rubricQuestionResponses.json b/src/web/app/components/question-types/question-statistics/test-data/rubricQuestionResponses.json index c829f05d5b5..e6623a372fc 100644 --- a/src/web/app/components/question-types/question-statistics/test-data/rubricQuestionResponses.json +++ b/src/web/app/components/question-types/question-statistics/test-data/rubricQuestionResponses.json @@ -58,7 +58,7 @@ } ], "expectedStatsMap": { - "Alice": { + "alice@gmail.com": { "answers": [ [1, 1], [1, 1], [2, 0] ], @@ -76,7 +76,7 @@ "overallWeightedSum": 2.8, "overallWeightAverage": 0.47 }, - "Bob": { + "bob@gmail.com": { "answers": [ [2, 0], [1, 1], [2, 0] ],