[F] Correct course average grade graph calculation
This commit is contained in:
@@ -83,17 +83,6 @@ export default class GraphOverall extends Vue
|
|||||||
dates.push(new Date(date));
|
dates.push(new Date(date));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize course specific variables
|
|
||||||
let courseScores: {[index: string]: any} = {};
|
|
||||||
let courseMaxScores: {[index: string]: any} = {};
|
|
||||||
let courseIndexes: {[index: string]: any} = {};
|
|
||||||
courses.forEach(course =>
|
|
||||||
{
|
|
||||||
courseScores[course.name] = 0;
|
|
||||||
courseMaxScores[course.name] = 0;
|
|
||||||
courseIndexes[course.name] = course.assignments.length - 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Compute the rows data
|
// Compute the rows data
|
||||||
let rows: {[index: string]: any}[] = [];
|
let rows: {[index: string]: any}[] = [];
|
||||||
dates.forEach(date =>
|
dates.forEach(date =>
|
||||||
@@ -104,33 +93,67 @@ export default class GraphOverall extends Vue
|
|||||||
// Loop through courses
|
// Loop through courses
|
||||||
courses.forEach(course =>
|
courses.forEach(course =>
|
||||||
{
|
{
|
||||||
// Reversed loop through the assignments
|
// Total Mean
|
||||||
for (let r = courseIndexes[course.name]; r >= 0; r--)
|
if (course.grading.method == 'TOTAL_MEAN')
|
||||||
{
|
{
|
||||||
let assignment = course.assignments[r];
|
let score = 0;
|
||||||
|
let max = 0;
|
||||||
|
|
||||||
// If assignment should be displayed
|
// Loop through assignments
|
||||||
if (assignment.complete != 'Complete') continue;
|
course.assignments.forEach(assignment =>
|
||||||
|
|
||||||
// Date is being looked at
|
|
||||||
let assignmentDate = new Date(assignment.date);
|
|
||||||
if (assignmentDate.getTime() == date.getTime())
|
|
||||||
{
|
{
|
||||||
// Record scores
|
// If assignment should be displayed
|
||||||
courseScores[course.name] += assignment.score;
|
if (assignment.complete != 'Complete') return;
|
||||||
courseMaxScores[course.name] += assignment.scoreMax;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not now
|
// Date is being looked at
|
||||||
else if (assignmentDate > date)
|
let assignmentDate = new Date(assignment.date);
|
||||||
{
|
if (assignmentDate.getTime() < date.getTime())
|
||||||
courseIndexes[course.name] = r;
|
{
|
||||||
break;
|
// Record scores
|
||||||
}
|
score += assignment.score;
|
||||||
|
max += assignment.scoreMax;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add average to the row
|
||||||
|
row[course.name] = score / max * 100;
|
||||||
}
|
}
|
||||||
|
else if (course.grading.method == 'PERCENT_TYPE')
|
||||||
|
{
|
||||||
|
let typeScores: {[index: string]: any} = {};
|
||||||
|
let typeCounts: {[index: string]: any} = {};
|
||||||
|
|
||||||
// Add average to the row
|
// Loop through assignments
|
||||||
row[course.name] = courseScores[course.name] / courseMaxScores[course.name] * 100;
|
course.assignments.forEach(assignment =>
|
||||||
|
{
|
||||||
|
// If assignment should be displayed
|
||||||
|
if (assignment.complete != 'Complete') return;
|
||||||
|
|
||||||
|
// Date is being looked at
|
||||||
|
let assignmentDate = new Date(assignment.date);
|
||||||
|
if (assignmentDate.getTime() < date.getTime())
|
||||||
|
{
|
||||||
|
// Record scores
|
||||||
|
if (typeScores[assignment.type] == undefined) typeScores[assignment.type] = 0;
|
||||||
|
typeScores[assignment.type] += assignment.score / assignment.scoreMax;
|
||||||
|
|
||||||
|
if (typeCounts[assignment.type] == undefined) typeCounts[assignment.type] = 0;
|
||||||
|
typeCounts[assignment.type] ++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let score = 0;
|
||||||
|
|
||||||
|
// Count
|
||||||
|
for (let type in typeScores)
|
||||||
|
{
|
||||||
|
score += typeScores[type] * course.grading.weightingMap[type] / typeCounts[type];
|
||||||
|
console.log(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add average to the row
|
||||||
|
row[course.name] = score * 100;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add it to the array
|
// Add it to the array
|
||||||
|
|||||||
Reference in New Issue
Block a user