orga / pages /notes.py
Lenylvt's picture
Update pages/notes.py
f2ee14b verified
raw
history blame
No virus
3.7 kB
import streamlit as st
from collections import defaultdict
def calculate_average(grades):
total_points, total_coefficients = 0, 0
for grade in grades:
try:
if grade.grade.lower() != 'absent':
numeric_grade = float(grade.grade)
grade_out_of = float(grade.out_of)
coefficient = float(grade.coefficient)
normalized_grade = (numeric_grade / grade_out_of) * 20
total_points += normalized_grade * coefficient
total_coefficients += coefficient
except ValueError:
continue
return total_points / total_coefficients if total_coefficients > 0 else "Aucune Note"
def app(client):
st.title('📝 Notes')
# Dropdown pour sélectionner la période
selected_period = st.selectbox("🧷 Sélectionner la période", ["Trimestre 1", "Trimestre 2", "Trimestre 3", "Année"])
# Filtrer les périodes en fonction de la sélection
if selected_period == "Année":
periods_to_display = client.periods
else:
periods_to_display = [period for period in client.periods if period.name == selected_period]
# Créer une liste des matières pour les onglets
tab_labels = sorted({grade.subject.name for period in periods_to_display for grade in period.grades})
# Créer des onglets pour les matières
tabs = st.tabs(tab_labels)
for tab, subject in zip(tabs, tab_labels):
with tab:
# Afficher les notes pour toutes les périodes sélectionnées
for period in periods_to_display:
# Organiser les notes par matière
grades_by_subject = defaultdict(list)
for grade in period.grades:
grades_by_subject[grade.subject.name].append(grade)
# Afficher les notes pour la matière de l'onglet actuel
if subject in grades_by_subject:
for grade in grades_by_subject[subject]:
with st.expander(f"📝 {grade.grade}/{grade.out_of} | {grade.comment if grade.comment else 'Et voilà, ça ne donne pas de nom !'} (📅 {grade.date})"):
st.markdown("### Information")
st.write(f"**Commentaire** : {grade.comment}")
st.write(f"**Date** : {grade.date}")
st.write(f"**Coefficient** : {grade.coefficient}")
if grade.is_bonus:
st.write(f"**Note Bonus** (*Est pris en compte seulement les points au-dessus de 10*)")
if grade.is_optionnal:
st.write(f"**Note Optionnelle** (*Est pris en compte seulement si la note augmente la moyenne*)")
st.markdown("### Eleve")
st.write(f"{grade.grade}/{grade.out_of}")
st.markdown("### Classe")
st.write(f"**Moyenne** : {grade.average}")
st.write(f"**Minimum** : {grade.min}")
st.write(f"**Maximum** : {grade.max}")
# Instead of directly calculating the overall average, gather all grades
all_grades = []
for period in periods_to_display:
for grade in period.grades:
all_grades.append(grade)
# Use the calculate_average function to calculate the overall average
overall_average = calculate_average(all_grades)
st.subheader("⭐ Moyenne Générale")
if isinstance(overall_average, str):
st.write(overall_average)
else:
st.write(f"### {overall_average:.2f}/20")