Soufianesejjari commited on
Commit
a7651d7
·
1 Parent(s): 54f91c5
Files changed (2) hide show
  1. app.py +89 -35
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import pandas as pd
 
3
 
4
  # Initialiser l'état de la session
5
  if 'phases' not in st.session_state:
@@ -8,36 +9,29 @@ if 'phases' not in st.session_state:
8
  # Titre
9
  st.title('Gestion des erreurs de mélange de béton')
10
 
11
-
12
-
13
-
14
-
15
-
16
-
17
- st.header('Entrées les norme de calcul')
18
- g1_norme = st.number_input('G1 norme',value=575.0 ,format="%.2f")
19
- g2_norme= st.number_input('G2 norme',value=1000.0 ,format="%.2f")
20
- sb_norme= st.number_input('SB norme',value=1237.0 ,format="%.2f")
21
- cube_norme= st.number_input('Cube norme',value=1.5 ,format="%.2f")
22
 
23
  # Section d'entrée pour la phase
24
  st.header('Entrées pour la phase')
25
- g1_input = st.number_input('G1',format="%.2f")
26
-
27
- g2_input = st.number_input('G2',format="%.2f")
28
- sb_input = st.number_input('SB', format="%.2f")
29
  cubes_input = st.number_input('Cubes', value=1.5, format="%.2f")
30
 
31
  # Ajouter la phase
32
  if st.button('Ajouter la phase'):
33
  phase_data = {
34
- 'G1': g1_input,
35
  'G2': g2_input,
 
36
  'SB': sb_input,
37
  'Cubes': cubes_input,
38
- 'G1_Error': g1_input- (g1_norme/cube_norme * cubes_input) ,
39
- 'G2_Error': (g2_input - g1_input)-(g2_norme/cube_norme * cubes_input) ,
40
- 'SB_Error': (sb_input - g2_input)-(sb_norme /cube_norme* cubes_input) ,
41
  }
42
  st.session_state['phases'].append(phase_data)
43
 
@@ -49,12 +43,12 @@ st.write(phases_df)
49
  # Calculer les erreurs totales
50
  st.header('Calcul des erreurs')
51
  try:
52
- total_g1_error = phases_df['G1_Error'].sum()
53
  total_g2_error = phases_df['G2_Error'].sum()
 
54
  total_sb_error = phases_df['SB_Error'].sum()
55
 
56
- st.write(f"Erreur totale G1: {total_g1_error}")
57
  st.write(f"Erreur totale G2: {total_g2_error}")
 
58
  st.write(f"Erreur totale SB: {total_sb_error}")
59
  except KeyError as e:
60
  st.error(f"Erreur dans les données: {e}")
@@ -62,17 +56,20 @@ except KeyError as e:
62
  # Correction des erreurs en fonction des cubes restants
63
  st.header('Correction des erreurs')
64
  remaining_cubes = st.number_input('Cubes restants', value=1.0, format="%.2f")
65
- if st.button('Corriger les erreurs'):
 
66
  try:
67
- correction_g1 = g1_norme/cube_norme *remaining_cubes - total_g1_error
68
- correction_g2 = g2_norme/cube_norme *remaining_cubes - total_g2_error
69
- correction_sb = sb_norme/cube_norme *remaining_cubes - total_sb_error
70
 
71
- st.write(f"Correction G1 par cube: {correction_g1}")
72
  st.write(f"Correction G2 par cube: {correction_g2}")
 
73
  st.write(f"Correction SB par cube: {correction_sb}")
74
  except ZeroDivisionError:
75
  st.error("Le nombre de cubes restants doit être supérieur à zéro pour corriger les erreurs.")
 
 
76
 
77
  # Générer un rapport détaillé des erreurs
78
  st.header('Rapport détaillé des erreurs')
