Domo91.py vers.4

This commit is contained in:
2025-07-08 13:16:02 +02:00
parent 840b0725ea
commit 1df19a1917

View File

@@ -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()
@@ -174,7 +175,6 @@ if st.session_state["authenticated"]:
cursor.close()
conn.close()
except Exception as e:
st.error(f"Erreur : {e}")
st.text(traceback.format_exc())
@@ -182,6 +182,13 @@ if st.session_state["authenticated"]:
# --- 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,6 +231,58 @@ if st.session_state["authenticated"]:
except Exception as e:
st.error(f"Erreur chargement statistiques : {e}")
# 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"<div style='text-align:center;font-size:20px'>{temp_max}°C</div>",
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")
@@ -244,7 +303,6 @@ if st.session_state["authenticated"]:
cursor.close()
conn.close()
except Exception as e:
st.error(f"Erreur : {e}")
st.text(traceback.format_exc())
@@ -287,3 +345,4 @@ if st.session_state["authenticated"]:
except Exception as e:
st.error(f"Erreur : {e}")
st.text(traceback.format_exc())