From c0cde8a08ae8895b9e4f0f07729262a8bf16a7a2 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 22 Apr 2022 02:33:26 +0000 Subject: [PATCH] Implemented Test.getAverageScore and Percentage --- lib/Test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/Test.js b/lib/Test.js index b7236ca..92f57b5 100644 --- a/lib/Test.js +++ b/lib/Test.js @@ -151,6 +151,19 @@ class Test { })); } + async getAverageScore() { + const trs = await this.getTestResults(); + + return trs.reduce((a, b) => a + b.mark, 0) / + (trs.length || 1); + } + + async getAveragePercentage() { + return await this.getAverageScore() / + this.template.maxMark * + 100; + } + async addResult(accountId, studentId, mark) { const tr = await TestResult.create( this.#conn,