diff options
author | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-01-10 14:54:04 +0100 |
commit | 99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch) | |
tree | e663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /school/node_modules/pronote-api/src/fetch/marks.js | |
parent | 9871b03912fc28ad38b4037ebf26a78aa937baba (diff) | |
download | pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2 pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip |
Update - This is an automated commit
Diffstat (limited to 'school/node_modules/pronote-api/src/fetch/marks.js')
-rw-r--r-- | school/node_modules/pronote-api/src/fetch/marks.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/school/node_modules/pronote-api/src/fetch/marks.js b/school/node_modules/pronote-api/src/fetch/marks.js new file mode 100644 index 0000000..1e57e85 --- /dev/null +++ b/school/node_modules/pronote-api/src/fetch/marks.js @@ -0,0 +1,73 @@ +const { getPeriodBy } = require('../data/periods'); +const { withId, checkDuplicates } = require('../data/id'); + +const getMarks = require('./pronote/marks'); + +async function marks(session, user, period = null, type = null) +{ + const marks = await getMarks(session, user, getPeriodBy(session, period, type)); + if (!marks) { + return null; + } + + const result = { + subjects: [], + averages: {} + }; + + if (marks.studentAverage) { + result.averages.student = Number((marks.studentAverage / marks.studentAverageScale * 20).toFixed(2)); + } + if (marks.studentClassAverage) { + result.averages.studentClass = Number(marks.studentClassAverage.toFixed(2)); + } + + for (const subject of marks.subjects.sort((a, b) => a.order - b.order)) { + result.subjects.push({ + name: subject.name, + averages: { + student: subject.studentAverage / subject.studentAverageScale * 20, + studentClass: subject.studentClassAverage, + max: subject.maxAverage, + min: subject.minAverage + }, + color: subject.color, + marks: [] + }); + } + + for (const mark of marks.marks) { + const subject = result.subjects.find(s => s.name === mark.subject.name); + if (!subject) { + continue; + } + + const res = { + isAway: mark.value < 0 + }; + + if (!res.isAway) { + res.value = mark.value; + } + + if (mark.average >= 0) { + res.min = mark.min; + res.max = mark.max; + res.average = mark.average; + } + + subject.marks.push(withId({ + title: mark.title, + ...res, + scale: mark.scale, + coefficient: mark.coefficient, + date: mark.date + }, ['title', 'date'], subject.name)); + } + + result.subjects.forEach(s => checkDuplicates(s.marks)); + + return result; +} + +module.exports = marks; |