diff --git a/CLAUDE.md b/CLAUDE.md index b9d9f4e..c9691b8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -25,6 +25,7 @@ Références : Papillon (parcours ED, pièges de l'API ; ne pas reprendre son ar ## Stack Expo SDK 58 (nouvelle architecture), TypeScript, expo-router (routes dans `app/`). Reanimated, Gesture Handler, FlashList. expo-sqlite (SQLCipher), expo-secure-store, expo-local-authentication, expo-notifications (locales), expo-background-task. Zustand au-dessus de la base (source de vérité). Jest (jest-expo) + fast-check. +- Branche de travail : `recipe`. Push sur `recipe` autorisé sans redemander. Publier une version : PR `recipe` → `main`, fusion en squash, puis workflow `release` lancé à la main sur `main` avec la version X.Y.Z (il crée le tag ; pousser un tag depuis le conteneur cloud échoue), puis réaligner `recipe` sur `main`. - Builds natifs : APK local (recette dans `docs/REPRISE.md`) pour les essais ; APK publiés par le workflow `release` (tag `vX.Y.Z`, signés avec la clé de Coef, suivis par Obtainium). Pas d'EAS. - Web (`npx expo start --web`) : aperçu visuel en mode démo seulement (l'API ED refuse le navigateur, CORS). Le web est toujours en démo (`src/demo`). Sur mobile : `EXPO_PUBLIC_DEMO=1`. - Toujours `npx expo install ` pour les modules Expo/RN. Ne jamais créer `ios/` ni `android/` à la main (CNG) : passer par `app.json` et des config plugins. diff --git a/app/(onglets)/notes.tsx b/app/(onglets)/notes.tsx index 5b22222..684b1b8 100644 --- a/app/(onglets)/notes.tsx +++ b/app/(onglets)/notes.tsx @@ -6,15 +6,24 @@ import Animated, { useAnimatedStyle, useReducedMotion, useSharedValue, withTimin import { ErreurED } from '@/api/ecoledirecte/erreurs'; import { MODE_DEMO } from '@/demo'; -import { avecHypotheses, type NoteHypothetique } from '@/domain/moyennes/simulateur'; +import { avecHypotheses, type NoteHypothetique, type Retouche } from '@/domain/moyennes/simulateur'; import type { Note } from '@/domain/types'; import type { Famille } from '@/ui/theme'; import { useEleveActif, useEleves } from '@/features/compte/eleves'; import { familleDe, NOM_FAMILLE, ORDRE_FAMILLES, useCouleurMatiere } from '@/features/notes/familles'; -import { ordonner, TRIS, type Tri, trierNotes } from '@/features/notes/ordre'; +import { ordonner, parRecence, TRIS, type Tri, trierNotes } from '@/features/notes/ordre'; import { cleSimulation, useSimulation } from '@/features/notes/simulation'; import { useNotes } from '@/features/notes/store'; -import { evolution, evolutionsMatieres, groupesPeriodes, type LigneMatiere, periodeParDefaut, periodesAffichees, type VueNotes, vueNotes } from '@/features/notes/vue'; +import { + evolution, + evolutionsMatieres, + groupesPeriodes, + type LigneMatiere, + periodeParDefaut, + periodesAffichees, + type VueNotes, + vueNotes, +} from '@/features/notes/vue'; import { ecrirePreference, lirePreference } from '@/storage/base'; import { libelleMatiere } from '@/sync/annonce'; import { @@ -53,6 +62,8 @@ const PREF_ORDRE_MATIERES = 'notes.ordre.matieres'; const PREF_ORDRE_FAMILLES = 'notes.ordre.familles'; const PREF_TRI = 'notes.tri'; const AUCUNE: NoteHypothetique[] = []; +const AUCUNE_RETOUCHE: Retouche[] = []; +const AUCUN_ID = new Set(); export default function Notes() { const c = useCouleurs(); @@ -102,11 +113,13 @@ export default function Notes() { const simulation = useSimulation(); useEffect(() => void simulation.charger(), [simulation.charger]); // eslint-disable-line react-hooks/exhaustive-deps const simulees = (periode && simulation.notes[cleSimulation(eleveId, periode)]) || AUCUNE; + const retouchees = (periode && simulation.retouches?.[cleSimulation(eleveId, periode)]) || AUCUNE_RETOUCHE; + const changements = simulees.length + retouchees.length; /** Notes réelles arrivées à la place d'une note simulée : id → note simulée. */ const etaitSimulee = new Map( (simulation.remplacees ?? []).filter((r) => periode && r.cle === cleSimulation(eleveId, periode)).map((r) => [r.noteId, r.hypothese]), ); - const simule = simulation.active && simulees.length > 0; + const simule = simulation.active && changements > 0; const reelle = useMemo(() => (instantane && periode ? vueNotes(instantane, periode) : undefined), [instantane, periode]); // Simulation active : les notes simulées rejoignent les vraies ; le reste (calibration, nouveautés) reste réel. const instantaneVu = useMemo( @@ -116,11 +129,11 @@ export default function Notes() { ...instantane, donnees: { ...instantane.donnees, - notes: avecHypotheses(reelle.periode, instantane.donnees.notes, simulees), + notes: avecHypotheses(reelle.periode, instantane.donnees.notes, simulees, retouchees), }, } : instantane, - [instantane, reelle, simule, simulees], + [instantane, reelle, simule, simulees, retouchees], ); const vue = useMemo(() => { if (!reelle || !simule || !instantaneVu) return reelle; @@ -171,7 +184,9 @@ export default function Notes() { action={ {vue ? ( - router.push({ pathname: '/courbes', params: { periode: vue.periode.code, eleve: eleveId } })}> + router.push({ pathname: '/courbes', params: { periode: vue.periode.code, eleve: eleveId } })}> ) : null} @@ -183,9 +198,7 @@ export default function Notes() { ) : null} - !etat?.chargement && charger(eleveId, true)}> + !etat?.chargement && charger(eleveId, true)}> @@ -203,9 +216,14 @@ export default function Notes() { ) : null} - {simulees.length > 0 ? ( + {changements > 0 ? ( - + ) : null} @@ -341,6 +359,7 @@ export default function Notes() { matieres={matieres} tri={tri} notes={instantaneVu!.donnees.notes} + retouchees={simule ? new Set(retouchees.map((x) => x.noteId)) : AUCUN_ID} etaitSimulee={etaitSimulee} onMatiere={ouvrir} onNote={ouvrirNote} @@ -380,6 +399,7 @@ function ParNote({ matieres, tri, notes, + retouchees, etaitSimulee, onMatiere, onNote, @@ -388,17 +408,19 @@ function ParNote({ matieres: LigneMatiere[]; tri: Tri; notes: Note[]; + /** Vraies notes changées par la simulation : leur valeur s'affiche en orange, comme une note simulée. */ + retouchees: Set; etaitSimulee: Map; onMatiere: (code: string) => void; onNote: (id: string) => void; }) { const c = useCouleurs(); const parId = new Map(notes.map((n) => [n.id, n])); - if (tri !== 'matiere') return ; + if (tri !== 'matiere') return ; const groupes = matieres .map(({ matiere: m }) => ({ m, - lignes: [...m.notes, ...m.sousMatieres.flatMap((s) => s.notes)].map((d) => ({ d, n: parId.get(d.id)! })).sort((a, b) => b.n.date.localeCompare(a.n.date)), + lignes: [...m.notes, ...m.sousMatieres.flatMap((s) => s.notes)].map((d) => ({ d, n: parId.get(d.id)! })).sort((a, b) => parRecence(a.n, b.n)), })) .filter((g) => g.lignes.length > 0); if (groupes.length === 0) { @@ -441,10 +463,11 @@ function ParNote({ {jour(n.date)} · coef {coef(n.coef)} {d.exclue ? ' · non comptée' : ''} + {retouchees.has(n.id) ? ' · retouchée' : ''} {etaitSimulee.has(n.id) ? ` · simulée ${coef(etaitSimulee.get(n.id)!.valeur)}/${etaitSimulee.get(n.id)!.noteSur}` : ''} - + {brute(n.valeurBrute)} /{n.noteSur} @@ -637,12 +660,14 @@ function NotesTriees({ matieres, tri, notes, + retouchees, onNote, }: { vue: VueNotes; matieres: LigneMatiere[]; tri: Exclude; notes: Note[]; + retouchees: Set; onNote: (id: string) => void; }) { const c = useCouleurs(); @@ -685,9 +710,10 @@ function NotesTriees({ {nom} · {jour(n.date)} · coef {coef(n.coef)} {exclues.has(n.id) ? ' · non comptée' : ''} + {retouchees.has(n.id) ? ' · retouchée' : ''} - + {brute(n.valeurBrute)} /{n.noteSur} @@ -733,7 +759,27 @@ function IconeTri() { } /** Rappel d'une simulation en cours : l'afficher ou non, la modifier. */ -function BandeauSimulation({ n, active, onActiver, onModifier }: { n: number; active: boolean; onActiver: (v: boolean) => void; onModifier: () => void }) { +/** « 2 notes simulées », « 1 note simulée, 1 retouchée », « 1 note retouchée ». */ +function resumeSimulation(ajoutees: number, retouchees: number): string { + const s = (n: number) => (n > 1 ? 's' : ''); + const parts = [ + ajoutees ? `${ajoutees} note${s(ajoutees)} simulée${s(ajoutees)}` : '', + retouchees ? `${retouchees}${ajoutees ? '' : ` note${s(retouchees)}`} retouchée${s(retouchees)}` : '', + ]; + return parts.filter(Boolean).join(', '); +} + +function BandeauSimulation({ + texte, + active, + onActiver, + onModifier, +}: { + texte: string; + active: boolean; + onActiver: (v: boolean) => void; + onModifier: () => void; +}) { const c = useCouleurs(); return ( - + - {n} note{n > 1 ? 's' : ''} simulée{n > 1 ? 's' : ''} + {texte} {active ? 'Moyennes simulées ci-dessous · modifier' : 'Masquée : moyennes réelles · modifier'} diff --git a/app/note/[id].tsx b/app/note/[id].tsx index ac64efe..4b923da 100644 --- a/app/note/[id].tsx +++ b/app/note/[id].tsx @@ -48,6 +48,11 @@ export default function DetailNote() { return ( + {n.dateSaisie ? ( + + Ajoutée le {jour(n.dateSaisie)} + + ) : null} @@ -80,7 +85,7 @@ export default function DetailNote() { /> ) : null} - {[jour(n.date), n.typeDevoir, valeur !== undefined && n.noteSur !== 20 ? `soit ${moyenne((valeur * 20) / n.noteSur)}/20` : undefined] + {[`devoir du ${jour(n.date)}`, n.typeDevoir, valeur !== undefined && n.noteSur !== 20 ? `soit ${moyenne((valeur * 20) / n.noteSur)}/20` : undefined] .filter(Boolean) .join(' · ')} diff --git a/app/reglages.tsx b/app/reglages.tsx index 1c5a028..abf96ff 100644 --- a/app/reglages.tsx +++ b/app/reglages.tsx @@ -56,7 +56,16 @@ export default function Reglages() { await toutEffacer(); vider(); reinitialiserApparence(); - useSimulation.setState({ notes: {}, objectif: undefined, objectifAffiche: undefined, remplacees: undefined, active: true, modifie: false, charge: false }); + useSimulation.setState({ + notes: {}, + retouches: undefined, + objectif: undefined, + objectifAffiche: undefined, + remplacees: undefined, + active: true, + modifie: false, + charge: false, + }); router.replace('/connexion'); } @@ -136,8 +145,8 @@ export default function Reglages() { {optimisee ? ( <> - Android économise la batterie de Coef : la vérification peut être retardée de plusieurs heures, voire bloquée. Si les notifications arrivent - tard ou jamais, retire Coef de l’optimisation. + Android économise la batterie de Coef : la vérification peut être retardée de plusieurs heures, voire bloquée. Si les notifications arrivent tard + ou jamais, retire Coef de l’optimisation. diff --git a/app/simulateur.tsx b/app/simulateur.tsx index 96bb031..a561951 100644 --- a/app/simulateur.tsx +++ b/app/simulateur.tsx @@ -5,8 +5,8 @@ import { useEffect, useState } from 'react'; import { StyleSheet, View } from 'react-native'; import { leviers } from '@/domain/moyennes/impact'; -import { calculer } from '@/domain/moyennes/moteur'; -import { avecHypotheses, noteNecessaire, type NoteHypothetique } from '@/domain/moyennes/simulateur'; +import { calculer, lireNote, notesDeLaPeriode } from '@/domain/moyennes/moteur'; +import { avecHypotheses, noteNecessaire, type NoteHypothetique, type Retouche } from '@/domain/moyennes/simulateur'; import type { Note, Periode } from '@/domain/types'; import { cleSimulation, useSimulation } from '@/features/notes/simulation'; import { useNotes } from '@/features/notes/store'; @@ -30,13 +30,14 @@ import { Segments, Texte, } from '@/ui/composants'; -import { coef as formatCoef, moyenne } from '@/ui/format'; +import { brute, coef as formatCoef, jour, moyenne } from '@/ui/format'; import { espace, police, taille, useCouleurs } from '@/ui/theme'; import Svg, { Path } from 'react-native-svg'; const POIDS = [0.5, 1, 2, 3, 4]; const AUCUNE: NoteHypothetique[] = []; -type Onglet = 'ajouter' | 'calcul' | 'objectif'; +const AUCUNE_RETOUCHE: Retouche[] = []; +type Onglet = 'ajouter' | 'notes' | 'calcul' | 'objectif'; type Saisie = { code: string; valeur: number; sur: number; poids: number }; export default function Simulation() { @@ -53,6 +54,8 @@ export default function Simulation() { const [onglet, setOnglet] = useState(params.onglet === 'objectif' ? 'objectif' : 'ajouter'); const cle = cleSimulation(params.eleve, params.periode); const hypotheses = useSimulation((s) => s.notes[cle]) ?? AUCUNE; + const retouches = useSimulation((s) => s.retouches?.[cle]) ?? AUCUNE_RETOUCHE; + const retoucher = useSimulation((s) => s.retoucher); const { active, modifie, definir, activer, enregistrer, charger, viser, afficherObjectif, afficherExtremes } = useSimulation(); const extremesAffiches = useSimulation((s) => s.extremesAffiches ?? false); const objectif = useSimulation((s) => s.objectif) ?? 14; @@ -114,7 +117,7 @@ export default function Simulation() { const options = { parametrage: d.parametrage }; const avant = calculer(p, d.notes, d.periodes, options); - const notesSimulees = avecHypotheses(p, d.notes, hypotheses); + const notesSimulees = avecHypotheses(p, d.notes, hypotheses, retouches); const apres = calculer(p, notesSimulees, d.periodes, options); const libelle = (code: string) => p.matieres.find((m) => m.code === code && !m.sousCode)?.libelle ?? code; const ajouter = (s: Saisie) => @@ -147,13 +150,31 @@ export default function Simulation() { 1 ? 's' : ''} ajoutée${hypotheses.length > 1 ? 's' : ''}`} + suffixe={`avec ${[ + hypotheses.length || !retouches.length + ? `${hypotheses.length} note${hypotheses.length > 1 ? 's' : ''} ajoutée${hypotheses.length > 1 ? 's' : ''}` + : '', + retouches.length + ? `${retouches.length}${hypotheses.length ? '' : ` note${retouches.length > 1 ? 's' : ''}`} retouchée${retouches.length > 1 ? 's' : ''}` + : '', + ] + .filter(Boolean) + .join(', ')}`} /> ) : ( )} - {hypotheses.length > 0 ? setHypotheses([])} /> : null} + {hypotheses.length + retouches.length > 0 ? ( + { + setHypotheses([]); + retoucher(cle, []); + }} + /> + ) : null} @@ -163,6 +184,7 @@ export default function Simulation() { libelle="Mode de simulation" options={[ { cle: 'ajouter' as const, libelle: 'Ajouter' }, + { cle: 'notes' as const, libelle: 'Mes notes' }, { cle: 'calcul' as const, libelle: 'Calculateur' }, { cle: 'objectif' as const, libelle: 'Objectif' }, ]} @@ -236,6 +258,8 @@ export default function Simulation() { })} + ) : onglet === 'notes' ? ( + retoucher(cle, r)} /> ) : onglet === 'calcul' ? ( string; + retouches: Retouche[]; + onChange: (r: Retouche[]) => void; +}) { + const c = useCouleurs(); + const [ouverte, setOuverte] = useState(); + const parNote = new Map(retouches.map((r) => [r.noteId, r])); + const note = notes.find((n) => n.id === ouverte); + const retouche = note ? parNote.get(note.id) : undefined; + const compteParDefaut = (n: Note) => !n.nonSignificative && lireNote(n.valeurBrute) !== undefined; + // Une retouche revenue à l'état réel disparaît : la simulation ne garde que de vrais changements. + const modifier = (n: Note, champs: Partial) => { + const suite = { ...parNote.get(n.id), ...champs, noteId: n.id }; + if (suite.valeur !== undefined && suite.valeur === lireNote(n.valeurBrute)) delete suite.valeur; + if (suite.compte !== undefined && suite.compte === compteParDefaut(n)) delete suite.compte; + const autres = retouches.filter((r) => r.noteId !== n.id); + onChange(suite.valeur === undefined && suite.compte === undefined ? autres : [...autres, suite]); + }; + const codes = [...new Set(notes.map((n) => n.matiereCode))].sort((a, b) => libelle(a).localeCompare(libelle(b), 'fr')); + + if (notes.length === 0) { + return ( + + Aucune note dans cette période. + + ); + } + return ( +
+ + {codes.map((code) => ( + + + {libelle(code)} + + + {notes + .filter((n) => n.matiereCode === code) + .sort((a, b) => b.date.localeCompare(a.date)) + .map((n, i, l) => { + const r = parNote.get(n.id); + const compte = r?.compte ?? compteParDefaut(n); + return ( + setOuverte(n.id)} + libelleAccessible={`${n.devoir || 'Devoir'}, ${brute(n.valeurBrute)} sur ${n.noteSur}${r ? ', retouchée' : ''}. Modifier`}> + + + {n.devoir || 'Devoir'} + + + {jour(n.date)} · coef {formatCoef(n.coef)} + {compte ? '' : ' · ne compte pas'} + + + + {r?.valeur !== undefined ? `${brute(n.valeurBrute)} → ${formatCoef(r.valeur)}` : brute(n.valeurBrute)} + + /{n.noteSur} + + + + ); + })} + + + ))} + + setOuverte(undefined)} titre={note ? note.devoir || 'Devoir' : ''}> + {note ? ( + + + {libelle(note.matiereCode)} · {jour(note.date)} · vraie note {brute(note.valeurBrute)}/{note.noteSur} + + modifier(note, { valeur: v })} + libelle="Note simulée" + texteValeur={`${formatCoef(retouche?.valeur ?? lireNote(note.valeurBrute) ?? note.noteSur / 2)}/${note.noteSur}`} + /> + modifier(note, { compte: v })} /> + {retouche ? ( + modifier(note, { valeur: undefined, compte: undefined })} /> + ) : null} + + ) : null} + +
+ ); +} diff --git a/src/domain/moyennes/__tests__/moteur.test.ts b/src/domain/moyennes/__tests__/moteur.test.ts index 437c858..370fdb1 100644 --- a/src/domain/moyennes/__tests__/moteur.test.ts +++ b/src/domain/moyennes/__tests__/moteur.test.ts @@ -3,7 +3,7 @@ import * as fc from 'fast-check'; import type { MatierePeriode, Note, Periode } from '../../types'; import { calibrer } from '../calibration'; import { arrondi, calculer, lireNote, notesDeLaPeriode } from '../moteur'; -import { noteNecessaire, simuler } from '../simulateur'; +import { avecHypotheses, noteNecessaire, simuler } from '../simulateur'; const periode = (matieres: MatierePeriode[], extra: Partial = {}): Periode => ({ code: 'A001', @@ -302,3 +302,21 @@ describe('calibration', () => { expect(retenue.ecarts[0]!.libelle).toBe('Algèbre (ALG)'); }); }); + +describe('retouches de vraies notes dans la simulation', () => { + const p = periode([MATHS]); + const a = note('MATHS', '10'); + const b = note('MATHS', '16'); + const ns = note('MATHS', '4', { nonSignificative: true }); + const moy = (notes: Note[]) => calculer(p, notes, []).matieres[0]!.moyenne; + + test('sans retouche, rien ne change', () => expect(avecHypotheses(p, [a, b], [], [])).toEqual([a, b])); + test('une autre valeur remplace la vraie', () => expect(moy(avecHypotheses(p, [a, b], [], [{ noteId: a.id, valeur: 12.5 }]))).toBe(14.25)); + test('compte: false retire la note du calcul', () => expect(moy(avecHypotheses(p, [a, b], [], [{ noteId: a.id, compte: false }]))).toBe(16)); + test('compte: true compte une note non significative', () => expect(moy(avecHypotheses(p, [a, ns], [], [{ noteId: ns.id, compte: true }]))).toBe(7)); + test('une retouche sur une note inconnue est sans effet', () => expect(moy(avecHypotheses(p, [a, b], [], [{ noteId: 'disparue', compte: false }]))).toBe(13)); + test('les notes réelles ne sont pas modifiées', () => { + avecHypotheses(p, [a], [], [{ noteId: a.id, valeur: 2 }]); + expect(a.valeurBrute).toBe('10'); + }); +}); diff --git a/src/domain/moyennes/simulateur.ts b/src/domain/moyennes/simulateur.ts index 21d60f2..802c133 100644 --- a/src/domain/moyennes/simulateur.ts +++ b/src/domain/moyennes/simulateur.ts @@ -19,9 +19,28 @@ function versNote(p: Periode, h: NoteHypothetique, i: number): Note { }; } -/** Les notes réelles plus les notes hypothétiques, prêtes pour le moteur. */ -export function avecHypotheses(p: Periode, notes: Note[], hypotheses: NoteHypothetique[]): Note[] { - return [...notes, ...hypotheses.map((h, i) => versNote(p, h, i))]; +/** + * Retouche d'une vraie note dans la simulation : une autre valeur (sur son barème), et/ou le choix de la compter + * (`compte: false` lui donne un coefficient 0 ; `compte: true` la compte même si ED la dit non significative). + */ +export type Retouche = { noteId: string; valeur?: number; compte?: boolean }; + +/** Les notes réelles (retouchées) plus les notes hypothétiques, prêtes pour le moteur. */ +export function avecHypotheses(p: Periode, notes: Note[], hypotheses: NoteHypothetique[], retouches: Retouche[] = []): Note[] { + const parNote = new Map(retouches.map((r) => [r.noteId, r])); + const reelles = notes.flatMap((n) => { + const r = parNote.get(n.id); + if (!r) return [n]; + return [ + { + ...n, + ...(r.valeur !== undefined ? { valeurBrute: String(r.valeur).replace('.', ',') } : {}), + // Non comptée : coefficient 0 plutôt que retirée, pour qu'elle reste visible (« coef 0 ») dans les listes. + ...(r.compte === false ? { coef: 0 } : r.compte ? { nonSignificative: false } : {}), + }, + ]; + }); + return [...reelles, ...hypotheses.map((h, i) => versNote(p, h, i))]; } /** Moyennes de la période si l'on ajoute ces notes. */ diff --git a/src/features/notes/__tests__/ordre.test.ts b/src/features/notes/__tests__/ordre.test.ts index 273a337..0585cec 100644 --- a/src/features/notes/__tests__/ordre.test.ts +++ b/src/features/notes/__tests__/ordre.test.ts @@ -22,3 +22,12 @@ test('trierNotes : ramené sur 20, absences à la fin', () => { expect(trierNotes(n, 'moins-bonnes').map((x) => x.id)).toEqual(['b', 'a', 'd', 'c']); expect(trierNotes(n, 'recentes').map((x) => x.id)).toEqual(['c', 'b', 'd', 'a']); }); + +test('trierNotes récentes : par date de saisie d’abord (un vieux devoir saisi hier passe devant)', () => { + const n = [ + { ...note('vieux-devoir', '17,5', 20, '2026-10-07'), dateSaisie: '2026-11-21' }, + { ...note('recent', '12', 20, '2026-11-18'), dateSaisie: '2026-11-19' }, + note('sans-saisie', '10', 20, '2026-11-20'), + ]; + expect(trierNotes(n, 'recentes').map((x) => x.id)).toEqual(['vieux-devoir', 'sans-saisie', 'recent']); +}); diff --git a/src/features/notes/ordre.ts b/src/features/notes/ordre.ts index c8534e4..a79bb50 100644 --- a/src/features/notes/ordre.ts +++ b/src/features/notes/ordre.ts @@ -34,9 +34,15 @@ const sur20 = (n: Note) => { return v === undefined || n.noteSur <= 0 ? undefined : (v * 20) / n.noteSur; }; +/** + * Plus récente d'abord = ajoutée le plus récemment (date de saisie), comme « Nouvelles notes » et l'accueil : une + * note d'un devoir d'octobre saisie hier passe devant ; à saisie égale, la date du devoir départage. + */ +export const parRecence = (a: Note, b: Note) => (b.dateSaisie ?? b.date).localeCompare(a.dateSaisie ?? a.date) || b.date.localeCompare(a.date); + /** Tri à plat (récentes, meilleures, moins bonnes) ; les notes sans valeur (Abs, Disp…) toujours à la fin. */ export function trierNotes(notes: readonly Note[], tri: Exclude): Note[] { - const recentes = (a: Note, b: Note) => b.date.localeCompare(a.date); + const recentes = parRecence; if (tri === 'recentes') return [...notes].sort(recentes); const sens = tri === 'meilleures' ? -1 : 1; return [...notes].sort((a, b) => { diff --git a/src/features/notes/simulation.ts b/src/features/notes/simulation.ts index ec170a3..88bc787 100644 --- a/src/features/notes/simulation.ts +++ b/src/features/notes/simulation.ts @@ -4,7 +4,7 @@ import { create } from 'zustand'; import { MODE_DEMO } from '@/demo'; -import type { NoteHypothetique } from '@/domain/moyennes/simulateur'; +import type { NoteHypothetique, Retouche } from '@/domain/moyennes/simulateur'; import type { DonneesNotes, Note } from '@/domain/types'; import { ecrirePreference, lirePreference } from '@/storage/base'; @@ -14,6 +14,8 @@ const PREF = 'simulation'; type Enregistre = { active: boolean; notes: Record; + /** Vraies notes modifiées ou retirées du calcul (onglet « Mes notes »), par élève et période. */ + retouches?: Record; /** Moyenne générale visée (onglet Objectif), repère sur l'anneau de l'écran Notes. */ objectif?: number; /** L'objectif est dessiné sur l'écran Notes (indépendant de l'affichage des notes simulées). */ @@ -30,6 +32,7 @@ type EtatSimulation = Enregistre & { charge: boolean; charger: () => Promise; definir: (cle: string, notes: NoteHypothetique[]) => void; + retoucher: (cle: string, retouches: Retouche[]) => void; activer: (active: boolean) => void; viser: (objectif: number) => void; afficherObjectif: (v: boolean) => void; @@ -67,16 +70,17 @@ export const useSimulation = create((set, get) => ({ set({ charge: true }); const e = await lire(); // Ce qui a été saisi avant la fin de la lecture l'emporte. - if (e && Object.keys(get().notes).length === 0 && get().objectif === undefined) set({ ...e }); + if (e && Object.keys(get().notes).length === 0 && Object.keys(get().retouches ?? {}).length === 0 && get().objectif === undefined) set({ ...e }); }, definir: (cle, notes) => set((s) => ({ notes: { ...s.notes, [cle]: notes }, modifie: true })), + retoucher: (cle, retouches) => set((s) => ({ retouches: { ...s.retouches, [cle]: retouches }, modifie: true })), activer: (active) => set({ active, modifie: true }), viser: (objectif) => set({ objectif, modifie: true }), afficherObjectif: (objectifAffiche) => set({ objectifAffiche, modifie: true }), afficherExtremes: (extremesAffiches) => set({ extremesAffiches, modifie: true }), async enregistrer() { - const { active, notes, objectif, objectifAffiche, extremesAffiches, remplacees } = get(); - if (!MODE_DEMO) await ecrirePreference(PREF, { active, notes, objectif, objectifAffiche, extremesAffiches, remplacees } satisfies Enregistre); + const { active, notes, retouches, objectif, objectifAffiche, extremesAffiches, remplacees } = get(); + if (!MODE_DEMO) await ecrirePreference(PREF, { active, notes, retouches, objectif, objectifAffiche, extremesAffiches, remplacees } satisfies Enregistre); set({ modifie: false }); }, async integrer(eleveId, nouvelles, d) {