Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +44 -25
src/streamlit_app.py
CHANGED
|
@@ -4,68 +4,87 @@ import numpy as np
|
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
import os
|
| 6 |
|
| 7 |
-
# Configuration
|
| 8 |
st.set_page_config(page_title="Brake_Lab_Test", layout="wide")
|
| 9 |
st.title("🔬 Lab_test_visual : Analyse de Performance")
|
| 10 |
|
| 11 |
-
# --- CHARGEMENT
|
| 12 |
@st.cache_data
|
| 13 |
def load_data():
|
| 14 |
-
#
|
| 15 |
current_dir = os.path.dirname(__file__)
|
| 16 |
file_path = os.path.join(current_dir, "Brake_Lab_Test_Data.xlsx")
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
try:
|
| 22 |
df = load_data()
|
| 23 |
-
# Nettoyage automatique des noms de colonnes
|
| 24 |
-
df.columns = df.columns.str.strip()
|
| 25 |
|
| 26 |
-
# Barre latérale
|
| 27 |
st.sidebar.header("⚙️ Configuration")
|
| 28 |
x_input = st.sidebar.slider("Valeur cible (X)", 40, 200, 100)
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
fig = go.Figure()
|
| 32 |
x_range = np.linspace(40, 200, 100)
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
for i, (index, row) in enumerate(df.iterrows()):
|
| 36 |
color = colors[i % len(colors)]
|
| 37 |
model = row['model name']
|
| 38 |
|
| 39 |
-
# Calcul y = ax + b
|
| 40 |
y_dry = row['dry a'] * x_range + row['dry b']
|
| 41 |
y_wet = row['wet a'] * x_range + row['wet b']
|
| 42 |
|
| 43 |
-
# Courbe
|
| 44 |
fig.add_trace(go.Scatter(x=x_range, y=y_dry, mode='lines',
|
| 45 |
name=f"{model} (Sec)", line=dict(color=color, width=3)))
|
| 46 |
-
|
|
|
|
| 47 |
fig.add_trace(go.Scatter(x=x_range, y=y_wet, mode='lines',
|
| 48 |
name=f"{model} (Wet)", line=dict(color=color, width=2, dash='dot')))
|
| 49 |
|
| 50 |
-
# Ligne
|
| 51 |
-
fig.add_vline(x=x_input, line_width=2, line_dash="dash", line_color="
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
st.plotly_chart(fig, use_container_width=True)
|
| 54 |
|
| 55 |
# --- TABLEAU RÉCAPITULATIF ---
|
| 56 |
-
st.subheader(f"📊
|
| 57 |
-
|
|
|
|
| 58 |
for index, row in df.iterrows():
|
| 59 |
val_dry = row['dry a'] * x_input + row['dry b']
|
| 60 |
val_wet = row['wet a'] * x_input + row['wet b']
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
"Modèle": row['model name'],
|
| 63 |
-
"Sec": round(val_dry, 3),
|
| 64 |
-
"Humide": round(val_wet, 3),
|
| 65 |
-
"
|
| 66 |
})
|
| 67 |
-
|
|
|
|
| 68 |
|
| 69 |
except Exception as e:
|
| 70 |
-
st.error(f"Erreur
|
| 71 |
-
st.
|
|
|
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
import os
|
| 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 |
+
# --- CHARGEMENT ---
|
| 12 |
@st.cache_data
|
| 13 |
def load_data():
|
| 14 |
+
# Détection du chemin du fichier dans le dossier /src
|
| 15 |
current_dir = os.path.dirname(__file__)
|
| 16 |
file_path = os.path.join(current_dir, "Brake_Lab_Test_Data.xlsx")
|
| 17 |
|
| 18 |
+
# On utilise 'Data' avec la majuscule ici
|
| 19 |
+
data = pd.read_excel(file_path, sheet_name='Data')
|
| 20 |
+
|
| 21 |
+
# Nettoyage des noms de colonnes (enlève les espaces avant/après)
|
| 22 |
+
data.columns = data.columns.str.strip()
|
| 23 |
+
return data
|
| 24 |
|
| 25 |
try:
|
| 26 |
df = load_data()
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Barre latérale pour le réglage X
|
| 29 |
st.sidebar.header("⚙️ Configuration")
|
| 30 |
x_input = st.sidebar.slider("Valeur cible (X)", 40, 200, 100)
|
| 31 |
|
| 32 |
+
st.info(f"Visualisation des régressions linéaires pour X entre 40 et 200")
|
| 33 |
+
|
| 34 |
+
# --- CRÉATION DU GRAPHIQUE ---
|
| 35 |
fig = go.Figure()
|
| 36 |
x_range = np.linspace(40, 200, 100)
|
| 37 |
+
|
| 38 |
+
# Palette de couleurs Decathlon / Sport
|
| 39 |
+
colors = ['#0082C3', '#E63312', '#333333', '#FFD200', '#00A14B']
|
| 40 |
|
| 41 |
for i, (index, row) in enumerate(df.iterrows()):
|
| 42 |
color = colors[i % len(colors)]
|
| 43 |
model = row['model name']
|
| 44 |
|
| 45 |
+
# Calcul des droites : y = ax + b
|
| 46 |
y_dry = row['dry a'] * x_range + row['dry b']
|
| 47 |
y_wet = row['wet a'] * x_range + row['wet b']
|
| 48 |
|
| 49 |
+
# Ajout Courbe SEC (Pleine)
|
| 50 |
fig.add_trace(go.Scatter(x=x_range, y=y_dry, mode='lines',
|
| 51 |
name=f"{model} (Sec)", line=dict(color=color, width=3)))
|
| 52 |
+
|
| 53 |
+
# Ajout Courbe HUMIDE (Pointillée)
|
| 54 |
fig.add_trace(go.Scatter(x=x_range, y=y_wet, mode='lines',
|
| 55 |
name=f"{model} (Wet)", line=dict(color=color, width=2, dash='dot')))
|
| 56 |
|
| 57 |
+
# Ligne verticale pour la valeur sélectionnée
|
| 58 |
+
fig.add_vline(x=x_input, line_width=2, line_dash="dash", line_color="red")
|
| 59 |
+
|
| 60 |
+
fig.update_layout(
|
| 61 |
+
height=600,
|
| 62 |
+
xaxis_title="Entrée (Pression/Vitesse)",
|
| 63 |
+
yaxis_title="Performance (Coefficient)",
|
| 64 |
+
legend_title="Modèles & Conditions",
|
| 65 |
+
hovermode="x unified"
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
st.plotly_chart(fig, use_container_width=True)
|
| 69 |
|
| 70 |
# --- TABLEAU RÉCAPITULATIF ---
|
| 71 |
+
st.subheader(f"📊 Performances au point X = {x_input}")
|
| 72 |
+
|
| 73 |
+
recap_data = []
|
| 74 |
for index, row in df.iterrows():
|
| 75 |
val_dry = row['dry a'] * x_input + row['dry b']
|
| 76 |
val_wet = row['wet a'] * x_input + row['wet b']
|
| 77 |
+
perte = ((val_dry - val_wet) / val_dry) * 100 if val_dry != 0 else 0
|
| 78 |
+
|
| 79 |
+
recap_data.append({
|
| 80 |
"Modèle": row['model name'],
|
| 81 |
+
"Résultat Sec": round(val_dry, 3),
|
| 82 |
+
"Résultat Humide": round(val_wet, 3),
|
| 83 |
+
"Perte d'efficacité": f"{round(perte, 1)}%"
|
| 84 |
})
|
| 85 |
+
|
| 86 |
+
st.table(pd.DataFrame(recap_data))
|
| 87 |
|
| 88 |
except Exception as e:
|
| 89 |
+
st.error(f"Erreur de lecture : {e}")
|
| 90 |
+
st.warning("Vérifiez que les colonnes 'model name', 'dry a', 'dry b', 'wet a', 'wet b' sont bien présentes dans l'onglet 'Data'.")
|