File size: 4,840 Bytes
1d8c2e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c548fe0
1d8c2e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"""
UI Components
"""

import streamlit as st


def render_navigation(current_index, total_items):
    """
    Affiche les boutons de navigation

    Returns:
        Nouvelle valeur de l'index si changement, None sinon
    """
    col1, col2, col3 = st.columns([1, 2, 1])

    new_index = None

    with col1:
        if st.button("Précédent", use_container_width=True, disabled=current_index == 0):
            new_index = current_index - 1

    with col2:
        st.markdown(f"<div class='center-text'>Exemple {current_index + 1} / {total_items}</div>", unsafe_allow_html=True)

    with col3:
        if st.button("Suivant", use_container_width=True, disabled=current_index >= total_items - 1):
            new_index = current_index + 1

    return new_index


def render_code_block(code_text, language="python"):
    """Affiche un bloc de code avec syntax highlighting"""
    st.markdown("### Code")
    st.code(code_text, language=language)


def render_feedback_block(feedback_text):
    """Affiche le feedback dans un bloc stylisé adapté au thème"""
    st.markdown("### Feedback")

    # Utilise la classe CSS qui s'adapte automatiquement au thème
    st.markdown(f"""
<div class="feedback-block">
{feedback_text}
</div>
""", unsafe_allow_html=True)


def render_score_slider(score_key, current_score=3):
    """
    Affiche le slider de notation

    Returns:
        Score sélectionné
    """
    st.markdown("### Notez le feedback")
    st.caption("À quel point ce feedback est-il utile et pertinent pour ce code ?")

    score = st.slider(
        "Score",
        min_value=0,
        max_value=5,
        value=current_score,
        step=1,
        format="%d",
        key=score_key,
        help="0 = Pas utile du tout, 5 = Extrêmement utile"
    )

    # Show score meaning
    score_meanings = {
        0: "Pas utile / Incorrect",
        1: "Très peu utile",
        2: "Peu utile",
        3: "Moyennement utile",
        4: "Utile",
        5: "Extrêmement utile"
    }

    st.info(f"{score} - {score_meanings[score]}")

    return score


def render_comment_field(comment_key, current_comment=""):
    """
    Affiche le champ de commentaire optionnel

    Returns:
        Commentaire saisi
    """
    with st.expander("Ajouter un commentaire (optionnel)"):
        comment = st.text_area(
            "Commentaire",
            value=current_comment,
            key=comment_key,
            placeholder="Pourquoi ce score ? (optionnel)",
            label_visibility="collapsed"
        )
    return comment


def render_progress_metrics(total, scored, remaining, progress_pct):
    """Affiche les métriques de progression"""
    st.markdown("### Progression")

    col1, col2, col3, col4 = st.columns(4)

    with col1:
        st.metric("Total", total)

    with col2:
        st.metric("Scorés", scored)

    with col3:
        st.metric("Restants", remaining)

    with col4:
        st.metric("Progression", f"{progress_pct:.0f}%")

    st.progress(progress_pct / 100)


def render_statistics(avg_score, most_common_score, score_counts):
    """Affiche les statistiques détaillées"""
    st.markdown("### Statistiques des Scores")

    col1, col2 = st.columns(2)

    with col1:
        st.metric("Score Moyen", f"{avg_score:.2f}")

    with col2:
        st.metric("Score le plus fréquent", f"{most_common_score[0]} ({most_common_score[1]}x)")

    st.bar_chart(score_counts, height=200)


def render_export_section(export_data):
    """Affiche la section d'export"""
    st.markdown("### Export")

    col1, col2 = st.columns(2)

    with col1:
        st.metric("Items à exporter", len(export_data))

    return col1, col2


def render_quick_actions(items_with_positive, feedback_scores, current_index):
    """
    Affiche les actions rapides

    Returns:
        Tuple (reset_requested, jump_to_unscored, jump_to_index)
    """
    st.markdown("### Actions Rapides")

    col1, col2, col3 = st.columns(3)

    reset_requested = False
    jump_to_unscored = False
    jump_to_index = None

    with col1:
        if st.button("Réinitialiser tous les scores", use_container_width=True):
            reset_requested = True

    with col2:
        unscored_indices = [idx for idx, _ in items_with_positive if idx not in feedback_scores]
        if unscored_indices and st.button("Aller au prochain non-scoré", use_container_width=True):
            jump_to_unscored = True

    with col3:
        jump_to = st.number_input(
            "Aller à l'exemple",
            min_value=1,
            max_value=len(items_with_positive),
            value=current_index + 1,
            step=1,
            key="jump_to"
        )
        if st.button("Aller", use_container_width=True):
            jump_to_index = jump_to - 1

    return reset_requested, jump_to_unscored, jump_to_index