-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grades): add
subjectFile
and correctionFile
- Loading branch information
Showing
4 changed files
with
128 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,140 @@ | ||
import { PronoteApiUserGrades } from "~/api/user/grades/types"; | ||
import { Pronote } from ".."; | ||
import { Period } from "./period"; | ||
import { StudentSubject } from "./subject"; | ||
import { PronoteApiGradeType, readPronoteApiGrade } from "~/pronote/grades"; | ||
import type { PronoteApiUserGrades } from "~/api/user/grades/types"; | ||
import type Pronote from "~/client/Pronote"; | ||
import { StudentSubject } from "~/parser/subject"; | ||
import { type PronoteApiGradeType, readPronoteApiGrade } from "~/pronote/grades"; | ||
import { readPronoteApiDate } from "~/pronote/dates"; | ||
import { StudentAttachment } from "./attachment"; | ||
import { PronoteApiAttachmentType } from ".."; | ||
|
||
/** Represents a grade. */ | ||
export class StudentGrade { | ||
readonly #id: string; | ||
readonly #value: number | PronoteApiGradeType; | ||
readonly #outOf: number | PronoteApiGradeType; | ||
readonly #defaultOutOf?: number | PronoteApiGradeType; | ||
readonly #date: Date; | ||
readonly #subject: StudentSubject; | ||
readonly #average: number | PronoteApiGradeType; | ||
readonly #max: number | PronoteApiGradeType; | ||
readonly #min: number | PronoteApiGradeType; | ||
readonly #coefficient: number; | ||
readonly #comment: string; | ||
readonly #isBonus: boolean; | ||
readonly #isOptional: boolean; | ||
readonly #isOutOf20: boolean; | ||
|
||
readonly #subjectFile?: StudentAttachment; | ||
readonly #correctionFile?: StudentAttachment; | ||
|
||
constructor (client: Pronote, grade: PronoteApiUserGrades["response"]["donnees"]["listeDevoirs"]["V"][number]) { | ||
this.#id = grade.N; | ||
this.#value = readPronoteApiGrade(grade.note.V); | ||
this.#outOf = readPronoteApiGrade(grade.bareme.V); | ||
this.#defaultOutOf = readPronoteApiGrade(grade.baremeParDefaut.V); | ||
this.#date = readPronoteApiDate(grade.date.V); | ||
this.#subject = new StudentSubject(grade.service.V); | ||
this.#average = readPronoteApiGrade(grade.moyenne.V); | ||
this.#max = readPronoteApiGrade(grade.noteMax.V); | ||
this.#min = readPronoteApiGrade(grade.noteMin.V); | ||
this.#coefficient = grade.coefficient; | ||
this.#comment = grade.commentaire; | ||
this.#isBonus = grade.estBonus; | ||
this.#isOptional = grade.estFacultatif && !this.isBonus; | ||
this.#isOutOf20 = grade.estRamenerSur20; | ||
|
||
if (grade.libelleCorrige) { | ||
this.#correctionFile = new StudentAttachment(client, { | ||
G: PronoteApiAttachmentType.File, | ||
L: grade.libelleCorrige, | ||
N: this.#id | ||
}); | ||
} | ||
|
||
if (grade.libelleSujet) { | ||
this.#subjectFile = new StudentAttachment(client, { | ||
G: PronoteApiAttachmentType.File, | ||
L: grade.libelleSujet, | ||
N: this.#id | ||
}); | ||
} | ||
} | ||
|
||
/** the id of the grade (used internally) */ | ||
public id: string; | ||
get id (): string { | ||
return this.#id; | ||
} | ||
|
||
/** the actual grade */ | ||
public value: number | PronoteApiGradeType; | ||
get value (): number | PronoteApiGradeType { | ||
return this.#value; | ||
} | ||
|
||
/** the maximum amount of points */ | ||
public outOf: number | PronoteApiGradeType; | ||
get outOf (): number | PronoteApiGradeType { | ||
return this.#outOf; | ||
} | ||
|
||
/** the default maximum amount of points */ | ||
public defaultOutOf?: number | PronoteApiGradeType; | ||
get defaultOutOf (): number | PronoteApiGradeType | undefined { | ||
return this.#defaultOutOf; | ||
} | ||
|
||
/** the date on which the grade was given */ | ||
public date: Date; | ||
get date (): Date { | ||
return this.#date; | ||
} | ||
|
||
/** the subject in which the grade was given */ | ||
public subject: StudentSubject; | ||
get subject (): StudentSubject { | ||
return this.#subject; | ||
} | ||
|
||
/** the average of the class */ | ||
public average: number | PronoteApiGradeType; | ||
get average (): number | PronoteApiGradeType { | ||
return this.#average; | ||
} | ||
|
||
/** the highest grade */ | ||
public max: number | PronoteApiGradeType; | ||
get max (): number | PronoteApiGradeType { | ||
return this.#max; | ||
} | ||
|
||
/** the lowest grade */ | ||
public min: number | PronoteApiGradeType; | ||
get min (): number | PronoteApiGradeType { | ||
return this.#min; | ||
} | ||
|
||
/** the coefficient of the grade */ | ||
public coefficient: number; | ||
get coefficient (): number { | ||
return this.#coefficient; | ||
} | ||
|
||
/** comment on the grade description */ | ||
public comment: string; | ||
get comment (): string { | ||
return this.#comment; | ||
} | ||
|
||
/** is the grade bonus : only points above 10 count */ | ||
public isBonus: boolean; | ||
get isBonus (): boolean { | ||
return this.#isBonus; | ||
} | ||
|
||
/** is the grade optional : the grade only counts if it increases the average */ | ||
public isOptional: boolean; | ||
get isOptional (): boolean { | ||
return this.#isOptional; | ||
} | ||
|
||
/** is the grade out of 20. Example 8/10 -> 16/20 */ | ||
public isOutOf20: boolean; | ||
|
||
constructor ( | ||
public client: Pronote, | ||
/** the period in which the grade was given */ | ||
public period: Period, | ||
grade: PronoteApiUserGrades["response"]["donnees"]["listeDevoirs"]["V"][number] | ||
) { | ||
this.id = grade.N; | ||
this.value = readPronoteApiGrade(grade.note.V); | ||
this.outOf = readPronoteApiGrade(grade.bareme.V); | ||
this.defaultOutOf = readPronoteApiGrade(grade.baremeParDefaut.V); | ||
this.date = readPronoteApiDate(grade.date.V); | ||
this.subject = new StudentSubject(grade.service.V); | ||
this.average = readPronoteApiGrade(grade.moyenne.V); | ||
this.max = readPronoteApiGrade(grade.noteMax.V); | ||
this.min = readPronoteApiGrade(grade.noteMin.V); | ||
this.coefficient = grade.coefficient; | ||
this.comment = grade.commentaire; | ||
this.isBonus = grade.estBonus; | ||
this.isOptional = grade.estFacultatif && !this.isBonus; | ||
this.isOutOf20 = grade.estRamenerSur20; | ||
get isOutOf20 (): boolean { | ||
return this.#isOutOf20; | ||
} | ||
|
||
/** the file of the subject */ | ||
get subjectFile (): StudentAttachment | undefined { | ||
return this.#subjectFile; | ||
} | ||
|
||
/** the file of the correction */ | ||
get correctionFile (): StudentAttachment | undefined { | ||
return this.#correctionFile; | ||
} | ||
} |