Ajout fichiers sur develop
This commit is contained in:
74
Technique.py
Normal file
74
Technique.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import streamlit as st
|
||||
import pandas as pd
|
||||
from utils.db import get_latest_chaufferie, get_history_by_sonde, verifier_utilisateur_commun
|
||||
|
||||
st.set_page_config(page_title="Tech Chaufferie", layout="wide")
|
||||
|
||||
def login_commun():
|
||||
login = st.text_input("Identifiant", type="default")
|
||||
password = st.text_input("Mot de passe", type="password")
|
||||
|
||||
if st.button("Se connecter"):
|
||||
user = verifier_utilisateur_commun(login, password)
|
||||
if user:
|
||||
st.session_state["authenticated"] = True
|
||||
st.session_state["utilisateur"] = user["NomUtilisateur"]
|
||||
st.success("✅ Connexion réussie")
|
||||
st.rerun()
|
||||
else:
|
||||
st.error("❌ Identifiants incorrects ou expirés")
|
||||
|
||||
# Authentification
|
||||
if "authenticated" not in st.session_state:
|
||||
st.session_state["authenticated"] = False
|
||||
|
||||
if not st.session_state["authenticated"]:
|
||||
st.title("🔧 Suivi des sondes de la chaufferie")
|
||||
st.subheader("🔐 Connexion technicien chaufferie")
|
||||
login_commun()
|
||||
st.stop()
|
||||
with st.sidebar:
|
||||
st.markdown(f"👤 Connecté en tant que **{st.session_state['utilisateur']}**")
|
||||
if st.button("🔓 Se déconnecter"):
|
||||
st.session_state.clear()
|
||||
st.rerun()
|
||||
# --- Affichage principal ---
|
||||
st.title("🔧 Suivi des sondes de la chaufferie")
|
||||
|
||||
data = get_latest_chaufferie()
|
||||
df = pd.DataFrame(data)
|
||||
|
||||
# Ajout d'un statut couleur
|
||||
def statut(temp):
|
||||
if temp > 75:
|
||||
return "❌ Très chaud"
|
||||
elif temp > 60:
|
||||
return "⚠️ Surveiller"
|
||||
else:
|
||||
return "✅ OK"
|
||||
|
||||
df["Statut"] = df["Temperature"].apply(statut)
|
||||
|
||||
# Séparer par topic
|
||||
for topic in df["Topic"].unique():
|
||||
st.subheader(f"Zone : {topic}")
|
||||
st.dataframe(df[df["Topic"] == topic][["Sonde", "Temperature", "Date", "Statut"]], use_container_width=True)
|
||||
|
||||
# Graphique historique
|
||||
st.markdown("---")
|
||||
st.header("📈 Historique par sonde (24h)")
|
||||
|
||||
sonde_selection = st.selectbox("Choisir une sonde à afficher", df["Sonde"].unique())
|
||||
|
||||
if sonde_selection:
|
||||
historique = get_history_by_sonde(sonde_selection)
|
||||
if historique:
|
||||
df_hist = pd.DataFrame(historique)
|
||||
df_hist["Date"] = pd.to_datetime(df_hist["Date"])
|
||||
|
||||
st.line_chart(
|
||||
df_hist.set_index("Date")["Temperature"],
|
||||
use_container_width=True
|
||||
)
|
||||
else:
|
||||
st.info("Aucune donnée disponible pour cette sonde dans les dernières 24h.")
|
||||
Reference in New Issue
Block a user