From 2567fcadbd7282926ab7f04be75648cac2df0706 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Tue, 1 Oct 2019 18:41:42 -0400 Subject: [PATCH] [+] Encapsulate method to calculate total-mean average --- src/utils/gpa-utils.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/utils/gpa-utils.ts b/src/utils/gpa-utils.ts index 1949ca7..993845f 100644 --- a/src/utils/gpa-utils.ts +++ b/src/utils/gpa-utils.ts @@ -102,4 +102,29 @@ export class GPAUtils return -1; } + + /** + * Calculate the total-mean (total/max) average + * + * @param course Course + */ + public static getTotalMeanAverage(course: Course) + { + let score = 0; + let max = 0; + + // Loop through assignments + course.assignments.forEach(assignment => + { + // If assignment should be displayed + if (assignment.complete != 'Complete') return; + + // Record scores + score += assignment.score; + max += assignment.scoreMax; + }); + + // Return + return score / max * 100; + } }