File size: 6,158 Bytes
54f91c5
 
a7651d7
54f91c5
 
 
 
 
 
 
 
a7651d7
 
 
 
 
54f91c5
 
 
a7651d7
 
 
54f91c5
 
 
 
 
 
a7651d7
54f91c5
 
a7651d7
 
 
54f91c5
 
 
 
 
 
 
 
 
 
 
 
a7651d7
54f91c5
 
 
a7651d7
54f91c5
 
 
 
 
 
 
a7651d7
 
54f91c5
a7651d7
 
 
54f91c5
 
a7651d7
54f91c5
 
 
a7651d7
 
54f91c5
 
 
 
 
 
 
 
 
a7651d7
54f91c5
 
 
 
a7651d7
54f91c5
 
 
 
 
 
 
 
 
a7651d7
 
 
54f91c5
a7651d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54f91c5
a7651d7
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
import streamlit as st
import pandas as pd
from fpdf import FPDF

# Initialiser l'état de la session
if 'phases' not in st.session_state:
    st.session_state['phases'] = []

# Titre
st.title('Gestion des erreurs de mélange de béton')

st.header('Entrées les normes de calcul')
g2_norme = st.number_input('G2 norme', value=575.0, format="%.2f")
g1_norme = st.number_input('G1 norme', value=1000.0, format="%.2f")
sb_norme = st.number_input('SB norme', value=1237.0, format="%.2f")
cube_norme = st.number_input('Cube norme', value=1.5, format="%.2f")

# Section d'entrée pour la phase
st.header('Entrées pour la phase')
g2_input = st.number_input('G2', format="%.2f")
g1_input = st.number_input('G1', format="%.2f")
sb_input = st.number_input('SB', format="%.2f")
cubes_input = st.number_input('Cubes', value=1.5, format="%.2f")

# Ajouter la phase
if st.button('Ajouter la phase'):
    phase_data = {
        'G2': g2_input,
        'G1': g1_input,
        'SB': sb_input,
        'Cubes': cubes_input,
        'G2_Error': g2_input - (g2_norme / cube_norme * cubes_input),
        'G1_Error': (g1_input - g2_input) - (g1_norme / cube_norme * cubes_input),
        'SB_Error': (sb_input - g1_input) - (sb_norme / cube_norme * cubes_input),
    }
    st.session_state['phases'].append(phase_data)

# Afficher les phases
st.header('Phases')
phases_df = pd.DataFrame(st.session_state['phases'])
st.write(phases_df)

# Calculer les erreurs totales
st.header('Calcul des erreurs')
try:
    total_g2_error = phases_df['G2_Error'].sum()
    total_g1_error = phases_df['G1_Error'].sum()
    total_sb_error = phases_df['SB_Error'].sum()

    st.write(f"Erreur totale G2: {total_g2_error}")
    st.write(f"Erreur totale G1: {total_g1_error}")
    st.write(f"Erreur totale SB: {total_sb_error}")
except KeyError as e:
    st.error(f"Erreur dans les données: {e}")

# Correction des erreurs en fonction des cubes restants
st.header('Correction des erreurs')
remaining_cubes = st.number_input('Cubes restants', value=1.0, format="%.2f")

if st.button('Corriger les erreurs') or remaining_cubes > 0:
    try:
        correction_g2 = g2_norme / cube_norme * remaining_cubes - total_g2_error
        correction_g1 = g1_norme / cube_norme * remaining_cubes - total_g1_error
        correction_sb = sb_norme / cube_norme * remaining_cubes - total_sb_error

        st.write(f"Correction G2 par cube: {correction_g2}")
        st.write(f"Correction G1 par cube: {correction_g1}")
        st.write(f"Correction SB par cube: {correction_sb}")
    except ZeroDivisionError:
        st.error("Le nombre de cubes restants doit être supérieur à zéro pour corriger les erreurs.")
else:
    correction_g2 = correction_g1 = correction_sb = 0

# Générer un rapport détaillé des erreurs
st.header('Rapport détaillé des erreurs')
if st.button('Générer le rapport'):
    try:
        report = f"""
        ## Rapport détaillé des erreurs
        ### Erreurs totales
        - Erreur G2: {total_g2_error}
        - Erreur G1: {total_g1_error}
        - Erreur SB: {total_sb_error}
        
        ### Correction nécessaire
        - G2 par cube: {correction_g2}
        - G1 par cube: {correction_g1}
        - SB par cube: {correction_sb}
        
        ### Phases
        {phases_df.to_markdown()}
        """
        st.markdown(report)
    except Exception as e:
        st.error(f"Erreur lors de la génération du rapport: {e}")

# Enregistrer le rapport en PDF
st.header('Enregistrer le rapport en PDF')
if st.button('Enregistrer le rapport en PDF'):
    try:
        class PDF(FPDF):
            def header(self):
                self.set_font('Arial', 'B', 12)
                self.cell(0, 10, 'Rapport détaillé des erreurs de mélange de béton', 0, 1, 'C')
                self.ln(10)

            def chapter_title(self, title):
                self.set_font('Arial', 'B', 12)
                self.cell(0, 10, title, 0, 1, 'L')
                self.ln(5)

            def chapter_body(self, body):
                self.set_font('Arial', '', 12)
                self.multi_cell(0, 10, body)
                self.ln()

            def add_phase_table(self, df):
                self.set_font('Arial', 'B', 10)
                col_width = self.w / (len(df.columns) + 1)  # Largeur des colonnes
                th = self.font_size

                # Header
                for column in df.columns:
                    self.cell(col_width, th, column, border=1)
                self.ln(th)

                # Data
                self.set_font('Arial', '', 10)
                for i in range(len(df)):
                    self.cell(col_width, th, str(df.iloc[i]['G2']), border=1)
                    self.cell(col_width, th, str(df.iloc[i]['G1']), border=1)
                    self.cell(col_width, th, str(df.iloc[i]['SB']), border=1)
                    self.cell(col_width, th, str(df.iloc[i]['Cubes']), border=1)
                    self.cell(col_width, th, str(df.iloc[i]['G2_Error']), border=1)
                    self.cell(col_width, th, str(df.iloc[i]['G1_Error']), border=1)
                    self.cell(col_width, th, str(df.iloc[i]['SB_Error']), border=1)
                    self.ln(th)

        pdf = PDF()
        pdf.add_page()

        pdf.chapter_title("Erreurs totales")
        pdf.chapter_body(f"Erreur G2: {total_g2_error}\nErreur G1: {total_g1_error}\nErreur SB: {total_sb_error}")

        pdf.chapter_title("Correction nécessaire")
        pdf.chapter_body(f"G2 par cube: {correction_g2}\nG1 par cube: {correction_g1}\nSB par cube: {correction_sb}")

        pdf.chapter_title("Phases")
        pdf.add_phase_table(phases_df)

        pdf_file = "rapport_erreurs.pdf"
        pdf.output(pdf_file)
        st.write('Rapport PDF enregistré sous le nom rapport_erreurs.pdf')
        with open(pdf_file, "rb") as file:
            st.download_button(
                label="Télécharger le rapport PDF",
                data=file,
                file_name=pdf_file,
                mime="application/octet-stream"
            )
    except Exception as e:
        st.error(f"Erreur lors de l'enregistrement du rapport en PDF: {e}")