Skip to content

Commit

Permalink
[#12894] Calculate msq totals by student email instead of name (#13141)
Browse files Browse the repository at this point in the history
* Calculate totals by email

* Standardize mcq and msq

* Undo sortBy

* Refactor initialization of variables

---------

Co-authored-by: domoberzin <[email protected]>
  • Loading branch information
itstrueitstrueitsrealitsreal and domoberzin authored Jul 10, 2024
1 parent 399a5fa commit c5af284
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class MsqQuestionStatisticsComponent extends MsqQuestionStatisticsCalcula
{ header: 'Recipient Name', sortBy: SortBy.MSQ_RECIPIENT_NAME },
...Object.keys(this.weightPerOption).map((key: string) => {
return {
header: `${key} [${this.weightPerOption[key]}]`,
header: `${key} [${(this.weightPerOption[key]).toFixed(2)}]`,
sortBy: SortBy.MSQ_OPTION_SELECTED_TIMES,
};
}),
Expand All @@ -83,8 +83,8 @@ export class MsqQuestionStatisticsComponent extends MsqQuestionStatisticsCalcula
value: this.perRecipientResponses[key].responses[option],
};
}),
{ value: this.perRecipientResponses[key].total },
{ value: this.perRecipientResponses[key].average },
{ value: (this.perRecipientResponses[key].total).toFixed(2) },
{ value: (this.perRecipientResponses[key].average).toFixed(2) },
];
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,29 @@ export class MsqQuestionStatisticsCalculation
const perRecipientResponse: Record<string, Record<string, number>> = {};
const recipientToTeam: Record<string, string> = {};
const recipientEmails: Record<string, string> = {};
const recipientNames: Record<string, string> = {};
for (const response of this.responses) {
perRecipientResponse[response.recipient] = perRecipientResponse[response.recipient] || {};
recipientEmails[response.recipient] = recipientEmails[response.recipient] || response.recipientEmail || '';
const responseEmail = response.recipientEmail;
if (!responseEmail) {
continue;
}
perRecipientResponse[responseEmail] = perRecipientResponse[responseEmail] || {};
recipientEmails[responseEmail] = recipientEmails[responseEmail] || responseEmail || '';
recipientNames[responseEmail] = recipientNames[responseEmail] || response.recipient || '';
for (const choice of this.question.msqChoices) {
perRecipientResponse[response.recipient][choice] = 0;
perRecipientResponse[responseEmail][choice] = 0;
}
if (this.question.otherEnabled) {
perRecipientResponse[response.recipient]['Other'] = 0;
perRecipientResponse[responseEmail]['Other'] = 0;
}
recipientToTeam[response.recipient] = response.recipientTeam;
recipientToTeam[responseEmail] = response.recipientTeam;
}
for (const response of this.responses) {
this.updateResponseCountPerOptionForResponse(response.responseDetails, perRecipientResponse[response.recipient]);
const email = response.recipientEmail;
if (!email) {
continue;
}
this.updateResponseCountPerOptionForResponse(response.responseDetails, perRecipientResponse[email]);
}

for (const recipient of Object.keys(perRecipientResponse)) {
Expand All @@ -120,7 +130,7 @@ export class MsqQuestionStatisticsCalculation
average = numOfResponsesForRecipient ? total / numOfResponsesForRecipient : 0;

this.perRecipientResponses[recipient] = {
recipient,
recipient: recipientNames[recipient],
recipientEmail: recipientEmails[recipient],
total: +total.toFixed(5),
average: +average.toFixed(2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
}
],
"expectedPerRecipientResponses": {
"Alice": {
"[email protected]": {
"average": 1.5,
"recipient": "Alice",
"recipientEmail": "[email protected]",
Expand All @@ -112,7 +112,7 @@
},
"total": 3
},
"Bob": {
"[email protected]": {
"average": 1,
"recipient": "Bob",
"recipientEmail": "[email protected]",
Expand All @@ -124,7 +124,7 @@
},
"total": 1
},
"Charles": {
"[email protected]": {
"average": 0,
"recipient": "Charles",
"recipientEmail": "[email protected]",
Expand All @@ -138,7 +138,7 @@
}
},
"expectedPerRecipientResponsesWithOther": {
"Alice": {
"[email protected]": {
"average": 2,
"recipient": "Alice",
"recipientEmail": "[email protected]",
Expand All @@ -151,7 +151,7 @@
},
"total": 6
},
"Bob": {
"[email protected]": {
"average": 2.5,
"recipient": "Bob",
"recipientEmail": "[email protected]",
Expand All @@ -164,7 +164,7 @@
},
"total": 5
},
"Charles": {
"[email protected]": {
"average": 0,
"recipient": "Charles",
"recipientEmail": "[email protected]",
Expand Down

0 comments on commit c5af284

Please sign in to comment.