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.")
|
||||||
64
utils/db.py
Normal file
64
utils/db.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import mysql.connector
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
def verifier_utilisateur_commun(login, password):
|
||||||
|
conn = get_connection()
|
||||||
|
cursor = conn.cursor(dictionary=True)
|
||||||
|
|
||||||
|
query = """
|
||||||
|
SELECT NomUtilisateur FROM Commun.AccesUtilisateurs
|
||||||
|
WHERE NomUtilisateur = %s
|
||||||
|
AND MotDePasse = %s
|
||||||
|
AND (DateExpiration IS NULL OR DateExpiration >= CURDATE())
|
||||||
|
"""
|
||||||
|
cursor.execute(query, (login, password))
|
||||||
|
user = cursor.fetchone()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
return user # None si non trouvé
|
||||||
|
|
||||||
|
def get_connection():
|
||||||
|
return mysql.connector.connect(
|
||||||
|
host=os.getenv("DB_HOST"),
|
||||||
|
user=os.getenv("DB_USER"),
|
||||||
|
password=os.getenv("DB_PASSWORD"),
|
||||||
|
database=os.getenv("DB_NAME")
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_latest_chaufferie():
|
||||||
|
conn = get_connection()
|
||||||
|
cursor = conn.cursor(dictionary=True)
|
||||||
|
query = """
|
||||||
|
SELECT c1.Sonde, c1.Temperature, c1.Date, c1.Topic
|
||||||
|
FROM Chaufferie c1
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT Sonde, MAX(Date) AS MaxDate
|
||||||
|
FROM Chaufferie
|
||||||
|
GROUP BY Sonde
|
||||||
|
) c2 ON c1.Sonde = c2.Sonde AND c1.Date = c2.MaxDate
|
||||||
|
ORDER BY c1.Topic, c1.Sonde
|
||||||
|
"""
|
||||||
|
cursor.execute(query)
|
||||||
|
data = cursor.fetchall()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_history_by_sonde(sonde_name):
|
||||||
|
conn = get_connection()
|
||||||
|
cursor = conn.cursor(dictionary=True)
|
||||||
|
query = """
|
||||||
|
SELECT Date, Temperature
|
||||||
|
FROM Chaufferie
|
||||||
|
WHERE Sonde = %s AND Date >= NOW() - INTERVAL 1 DAY
|
||||||
|
ORDER BY Date ASC
|
||||||
|
"""
|
||||||
|
cursor.execute(query, (sonde_name,))
|
||||||
|
data = cursor.fetchall()
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
return data
|
||||||
|
|
||||||
Reference in New Issue
Block a user