import streamlit as st import pandas as pd import os import numpy as np # ============================================================================== # 1. STYLE CSS V2.4 (FORÇAGE BLANC TOTAL SUR COMPOSANTS NOIRS) # ============================================================================== st.set_page_config(page_title="Brake Lab V2.4", layout="centered") st.markdown(""" """, unsafe_allow_html=True) # ============================================================================== # 2. CHARGEMENT DES DONNÉES # ============================================================================== @st.cache_data def load_data(): current_dir = os.path.dirname(__file__) file_path = os.path.join(current_dir, "Brake_Lab_Test_Data.xlsx") if not os.path.exists(file_path): return pd.DataFrame() df = pd.read_excel(file_path, sheet_name='Data') df.columns = df.columns.str.strip() return df df = load_data() # ============================================================================== # 3. INTERFACE V2.4 # ============================================================================== if not df.empty: # --- BLOC 1 : DONNÉES D'USAGE --- with st.expander("📊 Données d'usage", expanded=False): c1, c2 = st.columns(2) with c1: effort_val = st.number_input("Effort Levier [N]", value=100, step=1) mass_total = st.number_input("Masse Totale (kg)", value=100, step=1) wheel_size = st.number_input("Roue [inch]", value=28, step=1) with c2: speed_kmh = st.number_input("Vitesse [km/h]", value=25, step=1) mass_ratio = st.number_input("Rapport masse AR [%]", value=70, step=1) # --- BLOC 2 : DONNÉES COMPOSANTS --- with st.expander("⚙️ Données composant", expanded=True): model_list = df['model name'].unique().tolist() col_comp1, col_comp2 = st.columns(2) with col_comp1: main_model = st.selectbox("Système étudié", options=model_list) with col_comp2: comp_options = ["Aucun"] + model_list compare_model = st.selectbox("Système de comparaison", options=comp_options) # --- CALCULS --- row = df[df['model name'] == main_model].iloc[0] res_dry = row['dry a'] * effort_val + row['dry b'] res_wet = row['wet a'] * effort_val + row['wet b'] res_dry_c, res_wet_c = None, None if compare_model != "Aucun": row_c = df[df['model name'] == compare_model].iloc[0] res_dry_c = row_c['dry a'] * effort_val + row_c['dry b'] res_wet_c = row_c['wet a'] * effort_val + row_c['wet b'] # --- AFFICHAGE --- st.write("") res_c1, res_c2 = st.columns(2) def get_comp_html(val_main, val_comp): if val_comp is None: return "" diff_pct = ((val_main - val_comp) / val_comp) * 100 color_class = "comp-pos" if diff_pct >= 0 else "comp-neg" sign = "+" if diff_pct >= 0 else "" return f'

{sign}{round(diff_pct, 1)}% vs comp

' with res_c1: st.markdown(f"""

CONDITION : SEC

{round(res_dry, 1)} N

{get_comp_html(res_dry, res_dry_c)}
""", unsafe_allow_html=True) with res_c2: st.markdown(f"""

CONDITION : HUMIDE

{round(res_wet, 1)} N

{get_comp_html(res_wet, res_wet_c)}
""", unsafe_allow_html=True) else: st.error("Erreur : Fichier Excel manquant.")