'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: {
a3080c33 6 evaluationArray: evaluationArray,
43828378
BA
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 {
a3080c33
BA
32 Object.keys(this.grades[s.number]).forEach( evaluationName => {
33 s[evaluationName] = this.grades[s.number][evaluationName];
34 if (_.isNumeric(s[evaluationName]) && !isNaN(s[evaluationName]))
43828378 35 {
a3080c33 36 finalGrade += s[evaluationName];
43828378
BA
37 gradesCount++;
38 }
39 if (gradesCount >= 1)
40 finalGrade /= gradesCount;
a3080c33 41 s["final"] = finalGrade; //TODO: forbid "final" as evaluation name
43828378
BA
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 },
a3080c33
BA
68 grade: function(evaluationIndex, studentNumber) {
69 if (!this.grades[evaluationIndex] || !this.grades[evaluationIndex][studentNumber])
43828378 70 return ""; //no grade yet
a3080c33 71 return this.grades[evaluationIndex][studentNumber];
43828378
BA
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});