Skip to content

Commit

Permalink
feat(grades): add subjectFile and correctionFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Feb 22, 2024
1 parent 1b030b7 commit 31c05b9
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 43 deletions.
5 changes: 5 additions & 0 deletions src/api/user/grades/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ export interface PronoteApiUserGrades {
estBonus: boolean
estRamenerSur20: boolean

/** Name of the correction file. */
libelleCorrige?: string
/** Name of the subject file. */
libelleSujet?: string

/** Available when the grade was based on a quiz. */
executionQCM?: {
_T: 24
Expand Down
2 changes: 1 addition & 1 deletion src/client/Pronote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export default class Pronote {

return {
grades: data.listeDevoirs.V
.map((grade) => new StudentGrade(this, period, grade)),
.map((grade) => new StudentGrade(this, grade)),
averages: data.listeServices.V
.map((average) => new StudentAverage(average)),

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ export { StudentGrade } from "~/parser/grade";
export { Period, OngletPeriod } from "~/parser/period";
export { StudentNews, StudentNewsCategory, StudentNewsItem, StudentNewsItemQuestion } from "~/parser/news";
export { StudentAbsence, StudentDelay, StudentPunishment } from "~/parser/attendance";
export { StudentDiscussionsOverview, StudentDiscussion, StudentDiscussionFolder} from "~/parser/discussion";
export { StudentDiscussionsOverview, StudentDiscussion, StudentDiscussionFolder } from "~/parser/discussion";
162 changes: 121 additions & 41 deletions src/parser/grade.ts
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;
}
}

0 comments on commit 31c05b9

Please sign in to comment.