Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +17 -26
src/streamlit_app.py
CHANGED
|
@@ -2,27 +2,29 @@ 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
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
@st.cache_data(ttl=300)
|
| 18 |
def load_data():
|
| 19 |
-
|
| 20 |
-
return pd.
|
| 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)
|
|
@@ -31,38 +33,27 @@ try:
|
|
| 31 |
|
| 32 |
# --- GRAPHIQUE DES RÉGRESSIONS ---
|
| 33 |
fig = go.Figure()
|
| 34 |
-
x_range = np.linspace(40, 200, 100)
|
| 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
|
| 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 ---
|
|
@@ -84,6 +75,6 @@ try:
|
|
| 84 |
st.table(pd.DataFrame(recap_data))
|
| 85 |
|
| 86 |
except Exception as e:
|
| 87 |
-
st.error("
|
| 88 |
-
st.write("Vérifiez que votre
|
| 89 |
-
st.info(f"
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
import plotly.graph_objects as go
|
|
|
|
| 5 |
|
| 6 |
# Configuration de la page
|
| 7 |
st.set_page_config(page_title="Brake_Lab_Test", layout="wide")
|
| 8 |
st.title("🔬 Lab_test_visual : Analyse de Performance")
|
| 9 |
|
| 10 |
+
# --- PARAMÈTRES GOOGLE DRIVE (Lien direct CSV) ---
|
| 11 |
+
# Votre ID : 16tPsyYoe8O3LGM9FGOx5B-Je3S7ggVqUZPrs9XYDUHA
|
| 12 |
+
sheet_id = '16tPsyYoe8O3LGM9FGOx5B-Je3S7ggVqUZPrs9XYDUHA'
|
| 13 |
+
# On force l'export de l'onglet 'Data' en format CSV pour plus de simplicité
|
| 14 |
+
url = f'https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet=Data'
|
| 15 |
|
| 16 |
+
@st.cache_data(ttl=300)
|
| 17 |
def load_data():
|
| 18 |
+
# Connexion directe sans gdown
|
| 19 |
+
return pd.read_csv(url)
|
| 20 |
|
| 21 |
# --- CHARGEMENT ET INTERFACE ---
|
| 22 |
try:
|
| 23 |
df = load_data()
|
| 24 |
|
| 25 |
+
# Nettoyage des noms de colonnes (au cas où il y aurait des espaces)
|
| 26 |
+
df.columns = df.columns.str.strip()
|
| 27 |
+
|
| 28 |
# Barre latérale : Sélection de la valeur X (40 à 200)
|
| 29 |
st.sidebar.header("⚙️ Configuration")
|
| 30 |
x_input = st.sidebar.slider("Valeur cible (X)", 40, 200, 100)
|
|
|
|
| 33 |
|
| 34 |
# --- GRAPHIQUE DES RÉGRESSIONS ---
|
| 35 |
fig = go.Figure()
|
| 36 |
+
x_range = np.linspace(40, 200, 100)
|
| 37 |
|
|
|
|
| 38 |
colors = ['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3']
|
| 39 |
|
| 40 |
for i, (index, row) in enumerate(df.iterrows()):
|
| 41 |
color = colors[i % len(colors)]
|
| 42 |
model = row['model name']
|
| 43 |
|
| 44 |
+
# Calcul y = ax + b
|
| 45 |
y_dry = row['dry a'] * x_range + row['dry b']
|
| 46 |
y_wet = row['wet a'] * x_range + row['wet b']
|
| 47 |
|
|
|
|
| 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 |
fig.add_trace(go.Scatter(x=x_range, y=y_wet, mode='lines',
|
| 52 |
name=f"{model} (Wet)", line=dict(color=color, width=2, dash='dot')))
|
| 53 |
|
|
|
|
| 54 |
fig.add_vline(x=x_input, line_width=2, line_dash="dash", line_color="black")
|
| 55 |
|
| 56 |
+
fig.update_layout(height=600, xaxis_title="Entrée (X)", yaxis_title="Performance (Y)", hovermode="x unified")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
st.plotly_chart(fig, use_container_width=True)
|
| 58 |
|
| 59 |
# --- TABLEAU RÉCAPITULATIF ---
|
|
|
|
| 75 |
st.table(pd.DataFrame(recap_data))
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
+
st.error("⚠️ Impossible de lire l'onglet 'Data'.")
|
| 79 |
+
st.write("Vérifiez que votre Google Sheet possède bien un onglet nommé **Data** (avec une majuscule au D).")
|
| 80 |
+
st.info(f"Détail technique : {e}")
|