feat : fix a lot of stuff
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
type Note = { numEtud: number; idModule: string; note: number };
|
||||
type Note = {
|
||||
numEtud: number;
|
||||
idModule: string;
|
||||
note: number;
|
||||
noteSession2: number | null;
|
||||
};
|
||||
type UE = { id: number; nom: string };
|
||||
type UEModule = {
|
||||
idModule: string;
|
||||
@@ -9,7 +14,12 @@ type UEModule = {
|
||||
coeff: number;
|
||||
};
|
||||
type Module = { id: string; nom: string };
|
||||
type Ajustement = { numEtud: number; idUE: number; valeur: number };
|
||||
type Ajustement = {
|
||||
numEtud: number;
|
||||
idUE: number;
|
||||
valeur: number;
|
||||
malus: number;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
numEtud: number | null;
|
||||
@@ -26,6 +36,11 @@ function avgClass(avg: number | null): string {
|
||||
return avg >= 10 ? "avg-good" : "avg-warn";
|
||||
}
|
||||
|
||||
/** Returns the effective note (session 2 if exists, otherwise session 1). */
|
||||
function effectiveNote(n: Note): number {
|
||||
return n.noteSession2 ?? n.note;
|
||||
}
|
||||
|
||||
export default function NotesView({ numEtud, prenom }: Props) {
|
||||
const [notes, setNotes] = useState<Note[]>([]);
|
||||
const [ues, setUes] = useState<UE[]>([]);
|
||||
@@ -47,8 +62,8 @@ export default function NotesView({ numEtud, prenom }: Props) {
|
||||
try {
|
||||
const [notesRes, uesRes, ueModRes, modRes, ajRes] = await Promise.all([
|
||||
fetch(`/notes/api/notes?numEtud=${numEtud}`),
|
||||
fetch("/notes/api/ues"),
|
||||
fetch("/notes/api/ue-modules"),
|
||||
fetch("/admin/api/ues"),
|
||||
fetch("/admin/api/ue-modules"),
|
||||
fetch("/admin/api/modules"),
|
||||
fetch(`/notes/api/ajustements?numEtud=${numEtud}`),
|
||||
]);
|
||||
@@ -72,7 +87,6 @@ export default function NotesView({ numEtud, prenom }: Props) {
|
||||
setModules(modData);
|
||||
setAjustements(ajData);
|
||||
|
||||
// Derive promos from UE-modules for this student's notes
|
||||
const noteModuleIds = new Set(notesData.map((n: Note) => n.idModule));
|
||||
const relevantPromos = [
|
||||
...new Set(
|
||||
@@ -99,7 +113,7 @@ export default function NotesView({ numEtud, prenom }: Props) {
|
||||
<div class="page-content">
|
||||
<p class="state-empty">
|
||||
Bonjour {prenom}{" "}
|
||||
— aucun dossier étudiant n'est associé à votre compte.
|
||||
— aucun dossier etudiant n'est associe a votre compte.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
@@ -108,7 +122,7 @@ export default function NotesView({ numEtud, prenom }: Props) {
|
||||
if (loading) {
|
||||
return (
|
||||
<div class="page-content">
|
||||
<p class="state-loading">Chargement…</p>
|
||||
<p class="state-loading">Chargement...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -121,20 +135,18 @@ export default function NotesView({ numEtud, prenom }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
// Filter UE-modules by active promo
|
||||
const filteredUeModules = activePromo
|
||||
? ueModules.filter((um) => um.idPromo === activePromo)
|
||||
: ueModules;
|
||||
|
||||
// Group UE-modules by UE
|
||||
const ueIds = [...new Set(filteredUeModules.map((um) => um.idUE))];
|
||||
|
||||
const moduleMap = Object.fromEntries(modules.map((m) => [m.id, m]));
|
||||
const noteMap = Object.fromEntries(
|
||||
notes.map((n) => [n.idModule, n.note]),
|
||||
notes.map((n) => [n.idModule, n]),
|
||||
);
|
||||
const ajMap = Object.fromEntries(
|
||||
ajustements.map((a) => [a.idUE, a.valeur]),
|
||||
ajustements.map((a) => [a.idUE, a]),
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -155,7 +167,7 @@ export default function NotesView({ numEtud, prenom }: Props) {
|
||||
)}
|
||||
|
||||
{ueIds.length === 0 && (
|
||||
<p class="state-empty">Aucune note disponible pour cette période.</p>
|
||||
<p class="state-empty">Aucune note disponible pour cette periode.</p>
|
||||
)}
|
||||
|
||||
{ueIds.map((ueId) => {
|
||||
@@ -166,51 +178,65 @@ export default function NotesView({ numEtud, prenom }: Props) {
|
||||
let weightedSum = 0;
|
||||
let coveredCoeff = 0;
|
||||
ueModsForUE.forEach((um) => {
|
||||
const note = noteMap[um.idModule];
|
||||
if (note !== undefined) {
|
||||
weightedSum += note * um.coeff;
|
||||
const noteObj = noteMap[um.idModule];
|
||||
if (noteObj) {
|
||||
const val = effectiveNote(noteObj);
|
||||
weightedSum += val * um.coeff;
|
||||
coveredCoeff += um.coeff;
|
||||
}
|
||||
});
|
||||
|
||||
const avg = coveredCoeff > 0 ? weightedSum / coveredCoeff : null;
|
||||
const ajustement = ajMap[ueId] ?? null;
|
||||
const finalAvg = avg !== null && ajustement !== null
|
||||
? avg + ajustement
|
||||
: avg;
|
||||
const ajust = ajMap[ueId] ?? null;
|
||||
|
||||
// If ajust.valeur exists, it replaces the calculated average
|
||||
// Then malus is subtracted
|
||||
let finalAvg: number | null = avg;
|
||||
if (ajust) {
|
||||
finalAvg = ajust.valeur;
|
||||
if (ajust.malus > 0) {
|
||||
finalAvg = (finalAvg ?? 0) - ajust.malus;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={ueId} class="ue-card">
|
||||
<div class="ue-card-header">
|
||||
<p class="ue-card-title">UE : {ue.nom}</p>
|
||||
{finalAvg !== null && (
|
||||
<p class={`ue-card-avg ${avgClass(finalAvg)}`}>
|
||||
Moyenne : {finalAvg.toFixed(2)}/20
|
||||
{ajustement !== null && ajustement !== 0 && (
|
||||
<span>
|
||||
{" "}
|
||||
(ajustement : {ajustement > 0 ? "+" : ""}
|
||||
{ajustement})
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{finalAvg === null && (
|
||||
<p class="ue-card-avg avg-warn">Notes non disponibles</p>
|
||||
)}
|
||||
{finalAvg !== null
|
||||
? (
|
||||
<p class={`ue-card-avg ${avgClass(finalAvg)}`}>
|
||||
Moyenne : {finalAvg.toFixed(2)}/20
|
||||
{ajust && ajust.malus > 0 && (
|
||||
<span>(malus : -{ajust.malus})</span>
|
||||
)}
|
||||
</p>
|
||||
)
|
||||
: <p class="ue-card-avg avg-warn">Notes non disponibles</p>}
|
||||
</div>
|
||||
|
||||
{ueModsForUE.map((um) => {
|
||||
const mod = moduleMap[um.idModule];
|
||||
const note = noteMap[um.idModule] ?? null;
|
||||
const noteObj = noteMap[um.idModule] ?? null;
|
||||
const effective = noteObj ? effectiveNote(noteObj) : null;
|
||||
const hasS2 = noteObj?.noteSession2 != null;
|
||||
|
||||
return (
|
||||
<div key={um.idModule} class="ue-module-row">
|
||||
<span class="ue-module-name">
|
||||
{mod ? mod.id : um.idModule} —{" "}
|
||||
{mod ? mod.nom : "Module inconnu"} (coef {um.coeff})
|
||||
</span>
|
||||
<span class={`score-chip ${scoreClass(note)}`}>
|
||||
{note !== null ? `${note}/20` : "—"}
|
||||
<span class={`score-chip ${scoreClass(effective)}`}>
|
||||
{effective !== null ? `${effective}/20` : "—"}
|
||||
{hasS2 && (
|
||||
<span
|
||||
style="font-size: 0.7rem; opacity: 0.7; margin-left: 0.35rem"
|
||||
title={`Session 1 : ${noteObj!.note}/20`}
|
||||
>
|
||||
(S1: {noteObj!.note})
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user