@@ -81,13 +78,13 @@ if st.button('Générer le rapport'):
81
  report = f"""
82
  ## Rapport détaillé des erreurs
83
  ### Erreurs totales
84
- - Erreur G1: {total_g1_error}
85
  - Erreur G2: {total_g2_error}
 
86
  - Erreur SB: {total_sb_error}
87
 
88
  ### Correction nécessaire
89
- - G1 par cube: {correction_g1}
90
  - G2 par cube: {correction_g2}
 
91
  - SB par cube: {correction_sb}
92
 
93
  ### Phases
@@ -97,12 +94,69 @@ if st.button('Générer le rapport'):
97
  except Exception as e:
98
  st.error(f"Erreur lors de la génération du rapport: {e}")
99
 
100
- # Enregistrer le rapport
101
- st.header('Enregistrer le rapport')
102
- if st.button('Enregistrer le rapport'):
103
  try:
104
- with open("rapport_erreurs.txt", "w") as file:
105
- file.write(report)
106
- st.write('Rapport enregistré sous le nom rapport_erreurs.txt')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  except Exception as e:
108
- st.error(f"Erreur lors de l'enregistrement du rapport: {e}")
 
1
  import streamlit as st
2
  import pandas as pd
3
+ from fpdf import FPDF
4
 
5
  # Initialiser l'état de la session
6
  if 'phases' not in st.session_state:
 
9
  # Titre
10
  st.title('Gestion des erreurs de mélange de béton')
11
 
12
+ st.header('Entrées les normes de calcul')
13
+ g2_norme = st.number_input('G2 norme', value=575.0, format="%.2f")
14
+ g1_norme = st.number_input('G1 norme', value=1000.0, format="%.2f")
15
+ sb_norme = st.number_input('SB norme', value=1237.0, format="%.2f")
16
+ cube_norme = st.number_input('Cube norme', value=1.5, format="%.2f")
 
 
 
 
 
 
17
 
18
  # Section d'entrée pour la phase
19
  st.header('Entrées pour la phase')
20
+ g2_input = st.number_input('G2', format="%.2f")
21
+ g1_input = st.number_input('G1', format="%.2f")
22
+ sb_input = st.number_input('SB', format="%.2f")
 
23
  cubes_input = st.number_input('Cubes', value=1.5, format="%.2f")
24
 
25
  # Ajouter la phase
26
  if st.button('Ajouter la phase'):
27
  phase_data = {
 
28
  'G2': g2_input,
29
+ 'G1': g1_input,
30
  'SB': sb_input,
31
  'Cubes': cubes_input,
32
+ 'G2_Error': g2_input - (g2_norme / cube_norme * cubes_input),
33
+ 'G1_Error': (g1_input - g2_input) - (g1_norme / cube_norme * cubes_input),
34
+ 'SB_Error': (sb_input - g1_input) - (sb_norme / cube_norme * cubes_input),
35
  }
36
  st.session_state['phases'].append(phase_data)
37
 
 
43
  # Calculer les erreurs totales
44
  st.header('Calcul des erreurs')
45
  try:
 
46
  total_g2_error = phases_df['G2_Error'].sum()
47
+ total_g1_error = phases_df['G1_Error'].sum()
48
  total_sb_error = phases_df['SB_Error'].sum()
49
 
 
50
  st.write(f"Erreur totale G2: {total_g2_error}")
51
+ st.write(f"Erreur totale G1: {total_g1_error}")
52
  st.write(f"Erreur totale SB: {total_sb_error}")
53
  except KeyError as e:
54
  st.error(f"Erreur dans les données: {e}")
 
56
  # Correction des erreurs en fonction des cubes restants
57
  st.header('Correction des erreurs')
58
  remaining_cubes = st.number_input('Cubes restants', value=1.0, format="%.2f")
59
+
60
+ if st.button('Corriger les erreurs') or remaining_cubes > 0:
61
  try:
62
+ correction_g2 = g2_norme / cube_norme * remaining_cubes - total_g2_error
63
+ correction_g1 = g1_norme / cube_norme * remaining_cubes - total_g1_error
64
+ correction_sb = sb_norme / cube_norme * remaining_cubes - total_sb_error
65
 
 
66
  st.write(f"Correction G2 par cube: {correction_g2}")
67
+ st.write(f"Correction G1 par cube: {correction_g1}")
68
  st.write(f"Correction SB par cube: {correction_sb}")
69
  except ZeroDivisionError:
70
  st.error("Le nombre de cubes restants doit être supérieur à zéro pour corriger les erreurs.")
71
+ else:
72
+ correction_g2 = correction_g1 = correction_sb = 0
73
 
74
  # Générer un rapport détaillé des erreurs
75
  st.header('Rapport détaillé des erreurs')
 
78
  report = f"""
