def get_student_by_id(students, student_id): for student in students: if student.educmaster == student_id: return student return None def calculer_moyennes(resultats): moyennes = {} for annee, matieres in resultats.items(): if annee != "Baccalauréat": moyennes[annee] = {} for matiere, notes in matieres.items(): moyenne = (notes["Semestre 1"] + notes["Semestre 2"]) / 2 moyennes[annee][matiere] = moyenne return moyennes def calculer_scores_selection(moyennes, coefficients, biais): scores = {} for annee, matieres in moyennes.items(): scores[annee] = {} for matiere, moyenne in matieres.items(): coef = coefficients.get_coefficient(matiere) score = (moyenne * coef) + moyenne + biais.get(matiere, 0) scores[annee][matiere] = score return scores def selectionner_meilleures_matieres(scores): """ Sélectionne les trois meilleures matières pour chaque année, y compris le Baccalauréat. :param scores: Les scores des matières par année. :return: Un dictionnaire des meilleures matières par année. """ meilleures_matieres = {} for annee, matieres in scores.items(): sorted_matieres = sorted(matieres.items(), key=lambda x: x[1], reverse=True) meilleures_matieres[annee] = [matiere for matiere, score in sorted_matieres[:3]] return meilleures_matieres def compter_occurrences_meilleures_matieres(meilleures_matieres): occurrences = {} for annee, matieres in meilleures_matieres.items(): for matiere in matieres: if matiere in occurrences: occurrences[matiere] += 1 else: occurrences[matiere] = 1 return occurrences def selectionner_top_matieres(occurrences, biais): sorted_occurrences = sorted(occurrences.items(), key=lambda x: (x[1], biais.get(x[0], 0)), reverse=True) return [matiere for matiere, count in sorted_occurrences[:4]] def proposer_filieres(top_matieres, filieres, serie): propositions = [] for filiere in filieres: if filiere.serie == serie: count_best_matieres = sum(1 for matiere in top_matieres if matiere in filiere.matieres) propositions.append((filiere, count_best_matieres)) propositions_triees = sorted(propositions, key=lambda x: x[1], reverse=True) return [filiere for filiere, count in propositions_triees]