|
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') |
|
|
|
|
|
selected_period = st.selectbox("🧷 Sélectionner la période", ["Trimestre 1", "Trimestre 2", "Trimestre 3", "Année"]) |
|
|
|
|
|
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] |
|
|
|
|
|
tab_labels = sorted({grade.subject.name for period in periods_to_display for grade in period.grades}) |
|
|
|
|
|
tabs = st.tabs(tab_labels) |
|
|
|
for tab, subject in zip(tabs, tab_labels): |
|
with tab: |
|
|
|
for period in periods_to_display: |
|
|
|
grades_by_subject = defaultdict(list) |
|
for grade in period.grades: |
|
grades_by_subject[grade.subject.name].append(grade) |
|
|
|
|
|
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}") |
|
|
|
|
|
all_grades = [] |
|
for period in periods_to_display: |
|
for grade in period.grades: |
|
all_grades.append(grade) |
|
|
|
|
|
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") |
|
|
|
|
|
|