[+] Calculate type score and weight

This commit is contained in:
Hykilpikonna
2019-11-09 20:33:32 -05:00
parent 0525aae98a
commit cb22baf120
+18 -2
View File
@@ -229,14 +229,30 @@ export default class Course
get assignmentTypes(): AssignmentType[]
{
// Get all types
let types = this.assignments.map(a => {return {name: a.type, id: a.typeId}});
let types = this.assignments.map(a => a.type);
// Remove duplicates
types = types.filter((type, i, a) => a.indexOf(type) == i);
// Get total possible score for weight calculation
let totalScoreMax = this.assignments.reduce((sum, a) => sum + a.scoreMax, 0);
// For every type...
return types.map(type =>
{
return {...type, weight: 0, scoreMax: 0, score: 0}
// Get assignments of the type
let typeAssignments = this.assignments.filter(a => a.type == type);
// Count scores and max scores
let score = typeAssignments.reduce((sum, a) => sum + a.score, 0);
let scoreMax = typeAssignments.reduce((sum, a) => sum + a.scoreMax, 0);
// Calculate weight
let weight = this.grading.method == 'PERCENT_TYPE'
? this.grading.weightingMap[type] : scoreMax / totalScoreMax;
// Return
return {name: type, id: typeAssignments[0].typeId, weight: weight, scoreMax: scoreMax, score: score}
})
}
}