|
import streamlit as st |
|
from collections import defaultdict |
|
from datetime import datetime |
|
|
|
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.strftime('%d/%m/%Y')})"): |
|
|
|
|
|
st.markdown("### Informations Générales") |
|
st.write(f"**Commentaire**: {grade.comment if grade.comment else 'Pas de commentaire'}") |
|
col1, col2 = st.columns(2) |
|
with col1: |
|
st.metric(label="Date", value=grade.date.strftime("%d/%m/%Y")) |
|
with col2: |
|
st.metric(label="Coefficient", value=str(grade.coefficient)) |
|
|
|
st.markdown("---") |
|
|
|
st.markdown("### Note") |
|
col1, col2, col3, col4 = st.columns(4) |
|
with col1: |
|
st.metric(label="Note de l'Élève", value=f"{grade.grade}/{grade.out_of}") |
|
with col2: |
|
st.metric(label="Moyenne de la Classe", value=f"{grade.average}/{grade.out_of}") |
|
with col3: |
|
st.metric(label="Minimum", value=f"{grade.min}/{grade.out_of}") |
|
with col4: |
|
st.metric(label="Maximum", value=f"{grade.max}/{grade.out_of}") |
|
|
|
all_grades = [grade for period in periods_to_display for grade in period.grades] |
|
overall_average = calculate_average(all_grades) |
|
|
|
st.subheader("⭐ Moyenne Générale") |
|
if isinstance(overall_average, str): |
|
st.write(overall_average) |
|
else: |
|
col1, col2 = st.columns(2) |
|
with col1: |
|
st.metric(label="Élève", value=f"{overall_average:.2f}/20") |
|
with col2: |
|
st.metric(label="Classe", value=f"NaN/20") |