@@ -20,32 +20,54 @@ def load_notes_json(filepath):
2020 return []
2121
2222def save_notes_json (data , filepath ):
23- data . replace ( '�' , 'é' ). replace ( 'é' , 'é' ). replace ( 'è' , 'è' ). replace ( '�' , 'Á' )
23+ # La variable data est une liste, pas une string, donc on ne peut pas appeler replace dessus
2424 with open (filepath , "w" , encoding = "utf-8" ) as f :
2525 json .dump (data , f , ensure_ascii = False , indent = 2 )
2626 # Restreindre les permissions du fichier JSON (lecture/écriture propriétaire uniquement)
2727 os .chmod (filepath , 0o600 )
2828
2929def find_new_notes (old_notes , new_notes ):
30+ """
31+ Détecte les changements entre old_notes et new_notes.
32+ Retourne une liste de changements : [matiere, section, note, ponderation]
33+
34+ Détecte :
35+ - Nouvelles notes ajoutées
36+ - Notes modifiées
37+ - Pondérations modifiées
38+ """
3039 changes = []
3140 old_map = {(m ['matiere' ], m ['coef' ]): m for m in old_notes }
41+
3242 for new_matiere in new_notes :
3343 key = (new_matiere ['matiere' ], new_matiere ['coef' ])
3444 old_matiere = old_map .get (key )
45+
3546 if not old_matiere :
47+ # Nouvelle matière, ignorer (on ne notifie que les notes)
3648 continue
49+
3750 for section in ["Projet" , "Contrôle Continu" , "Examen" ]:
3851 old_section = old_matiere ['sections' ].get (section , [])
3952 new_section = new_matiere ['sections' ].get (section , [])
53+
4054 for idx , new_block in enumerate (new_section ):
4155 old_block = old_section [idx ] if idx < len (old_section ) else None
4256 new_notes_list = new_block .get ("notes" , [])
4357 old_notes_list = old_block .get ("notes" , []) if old_block else []
44- for n_idx , new_note in enumerate (new_notes_list ):
45- old_note = old_notes_list [n_idx ] if n_idx < len (old_notes_list ) else None
46- if old_note != new_note :
58+
59+ # Créer un ensemble des notes existantes pour comparaison
60+ old_notes_set = {(n .get ("note" , "" ), n .get ("pondération" , "" )) for n in old_notes_list }
61+
62+ # Parcourir toutes les nouvelles notes
63+ for new_note in new_notes_list :
64+ new_note_tuple = (new_note .get ("note" , "" ), new_note .get ("pondération" , "" ))
65+
66+ # Si la note n'existe pas dans old_notes_set, c'est un changement
67+ if new_note_tuple not in old_notes_set :
4768 matiere_tronquee = new_matiere ['matiere' ].split ('/' )[0 ].strip ()
4869 note = new_note .get ("note" , "" )
4970 ponderation = new_note .get ("pondération" , "" )
5071 changes .append ([matiere_tronquee , section , note , ponderation ])
72+
5173 return changes
0 commit comments