'update'
[qomet.git] / public / javascripts / grade.js
CommitLineData
43828378
BA
1//TODO: compute grades after exam (in teacher's view)
2
3new Vue({
4 el: '#grade',
5 data: {
6 assessmentArray: assessmentArray,
7 settings: {
8 totalPoints: 20,
9 halfPoints: false,
10 zeroSum: false,
11 },
12 group: 1, //for detailed grades tables
13 grades: { }, //computed
14 },
15 mounted: function() {
16 // TODO
17 },
18 methods: {
19 // GRADES:
20 gradeSettings: function() {
21 $("#gradeSettings").modal("open");
22 Materialize.updateTextFields(); //total points field in grade settings overlap
23 },
24 download: function() {
25 // Download (all) grades as a CSV file
26 let data = [ ];
27 this.studentList(0).forEach( s => {
28 let finalGrade = 0.;
29 let gradesCount = 0;
30 if (!!this.grades[s.number])
31 {
32 Object.keys(this.grades[s.number]).forEach( assessmentName => {
33 s[assessmentName] = this.grades[s.number][assessmentName];
34 if (_.isNumeric(s[assessmentName]) && !isNaN(s[assessmentName]))
35 {
36 finalGrade += s[assessmentName];
37 gradesCount++;
38 }
39 if (gradesCount >= 1)
40 finalGrade /= gradesCount;
41 s["final"] = finalGrade; //TODO: forbid "final" as assessment name
42 });
43 }
44 data.push(s); //number,name,group,assessName1...assessNameN,final
45 });
46 let csv = Papa.unparse(data, {
47 quotes: true,
48 header: true,
49 });
50 let downloadAnchor = $("#download");
51 downloadAnchor.attr("download", this.course.code + "_results.csv");
52 downloadAnchor.attr("href", "data:text/plain;charset=utf-8," + encodeURIComponent(csv));
53 this.$refs.download.click()
54 //downloadAnchor.click(); //fails
55 },
56 showDetails: function(group) {
57 this.group = group;
58 $("#detailedGrades").modal("open");
59 },
60 groupList: function() {
61 let maxGrp = 1;
62 this.course.students.forEach( s => {
63 if (s.group > maxGrp)
64 maxGrp = s.group;
65 });
66 return _.range(1,maxGrp+1);
67 },
68 grade: function(assessmentIndex, studentNumber) {
69 if (!this.grades[assessmentIndex] || !this.grades[assessmentIndex][studentNumber])
70 return ""; //no grade yet
71 return this.grades[assessmentIndex][studentNumber];
72 },
73 groupId: function(group, prefix) {
74 return (prefix || "") + "group" + group;
75 },
76 togglePresence: function(number, index) {
77 // UNIMPLEMENTED
78 // TODO: if no grade (thus automatic 0), toggle "exempt" state on student for current exam
79 // --> automatic update of grades view (just a few number to change)
80 },
81 computeGrades: function() {
82 // UNIMPLEMENTED
83 // TODO: compute all grades using settings (points, coefficients, bonus/malus...).
84 // If some questions with free answers (open), display answers and ask teacher action.
85 // TODO: need a setting for that too (by student, by exercice, by question)
86 },
87 },
88});