MaxBDKT commited on
Commit
23d5a62
·
verified ·
1 Parent(s): b3928fe

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +87 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,89 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import plotly.graph_objects as go
5
+ import gdown
6
+
7
+ # Configuration de la page
8
+ st.set_page_config(page_title="Brake_Lab_Test", layout="wide")
9
+ st.title("🔬 Lab_test_visual : Analyse de Performance")
10
+
11
+ # --- PARAMÈTRES GOOGLE DRIVE ---
12
+ # ID extrait de votre lien : 16tPsyYoe8O3LGM9FGOx5B-Je3S7ggVqUZPrs9XYDUHA
13
+ file_id = '16tPsyYoe8O3LGM9FGOx5B-Je3S7ggVqUZPrs9XYDUHA'
14
+ url = f'https://drive.google.com/uc?id={file_id}'
15
+ output = 'Brake_Lab_Test_Data.xlsx'
16
+
17
+ @st.cache_data(ttl=300) # Recharge les données toutes les 5 minutes
18
+ def load_data():
19
+ gdown.download(url, output, quiet=True)
20
+ return pd.read_excel(output, sheet_name='Data')
21
+
22
+ # --- CHARGEMENT ET INTERFACE ---
23
+ try:
24
+ df = load_data()
25
+
26
+ # Barre latérale : Sélection de la valeur X (40 à 200)
27
+ st.sidebar.header("⚙️ Configuration")
28
+ x_input = st.sidebar.slider("Valeur cible (X)", 40, 200, 100)
29
+
30
+ st.write(f"Comparaison des modèles pour une valeur d'entrée de **{x_input}**")
31
+
32
+ # --- GRAPHIQUE DES RÉGRESSIONS ---
33
+ fig = go.Figure()
34
+ x_range = np.linspace(40, 200, 100) # Plage de 40 à 200
35
+
36
+ # Couleurs pour différencier les modèles
37
+ colors = ['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3']
38
+
39
+ for i, (index, row) in enumerate(df.iterrows()):
40
+ color = colors[i % len(colors)]
41
+ model = row['model name']
42
+
43
+ # Calcul des droites y = ax + b
44
+ y_dry = row['dry a'] * x_range + row['dry b']
45
+ y_wet = row['wet a'] * x_range + row['wet b']
46
+
47
+ # Ajout Courbe SEC (Pleine)
48
+ fig.add_trace(go.Scatter(x=x_range, y=y_dry, mode='lines',
49
+ name=f"{model} (Sec)", line=dict(color=color, width=3)))
50
+
51
+ # Ajout Courbe HUMIDE (Pointillée)
52
+ fig.add_trace(go.Scatter(x=x_range, y=y_wet, mode='lines',
53
+ name=f"{model} (Wet)", line=dict(color=color, width=2, dash='dot')))
54
+
55
+ # Ligne verticale de l'entrée sélectionnée
56
+ fig.add_vline(x=x_input, line_width=2, line_dash="dash", line_color="black")
57
+
58
+ fig.update_layout(
59
+ height=600,
60
+ xaxis_title="Entrée (X)",
61
+ yaxis_title="Performance (Y)",
62
+ legend_title="Modèles",
63
+ hovermode="x unified"
64
+ )
65
+
66
+ st.plotly_chart(fig, use_container_width=True)
67
+
68
+ # --- TABLEAU RÉCAPITULATIF ---
69
+ st.subheader(f"📊 Performances calculées à X = {x_input}")
70
+
71
+ recap_data = []
72
+ for index, row in df.iterrows():
73
+ val_dry = row['dry a'] * x_input + row['dry b']
74
+ val_wet = row['wet a'] * x_input + row['wet b']
75
+ perte = ((val_dry - val_wet) / val_dry) * 100 if val_dry != 0 else 0
76
+
77
+ recap_data.append({
78
+ "Modèle": row['model name'],
79
+ "Résultat Sec": round(val_dry, 2),
80
+ "Résultat Humide": round(val_wet, 2),
81
+ "Perte d'efficacité (%)": f"{round(perte, 1)}%"
82
+ })
83
+
84
+ st.table(pd.DataFrame(recap_data))
85
 
86
+ except Exception as e:
87
+ st.error("Erreur de connexion aux données.")
88
+ st.write("Vérifiez que votre fichier Excel sur Drive a bien un onglet nommé 'Data' et les colonnes : 'model name', 'dry a', 'dry b', 'wet a', 'wet b'.")
89
+ st.info(f"Détails : {e}")