Merge branch 'develop' into product
mo91.py Vers5"
This commit is contained in:
28
domo91.py
28
domo91.py
@@ -16,6 +16,9 @@ load_dotenv()
|
||||
|
||||
st.set_page_config(page_title="Domo91 - Surveillance", layout="wide")
|
||||
|
||||
st.title("📊 Domo91 - Surveillance des sondes")
|
||||
st.write("Bienvenue sur l’application de supervision.")
|
||||
|
||||
# Initialisation session state avec valeurs sûres
|
||||
for key, default in {
|
||||
"authenticated": False,
|
||||
@@ -28,8 +31,6 @@ for key, default in {
|
||||
}.items():
|
||||
st.session_state.setdefault(key, default)
|
||||
|
||||
st.title("📡 Supervision Températures")
|
||||
|
||||
# Configuration MySQL
|
||||
db_config = {
|
||||
"host": os.getenv("DB_HOST"),
|
||||
@@ -96,11 +97,16 @@ else:
|
||||
|
||||
# --- Navigation ---
|
||||
if st.session_state["authenticated"]:
|
||||
onglets = ["Accueil", "Entretien"] if st.session_state["role"] != "superviseur" else ["Accueil", "Statistiques", "Entretien", "Traffic", "Utilisateurs"]
|
||||
onglet_selectionne = st.sidebar.radio("📁 Navigation", onglets, index=onglets.index(st.session_state["onglet_actif"]))
|
||||
onglets = ["Accueil", "Entretien"] if st.session_state["role"] != "superviseur" else ["Accueil", "Statistiques",
|
||||
"Entretien", "Traffic",
|
||||
"Utilisateurs"]
|
||||
onglet_selectionne = st.sidebar.radio("📁 Navigation", onglets,
|
||||
index=onglets.index(st.session_state["onglet_actif"]))
|
||||
st.session_state["onglet_actif"] = onglet_selectionne
|
||||
|
||||
site_actuel = st.session_state.get("lieu_autorise") if st.session_state["role"] != "superviseur" else st.session_state.get("selected_site", "Saclay")
|
||||
site_actuel = st.session_state.get("lieu_autorise") if st.session_state[
|
||||
"role"] != "superviseur" else st.session_state.get(
|
||||
"selected_site", "Saclay")
|
||||
date_selectionnee = st.session_state.get("selected_date", date.today())
|
||||
periode_selectionnee = st.session_state.get("selected_periode", "Toute la journée")
|
||||
|
||||
@@ -131,7 +137,8 @@ if st.session_state["authenticated"]:
|
||||
df_sonde = df[df["Sonde"] == sonde_choisie].copy()
|
||||
df_sonde["Heure"] = df_sonde["Date"].dt.hour
|
||||
|
||||
tranche = st.radio("🕒 Tranche horaire :", ["Toute la journée", "Matin (6h-12h)", "Après-midi (12h-18h)", "Nuit (18h-6h)"])
|
||||
tranche = st.radio("🕒 Tranche horaire :",
|
||||
["Toute la journée", "Matin (6h-12h)", "Après-midi (12h-18h)", "Nuit (18h-6h)"])
|
||||
st.session_state["selected_periode"] = tranche
|
||||
|
||||
if tranche == "Matin (6h-12h)":
|
||||
@@ -150,6 +157,7 @@ if st.session_state["authenticated"]:
|
||||
|
||||
st.subheader("📊 Tableau des relevés")
|
||||
|
||||
|
||||
def surlignage_temp(val):
|
||||
try:
|
||||
if float(val) > seuil_temp:
|
||||
@@ -158,6 +166,7 @@ if st.session_state["authenticated"]:
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
styled_df = df_sonde.style.applymap(surlignage_temp, subset=["Temperature"])
|
||||
st.dataframe(styled_df, use_container_width=True)
|
||||
|
||||
@@ -313,7 +322,8 @@ if st.session_state["authenticated"]:
|
||||
try:
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("SELECT Utilisateur, Lieu, Date_Connexion FROM Connexion_Log ORDER BY Date_Connexion DESC LIMIT 100")
|
||||
cursor.execute(
|
||||
"SELECT Utilisateur, Lieu, Date_Connexion FROM Connexion_Log ORDER BY Date_Connexion DESC LIMIT 100")
|
||||
logs = cursor.fetchall()
|
||||
df_logs = pd.DataFrame(logs)
|
||||
st.dataframe(df_logs)
|
||||
@@ -336,7 +346,8 @@ if st.session_state["authenticated"]:
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
hash_mdp = hash_password(new_pass)
|
||||
cursor.execute("INSERT INTO MotsDePasse (utilisateur, mot_de_passe, role, Lieu) VALUES (%s, %s, %s, %s)",
|
||||
cursor.execute(
|
||||
"INSERT INTO MotsDePasse (utilisateur, mot_de_passe, role, Lieu) VALUES (%s, %s, %s, %s)",
|
||||
(new_user, hash_mdp, new_role, new_lieu))
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
@@ -345,4 +356,3 @@ if st.session_state["authenticated"]:
|
||||
except Exception as e:
|
||||
st.error(f"Erreur : {e}")
|
||||
st.text(traceback.format_exc())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user