79
  ## Rapport détaillé des erreurs
80
  ### Erreurs totales
 
81
  - Erreur G2: {total_g2_error}
82
+ - Erreur G1: {total_g1_error}
83
  - Erreur SB: {total_sb_error}
84
 
85
  ### Correction nécessaire
 
86
  - G2 par cube: {correction_g2}
87
+ - G1 par cube: {correction_g1}
88
  - SB par cube: {correction_sb}
89
 
90
  ### Phases
 
94
  except Exception as e:
95
  st.error(f"Erreur lors de la génération du rapport: {e}")
96
 
97
+ # Enregistrer le rapport en PDF
98
+ st.header('Enregistrer le rapport en PDF')
99
+ if st.button('Enregistrer le rapport en PDF'):
100
  try:
101
+ class PDF(FPDF):
102
+ def header(self):
103
+ self.set_font('Arial', 'B', 12)
104
+ self.cell(0, 10, 'Rapport détaillé des erreurs de mélange de béton', 0, 1, 'C')
105
+ self.ln(10)
106
+
107
+ def chapter_title(self, title):
108
+ self.set_font('Arial', 'B', 12)
109
+ self.cell(0, 10, title, 0, 1, 'L')
110
+ self.ln(5)
111
+
112
+ def chapter_body(self, body):
113
+ self.set_font('Arial', '', 12)
114
+ self.multi_cell(0, 10, body)
115
+ self.ln()
116
+
117
+ def add_phase_table(self, df):
118
+ self.set_font('Arial', 'B', 10)
119
+ col_width = self.w / (len(df.columns) + 1) # Largeur des colonnes
120
+ th = self.font_size
121
+
122
+ # Header
123
+ for column in df.columns:
124
+ self.cell(col_width, th, column, border=1)
125
+ self.ln(th)
126
+
127
+ # Data
128
+ self.set_font('Arial', '', 10)
129
+ for i in range(len(df)):
130
+ self.cell(col_width, th, str(df.iloc[i]['G2']), border=1)
131
+ self.cell(col_width, th, str(df.iloc[i]['G1']), border=1)
132
+ self.cell(col_width, th, str(df.iloc[i]['SB']), border=1)
133
+ self.cell(col_width, th, str(df.iloc[i]['Cubes']), border=1)
134
+ self.cell(col_width, th, str(df.iloc[i]['G2_Error']), border=1)
135
+ self.cell(col_width, th, str(df.iloc[i]['G1_Error']), border=1)
136
+ self.cell(col_width, th, str(df.iloc[i]['SB_Error']), border=1)
137
+ self.ln(th)
138
+
139
+ pdf = PDF()
140
+ pdf.add_page()
141
+
142
+ pdf.chapter_title("Erreurs totales")
143
+ pdf.chapter_body(f"Erreur G2: {total_g2_error}\nErreur G1: {total_g1_error}\nErreur SB: {total_sb_error}")
144
+
145
+ pdf.chapter_title("Correction nécessaire")
146
+ pdf.chapter_body(f"G2 par cube: {correction_g2}\nG1 par cube: {correction_g1}\nSB par cube: {correction_sb}")
147
+
148
+ pdf.chapter_title("Phases")
149
+ pdf.add_phase_table(phases_df)
150
+
151
+ pdf_file = "rapport_erreurs.pdf"
152
+ pdf.output(pdf_file)
153
+ st.write('Rapport PDF enregistré sous le nom rapport_erreurs.pdf')
154
+ with open(pdf_file, "rb") as file:
155
+ st.download_button(
156
+ label="Télécharger le rapport PDF",
157
+ data=file,
158
+ file_name=pdf_file,
159
+ mime="application/octet-stream"
160
+ )
161
  except Exception as e:
162
+ st.error(f"Erreur lors de l'enregistrement du rapport en PDF: {e}")
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fpdf2