From f84095fc20a327251090bf577a7c86ce88341f01 Mon Sep 17 00:00:00 2001 From: Etienne Chassaing <60154720+cetiennec@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:53:39 +0200 Subject: [PATCH] Corrected merge issues, fixes html pages --- main.py | 83 ++++++++++++++++++++++++++++++++++++++++++++--- static/index.html | 81 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 148 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 99423e6..333072a 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,10 @@ from fastapi import Request, APIRouter import subprocess import platform -from classCAN import CANBackend # Your real backend +if platform.system() in ['Darwin']: # macOS or Windows + from MockCAN import CANBackend +else : + from classCAN import CANBackend # Your real backend app = FastAPI() router = APIRouter() @@ -71,10 +74,72 @@ def get_monitor_data(): data = can_backend.get_latest_data() print(f"[MONITOR] Latest SDO: {data}") return { - "Qperm": [data.get("FM2", 0.0), data.get("FM2", 0.0), 0.0], - "Pdilute": [data.get("PS1", 0.0), 0.0, 0.0], - "Conductivity": [0.0, 0.0, 0.0], - "Pro": [0.0, 0.0, 0.0], + "PU_1": { + "Qperm": data.get("FM2", 0.0), + "Qdilute": data.get("FM3", 0.0), + "Qdrain": data.get("FM4", 0.0), + "Qrecirc": data.get("FM5", 0.0), + "Pro": data.get("PS1", 0.0), + "Pdilute": data.get("PS2", 0.0), + "Prentate": data.get("PS3", 0.0), + "Conductivity": data.get("Cond", 0.0), + "MV02": data.get("MV02", 0.0), + "MV02_sp": data.get("MV02_sp", 0.0), + "MV03": data.get("MV03", 0.0), + "MV03_sp": data.get("MV03_sp", 0.0), + "MV05": data.get("MV05", 0.0), + "MV05_sp": data.get("MV05_sp", 0.0), + "MV06": data.get("MV06", 0.0), + "MV06_sp": data.get("MV06_sp", 0.0), + "MV07": data.get("MV07", 0.0), + "MV07_sp": data.get("MV07_sp", 0.0), + "MV08": data.get("MV08", 0.0), + "MV08_sp": data.get("MV08_sp", 0.0) + }, + "PU_2": { + "Qperm": data.get("FM2", 0.0), + "Qdilute": data.get("FM3", 0.0), + "Qdrain": data.get("FM4", 0.0), + "Qrecirc": data.get("FM5", 0.0), + "Pro": data.get("PS1", 0.0), + "Pdilute": data.get("PS2", 0.0), + "Prentate": data.get("PS3", 0.0), + "Conductivity": data.get("Cond", 0.0), + "MV02": data.get("MV02", 0.0), + "MV02_sp": data.get("MV02_sp", 0.0), + "MV03": data.get("MV03", 0.0), + "MV03_sp": data.get("MV03_sp", 0.0), + "MV05": data.get("MV05", 0.0), + "MV05_sp": data.get("MV05_sp", 0.0), + "MV06": data.get("MV06", 0.0), + "MV06_sp": data.get("MV06_sp", 0.0), + "MV07": data.get("MV07", 0.0), + "MV07_sp": data.get("MV07_sp", 0.0), + "MV08": data.get("MV08", 0.0), + "MV08_sp": data.get("MV08_sp", 0.0) + }, + "PU_3": { + "Qperm": data.get("FM2", 0.0), + "Qdilute": data.get("FM3", 0.0), + "Qdrain": data.get("FM4", 0.0), + "Qrecirc": data.get("FM5", 0.0), + "Pro": data.get("PS1", 0.0), + "Pdilute": data.get("PS2", 0.0), + "Prentate": data.get("PS3", 0.0), + "Conductivity": data.get("Cond", 0.0), + "MV02": data.get("MV02", 0.0), + "MV02_sp": data.get("MV02_sp", 0.0), + "MV03": data.get("MV03", 0.0), + "MV03_sp": data.get("MV03_sp", 0.0), + "MV05": data.get("MV05", 0.0), + "MV05_sp": data.get("MV05_sp", 0.0), + "MV06": data.get("MV06", 0.0), + "MV06_sp": data.get("MV06_sp", 0.0), + "MV07": data.get("MV07", 0.0), + "MV07_sp": data.get("MV07_sp", 0.0), + "MV08": data.get("MV08", 0.0), + "MV08_sp": data.get("MV08_sp", 0.0) + } } @app.get("/can_status") @@ -88,6 +153,14 @@ async def read_root(): with open("static/index.html", "r") as file: return HTMLResponse(content=file.read(), status_code=200) + +@app.get("/monitor-page", response_class=HTMLResponse) +async def read_monitor_page(): + """Serve monitor HTML page.""" + with open("static/monitor.html", "r") as file: + return HTMLResponse(content=file.read(), status_code=200) + + app.include_router(router) if __name__ == "__main__": diff --git a/static/index.html b/static/index.html index d55e59f..107f1d0 100644 --- a/static/index.html +++ b/static/index.html @@ -210,9 +210,9 @@

Conductivity

-
#1
0.0 µS/cm
-
#2
0.0 µS/cm
-
#3
0.0 µS/cm
+
#1
0.0 µS/cm
+
#2
0.0 µS/cm
+
#3
0.0 µS/cm
@@ -269,14 +269,38 @@ } - async function updateMonitorData() { - const response = await fetch('/monitor'); - const data = await response.json(); - updateMonitorValues('Qperm', data.Qperm, 'L/h'); - updateMonitorValues('Pdilute', data.Pdilute, 'bar'); - updateMonitorValues('Conductivity', data.Conductivity, 'µS/cm'); - updateMonitorValues('Pro', data.Pro, 'units'); - } + + async function updateMonitorData() { + const response = await fetch('/monitor'); + const data = await response.json(); // data = { PU_1: {...}, PU_2: {...}, PU_3: {...} } + + for (const [puId, puData] of Object.entries(data)) { + const container = document.getElementById(puId); + if (!container) continue; + + container.innerHTML = ` +

${puId}

+
Q_perm
${puData.Qperm.toFixed(1)} L/h
+
Q_dilute
${puData.Qdilute.toFixed(1)} L/h
+
Q_drain
${puData.Qdrain.toFixed(1)} L/h
+
Q_recirc
${puData.Qrecirc.toFixed(1)} L/h
+ +
P_ro
${puData.Pro.toFixed(1)} bar
+
P_dilute
${puData.Pdilute.toFixed(1)} bar
+
P_rentate
${puData.Prentate.toFixed(1)} bar
+ +
Conductivity
${puData.Conductivity.toFixed(1)} µS/cm
+ +
MV02
${puData.MV02.toFixed(1)} % (sp: ${puData.MV02_sp.toFixed(1)})
+
MV03
${puData.MV03.toFixed(1)} % (sp: ${puData.MV03_sp.toFixed(1)})
+
MV05
${puData.MV05.toFixed(1)} % (sp: ${puData.MV05_sp.toFixed(1)})
+
MV06
${puData.MV06.toFixed(1)} % (sp: ${puData.MV06_sp.toFixed(1)})
+
MV07
${puData.MV07.toFixed(1)} % (sp: ${puData.MV07_sp.toFixed(1)})
+
MV08
${puData.MV08.toFixed(1)} % (sp: ${puData.MV08_sp.toFixed(1)})
+ `; + } + } + function updateMonitorValues(id, values, unit) { const container = document.getElementById(id); @@ -291,5 +315,40 @@ // Update monitor data every second setInterval(updateMonitorData, 1000); + + + +