test : changed test format + added playwright support
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
import {
|
||||
applyAjustement,
|
||||
calculateWeightedAverage,
|
||||
getEffectiveNote,
|
||||
} from "$root/logic/grades.ts";
|
||||
|
||||
type Student = {
|
||||
// ...
|
||||
numEtud: number;
|
||||
nom: string;
|
||||
prenom: string;
|
||||
@@ -37,11 +43,6 @@ function noteClass(n: number): string {
|
||||
return n >= 10 ? "note-chip note-chip--ok" : "note-chip note-chip--fail";
|
||||
}
|
||||
|
||||
/** Returns the effective note (session 2 if exists, otherwise session 1). */
|
||||
function effectiveNote(n: Note): number {
|
||||
return n.noteSession2 ?? n.note;
|
||||
}
|
||||
|
||||
export default function NoteRecap({ numEtud }: Props) {
|
||||
const [student, setStudent] = useState<Student | null>(null);
|
||||
const [ueList, setUeList] = useState<UE[]>([]);
|
||||
@@ -108,19 +109,6 @@ export default function NoteRecap({ numEtud }: Props) {
|
||||
load();
|
||||
}, [numEtud]);
|
||||
|
||||
function calcAvg(ueMods: UEModule[]): number | null {
|
||||
let total = 0,
|
||||
coeff = 0;
|
||||
for (const um of ueMods) {
|
||||
const n = noteMap.get(um.idModule);
|
||||
if (n === undefined) return null;
|
||||
const val = effectiveNote(n);
|
||||
total += val * um.coeff;
|
||||
coeff += um.coeff;
|
||||
}
|
||||
return coeff > 0 ? total / coeff : null;
|
||||
}
|
||||
|
||||
async function saveNote(
|
||||
idModule: string,
|
||||
field: "note" | "noteSession2",
|
||||
@@ -280,18 +268,11 @@ export default function NoteRecap({ numEtud }: Props) {
|
||||
</p>
|
||||
)
|
||||
: ueList.map((ue) => {
|
||||
const ueMods = ueModules.filter((um) => um.idUE === ue.id);
|
||||
const avg = calcAvg(ueMods);
|
||||
const ajust = ajustements.find((a) => a.idUE === ue.id);
|
||||
|
||||
// Final displayed average: if ajust.valeur exists it replaces avg, then subtract malus
|
||||
let finalAvg = avg;
|
||||
if (ajust) {
|
||||
finalAvg = ajust.valeur;
|
||||
if (ajust.malus > 0) {
|
||||
finalAvg = (finalAvg ?? 0) - ajust.malus;
|
||||
}
|
||||
}
|
||||
const ueMods = ueList.length > 0 ? ueModules.filter((um) => um.idUE === ue.id) : [];
|
||||
const notesRecord = Object.fromEntries(noteMap);
|
||||
const avg = calculateWeightedAverage(ueMods, notesRecord);
|
||||
const ajust = ajustements.find((a) => a.idUE === ue.id) ?? null;
|
||||
const finalAvg = applyAjustement(avg, ajust);
|
||||
|
||||
return (
|
||||
<div key={ue.id} class="edit-section">
|
||||
@@ -341,7 +322,7 @@ export default function NoteRecap({ numEtud }: Props) {
|
||||
const noteVal = noteObj?.note;
|
||||
const noteS2 = noteObj?.noteSession2;
|
||||
const effective = noteObj
|
||||
? effectiveNote(noteObj)
|
||||
? getEffectiveNote(noteObj)
|
||||
: undefined;
|
||||
const nomMod = moduleMap.get(um.idModule) ?? um.idModule;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user