[+] Create method to check course gradings

This commit is contained in:
Hykilpikonna
2019-10-01 18:29:50 -04:00
parent b5b9f14a49
commit feabc336c1
+62
View File
@@ -7,6 +7,7 @@ import JsonUtils from '@/utils/json-utils';
import pWaitFor from 'p-wait-for';
import {HttpUtils} from '@/utils/http-utils';
import {CourseUtils} from '@/utils/course-utils';
import {GPAUtils} from '@/utils/gpa-utils';
/**
* Objects of this interface represent assignment grades.
@@ -184,6 +185,67 @@ export default class App extends Vue
return true;
}
/**
* Check the courses' grading algorithms. (Total-average or percent-type)
*/
private checkGradingAlgorithms()
{
// Loop through all the courses
for (const course of this.filteredCourses)
{
// Check if total-average grade is the same with percent-type grade
if (course.numericGrade == GPAUtils.getTotalMeanAverage(course))
{
course.grading.method = 'TOTAL_AVERAGE';
}
else
{
// Request grading scheme for this course
this.http.post('/grading', {assignments_id: course.assignmentsId}).then(response =>
{
// Check success
if (response.success)
{
// Add it to course
course.grading = response.data;
}
else
{
// Show error message TODO: Show it properly
alert(response.data)
}
})
.catch(alert)
}
}
// Wait for done
pWaitFor(() => this.isGradingReady()).then(() =>
{
// When the assignments are ready
// TODO: Display loading
this.assignmentsReady = true;
})
}
/**
* Are grading algorithms ready or not.
*
* @returns boolean Ready or not
*/
private isGradingReady(): boolean
{
for (const course of this.filteredCourses)
{
if (course.grading.method == undefined)
{
return false;
}
}
return true;
}
/**
* This is called when a navigation tab is clicked
*