From 1df19a191781a5ad35858351d830a3eec569ffe5 Mon Sep 17 00:00:00 2001 From: Michel Date: Tue, 8 Jul 2025 13:16:02 +0200 Subject: [PATCH] Domo91.py vers.4 --- domo91.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/domo91.py b/domo91.py index c8854bf..28a1379 100644 --- a/domo91.py +++ b/domo91.py @@ -9,6 +9,7 @@ from dotenv import load_dotenv from datetime import datetime, date import bcrypt import traceback +import random # Charger les variables d'environnement load_dotenv() @@ -103,7 +104,7 @@ if st.session_state["authenticated"]: date_selectionnee = st.session_state.get("selected_date", date.today()) periode_selectionnee = st.session_state.get("selected_periode", "Toute la journée") -# --- Onglet Accueil --- + # --- Onglet Accueil --- if onglet_selectionne == "Accueil": try: conn = get_connection() @@ -174,14 +175,20 @@ if st.session_state["authenticated"]: cursor.close() conn.close() - except Exception as e: st.error(f"Erreur : {e}") st.text(traceback.format_exc()) -# --- Onglet Statistiques --- - elif onglet_selectionne == "Statistiques": + # --- Onglet Statistiques --- + elif onglet_selectionne == "Statistiques": st.markdown("## 📈 Statistiques de température") + site = ( + st.session_state["lieu_autorise"] + if st.session_state["role"] != "superviseur" + else st.session_state.get("selected_site", "Saclay") + ) + date_val = st.session_state.get("selected_date", date.today()) + try: conn = mysql.connector.connect(**db_config) cursor = conn.cursor(dictionary=True) @@ -224,7 +231,59 @@ if st.session_state["authenticated"]: except Exception as e: st.error(f"Erreur chargement statistiques : {e}") -# --- Onglet Entretien --- + # Tableau consignes chambres froides + if st.session_state["role"] == "superviseur": + with st.expander("🛠️ Gestion des chambres froides (administrateur)", expanded=True): + if st.button("🔄 Actualiser la liste"): + st.session_state["refresh_admin"] = random.randint(0, 9999) + + try: + conn_admin = mysql.connector.connect(**db_config) + cursor_admin = conn_admin.cursor(dictionary=True) + cursor_admin.execute("SELECT * FROM Chambres_froides WHERE Lieu = %s", (site,)) + chambres = cursor_admin.fetchall() + + if not chambres: + st.warning("Aucune chambre froide pour ce site.") + else: + for chambre in chambres: + col1, col2, col3 = st.columns([3, 1, 2]) + with col1: + st.markdown(f"**{chambre['Sonde']}**") + + with col2: + etat = st.checkbox("ON", value=(chambre["Etat"] == "ON"), + key=f"etat_{chambre['Id']}_{st.session_state.get('refresh_admin', 0)}") + new_etat = "ON" if etat else "OFF" + + with col3: + temp_max = chambre["Temp_Max"] + moins, temp_display, plus = st.columns([1, 2, 1]) + with moins: + if st.button("▼", key=f"moins_{chambre['Id']}"): + temp_max -= 1 + with temp_display: + st.markdown(f"
{temp_max}°C
", + unsafe_allow_html=True) + with plus: + if st.button("▲", key=f"plus_{chambre['Id']}"): + temp_max += 1 + + if new_etat != chambre["Etat"] or temp_max != chambre["Temp_Max"]: + cursor_admin.execute( + "UPDATE Chambres_froides SET Etat = %s, Temp_Max = %s WHERE Id = %s", + (new_etat, temp_max, chambre["Id"]) + ) + conn_admin.commit() + st.success(f"{chambre['Sonde']} mise à jour") + + cursor_admin.close() + conn_admin.close() + + except Exception as e: + st.error(f"Erreur SQL (admin) : {e}") + + # --- Onglet Entretien --- elif onglet_selectionne == "Entretien": st.header("🧰 Gestion Entretien") try: @@ -244,12 +303,11 @@ if st.session_state["authenticated"]: cursor.close() conn.close() - except Exception as e: st.error(f"Erreur : {e}") st.text(traceback.format_exc()) -# --- Onglet Traffic --- + # --- Onglet Traffic --- elif onglet_selectionne == "Traffic": st.header("🚦 Connexions récentes") try: @@ -287,3 +345,4 @@ if st.session_state["authenticated"]: except Exception as e: st.error(f"Erreur : {e}") st.text(traceback.format_exc()) +