diff --git a/domo91.py b/domo91.py index 3ec8497..61f3fc8 100644 --- a/domo91.py +++ b/domo91.py @@ -32,7 +32,6 @@ db_config = { "database": os.getenv("DB_NAME") } - # --- Fonction de génération PDF --- def generer_pdf(site, date_str): st.info(f"Génération du rapport PDF pour {site} à la date {date_str}") @@ -124,7 +123,7 @@ if "lieu_autorise" not in st.session_state: st.session_state["lieu_autorise"] = None # --- Connexion utilisateur dans la sidebar --- -st.sidebar.header("🔐 Connexion") + st.sidebar.header("🔐 Connexion") if not st.session_state.get("authenticated"): login = st.sidebar.text_input("Nom d'utilisateur") password = st.sidebar.text_input("Mot de passe", type="password") @@ -271,10 +270,10 @@ if st.session_state["authenticated"]: # --- NAVIGATION --- if st.session_state["role"] == "superviseur": - onglet = st.sidebar.radio("📁 Navigation", ["Accueil", "Statistiques"]) + onglet = st.sidebar.radio("📁 Navigation", ["Accueil", "Statistiques", "Traffic"]) +# --- ONGLET ACCUEIL --- else: - onglet = "Accueil" - + onglet = "Accueil" if onglet == "Accueil": st.markdown("## Sélection du site et de la date") try: @@ -354,7 +353,7 @@ if st.session_state["authenticated"]: except Exception as e: st.error(f"Erreur MySQL : {e}") - +# ---- ONGLET STATISTIQUES --- elif onglet == "Statistiques": st.markdown("## 📈 Statistiques de température") try: @@ -486,5 +485,25 @@ if st.session_state["authenticated"]: except Exception as e: st.error(f"Erreur SQL (admin) : {e}") - except exception as err: - st.error(f"Erreur MySQL : {err}") +# --- ONGLET TRAFFIC ------ + elif onglet == "Traffic": + st.markdown("## 🚦 Connexions récentes") + try: + conn = mysql.connector.connect(**db_config) + cursor = conn.cursor(dictionary=True) + cursor.execute( + "SELECT Utilisateur, Lieu, Date_Connexion FROM Connexion_Log ORDER BY Date_Connexion DESC LIMIT 200") + connexions = cursor.fetchall() + cursor.close() + conn.close() + + if connexions: + df_connexions = pd.DataFrame(connexions) + st.dataframe(df_connexions, use_container_width=True) + else: + st.info("Aucune connexion enregistrée.") + except Exception as e: + st.error(f"Erreur chargement des connexions : {e}") + + except exception as err: + st.error(f"Erreur MySQL : {err}")