File size: 3,636 Bytes
a01c266
 
826d110
a01c266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
826d110
 
a01c266
826d110
 
 
 
 
 
 
a01c266
826d110
 
 
 
 
 
 
 
 
 
 
 
 
 
a01c266
 
 
 
 
 
826d110
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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')})"):
                            # Display grade information using structured layout

                            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")