updates to html page

This commit is contained in:
aniketSaha 2025-08-05 13:23:03 +02:00
parent 79b9f2d95d
commit efd44dbf3e
2 changed files with 178 additions and 166 deletions

View File

@ -31,7 +31,7 @@ if platform.system() in ["Darwin"]: # macOS or Windows
else: else:
from classCAN import CANBackend # Your real backend from classCAN import CANBackend # Your real backend
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG)
logging.getLogger("uvicorn.access").setLevel(logging.WARNING) logging.getLogger("uvicorn.access").setLevel(logging.WARNING)
@ -392,6 +392,7 @@ async def auto_test_pu3():
# PATIENT SKID HELPERS # PATIENT SKID HELPERS
async def update_latest_flow(): async def update_latest_flow():
global active_PUs
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
while True: while True:
try: try:
@ -400,6 +401,9 @@ async def update_latest_flow():
latest_flow = int(data["log"]["flow"]) latest_flow = int(data["log"]["flow"])
logging.debug(f"Updated flow: {latest_flow}") logging.debug(f"Updated flow: {latest_flow}")
latest_data["PatientSkid"]["QSkid"] = latest_flow latest_data["PatientSkid"]["QSkid"] = latest_flow
# for index in active_PUs :
# logging.debug("PU_"+str(index))
# latest_data["PU_"+str(index)]["QSkid"] = latest_flow # Adding the data to all actives PUs
except Exception as e: except Exception as e:
logging.error(f"Error fetching flow: {e}") logging.error(f"Error fetching flow: {e}")

View File

@ -1,8 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Live Monitoring Dashboard</title> <title>Live Monitoring Dashboard</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style> <style>
@ -11,23 +12,28 @@
margin: 0; margin: 0;
padding: 20px; padding: 20px;
} }
.plot-container { .plot-container {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: center; justify-content: center;
gap: 20px; gap: 20px;
} }
.large-plot { .large-plot {
width: 45%; width: 45%;
height: 300px; height: 300px;
} }
.small-plot { .small-plot {
width: 30%; width: 30%;
height: 250px; height: 250px;
} }
h1 { h1 {
text-align: center; text-align: center;
} }
.status-container { .status-container {
background-color: #f0f0f0; background-color: #f0f0f0;
padding: 10px; padding: 10px;
@ -38,6 +44,7 @@
} }
</style> </style>
</head> </head>
<body> <body>
<h1 id="pageTitle">Live Monitoring Dashboard</h1> <h1 id="pageTitle">Live Monitoring Dashboard</h1>
<div class="status-container"> <div class="status-container">
@ -50,198 +57,199 @@
<div id="flow-plot-2" class="large-plot"></div> <div id="flow-plot-2" class="large-plot"></div>
<div id="pressure-plot-2" class="large-plot"></div> <div id="pressure-plot-2" class="large-plot"></div>
<div id="conductivity-plot" class="large-plot"></div> <div id="conductivity-plot" class="large-plot"></div>
<div id="MV02_sp-plot" class="small-plot"></div> <div id="MV07-plot" class="small-plot"></div>
<div id="MV03_sp-plot" class="small-plot"></div> <div id="MV02-plot" class="small-plot"></div>
<div id="MV03-plot" class="small-plot"></div>
<div id="MV04_sp-05-plot" class="small-plot"></div> <div id="MV04_sp-05-plot" class="small-plot"></div>
<div id="MV06_sp-plot" class="small-plot"></div> <div id="MV06-plot" class="small-plot"></div>
<div id="MV07_sp-plot" class="small-plot"></div> <div id="MV08-plot" class="small-plot"></div>
<div id="MV08_sp-plot" class="small-plot"></div>
</div> </div>
<script> <script>
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const puNumber = urlParams.get('pu_number') || '1'; const puNumber = urlParams.get('pu_number') || '1';
document.getElementById('pageTitle').textContent = `Live Monitoring Dashboard - PU ${puNumber}`; document.getElementById('pageTitle').textContent = `Live Monitoring Dashboard - PU ${puNumber}`;
const maxPoints = 100; const maxPoints = 50;
async function updatePlots() { async function updatePlots() {
try { try {
const response = await fetch('/monitor'); const response = await fetch('/monitor');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const allData = await response.json(); const allData = await response.json();
const puData = allData[`PU_${puNumber}`]; const puData = allData[`PU_${puNumber}`];
const SkidData = allData[`PatientSkid`]; const SkidData = allData[`PatientSkid`];
const t = new Date(puData.timestamp); const t = new Date(puData.timestamp);
Plotly.extendTraces('flow-plot-1', { Plotly.extendTraces('flow-plot-1', {
x: [[t], [t]], x: [[t], [t]],
y: [[puData.Qperm], [puData.Qdilute]] y: [[puData.Qperm], [puData.Qdilute]]
}, [0, 1], maxPoints); }, [0, 1], maxPoints);
Plotly.extendTraces('flow-plot-2', { Plotly.extendTraces('flow-plot-2', {
x: [[t], [t], [t], [t]], x: [[t], [t], [t], [t]],
y: [[puData.Qdrain], [puData.Qrecirc], [SkidData.QSkid], [puData.QdrainEDI]] y: [[puData.Qdrain], [puData.Qrecirc], [SkidData.QSkid], [puData.QdrainEDI]]
}, [0, 1, 2, 3], maxPoints); }, [0, 1, 2, 3], maxPoints);
Plotly.extendTraces('pressure-plot-1', { Plotly.extendTraces('pressure-plot-1', {
x: [[t], [t]], x: [[t], [t]],
y: [[puData.Pro], [puData.Pretentate]] y: [[puData.Pro], [puData.Pretentate]]
}, [0, 1], maxPoints); }, [0, 1], maxPoints);
Plotly.extendTraces('pressure-plot-2', { Plotly.extendTraces('pressure-plot-2', {
x: [[t]], x: [[t]],
y: [[puData.Pdilute]] y: [[puData.Pdilute]]
}, [0], maxPoints); }, [0], maxPoints);
Plotly.extendTraces('conductivity-plot', { Plotly.extendTraces('conductivity-plot', {
x: [[t], [t], [t]], x: [[t], [t], [t]],
y: [[puData.Cfeed], [puData.Cperm], [puData.Cdilute]] y: [[puData.Cfeed], [puData.Cperm], [puData.Cdilute]]
}, [0, 1, 2], maxPoints); }, [0, 1, 2], maxPoints);
Plotly.extendTraces('MV07-plot', {
x: [[t], [t]],
y: [[puData.MV07_sp], [puData.MV07]]
}, [0, 1], maxPoints);
Plotly.extendTraces('MV02-plot', {
x: [[t], [t]],
y: [[puData.MV02_sp], [puData.MV02]]
}, [0, 1], maxPoints);
Plotly.extendTraces('MV03-plot', {
x: [[t], [t]],
y: [[puData.MV03_sp], [puData.MV03]]
}, [0, 1], maxPoints);
Plotly.extendTraces('MV04_sp-05-plot', {
x: [[t], [t], [t], [t]],
y: [[puData.MV04_sp], [puData.MV04], [puData.MV05_sp], [puData.MV05]]
}, [0, 1, 2, 3], maxPoints);
Plotly.extendTraces('MV06-plot', {
x: [[t], [t]],
y: [[puData.MV06_sp], [puData.MV06]]
}, [0, 1], maxPoints);
Plotly.extendTraces('MV02_sp-plot', { Plotly.extendTraces('MV08-plot', {
x: [[t], [t]], x: [[t], [t]],
y: [[puData.MV02_sp], [puData.MV02]] y: [[puData.MV08_sp], [puData.MV08]]
}, [0, 1], maxPoints); }, [0, 1], maxPoints);
} catch (e) {
Plotly.extendTraces('MV03_sp-plot', { console.error("Error updating plots:", e);
x: [[t], [t]], }
y: [[puData.MV03_sp], [puData.MV03]]
}, [0, 1], maxPoints);
Plotly.extendTraces('MV04_sp-05-plot', {
x: [[t], [t], [t], [t]],
y: [[puData.MV04_sp], [puData.MV04], [puData.MV05_sp], [puData.MV05]]
}, [0, 1, 2, 3], maxPoints);
Plotly.extendTraces('MV06_sp-plot', {
x: [[t], [t]],
y: [[puData.MV06_sp], [puData.MV06]]
}, [0, 1], maxPoints);
Plotly.extendTraces('MV07_sp-plot', {
x: [[t], [t]],
y: [[puData.MV07_sp], [puData.MV07]]
}, [0, 1], maxPoints);
Plotly.extendTraces('MV08_sp-plot', {
x: [[t], [t]],
y: [[puData.MV08_sp], [puData.MV08]]
}, [0, 1], maxPoints);
} catch (e) {
console.error("Error updating plots:", e);
} }
}
async function fetchPUStatus() { async function fetchPUStatus() {
try { try {
const res = await fetch("/api/pu_status"); const res = await fetch("/api/pu_status");
const data = await res.json(); const data = await res.json();
const status = data[`PU${puNumber}`] || "Unknown"; const status = data[`PU${puNumber}`] || "Unknown";
document.getElementById("currentStatus").textContent = status; document.getElementById("currentStatus").textContent = status;
} catch (e) { } catch (e) {
console.error("Error fetching PU status:", e); console.error("Error fetching PU status:", e);
document.getElementById("currentStatus").textContent = "Error fetching status"; document.getElementById("currentStatus").textContent = "Error fetching status";
}
} }
}
function initPlots() { function initPlots() {
const time0 = [new Date()]; const time0 = [new Date()];
Plotly.newPlot('flow-plot-1', [ Plotly.newPlot('flow-plot-1', [
{ x: time0, y: [0], name: 'Qperm', mode: 'lines' }, { x: time0, y: [0], name: 'Qperm', mode: 'lines' },
{ x: time0, y: [0], name: 'Qdilute', mode: 'lines' } { x: time0, y: [0], name: 'Qdilute', mode: 'lines' }
], { ], {
title: 'Qperm and Qdilute', title: 'Qperm and Qdilute',
xaxis: { type: 'date' }, yaxis: { title: 'Flow (L/h)' } xaxis: { type: 'date' }, yaxis: { title: 'Flow (L/h)' }
}); });
Plotly.newPlot('flow-plot-2', [ Plotly.newPlot('flow-plot-2', [
{ x: time0, y: [0], name: 'Qdrain', mode: 'lines' }, { x: time0, y: [0], name: 'Qdrain', mode: 'lines' },
{ x: time0, y: [0], name: 'Qrecirc', mode: 'lines' }, { x: time0, y: [0], name: 'Qrecirc', mode: 'lines' },
{ x: time0, y: [0], name: 'QSkid', mode: 'lines' }, { x: time0, y: [0], name: 'QSkid', mode: 'lines' },
{ x: time0, y: [0], name: 'QdrainEDI', mode: 'lines' } { x: time0, y: [0], name: 'QdrainEDI', mode: 'lines' }
], { ], {
title: 'Other Flows', xaxis: { type: 'date' }, yaxis: { title: 'Flow (L/h)' } title: 'Other Flows', xaxis: { type: 'date' }, yaxis: { title: 'Flow (L/h)' }
}); });
Plotly.newPlot('pressure-plot-1', [ Plotly.newPlot('pressure-plot-1', [
{ x: time0, y: [0], name: 'Pro', mode: 'lines' }, { x: time0, y: [0], name: 'Pro', mode: 'lines' },
{ x: time0, y: [0], name: 'Pretentate', mode: 'lines' } { x: time0, y: [0], name: 'Pretentate', mode: 'lines' }
], { ], {
title: 'Pro and Pretentate ', xaxis: { type: 'date' }, yaxis: { title: 'Pressure (bar)' } title: 'Pro and Pretentate ', xaxis: { type: 'date' }, yaxis: { title: 'Pressure (bar)' }
}); });
Plotly.newPlot('pressure-plot-2', [ Plotly.newPlot('pressure-plot-2', [
{ x: time0, y: [0], name: 'Pdilute', mode: 'lines' } { x: time0, y: [0], name: 'Pdilute', mode: 'lines' }
], { ], {
title: 'Pdilute Pressure', xaxis: { type: 'date' }, yaxis: { title: 'Pressure (bar)' } title: 'Pdilute Pressure', xaxis: { type: 'date' }, yaxis: { title: 'Pressure (bar)' }
}); });
Plotly.newPlot('conductivity-plot', [ Plotly.newPlot('conductivity-plot', [
{ x: time0, y: [0], name: 'Cfeed', mode: 'lines' }, { x: time0, y: [0], name: 'Cfeed', mode: 'lines' },
{ x: time0, y: [0], name: 'Cperm', mode: 'lines' }, { x: time0, y: [0], name: 'Cperm', mode: 'lines' },
{ x: time0, y: [0], name: 'Cdilute', mode: 'lines' } { x: time0, y: [0], name: 'Cdilute', mode: 'lines' }
], { ], {
title: 'Conductivity Measurements', title: 'Conductivity Measurements',
xaxis: { type: 'date' }, xaxis: { type: 'date' },
yaxis: { title: 'Conductivity (µS/cm)' } yaxis: { title: 'Conductivity (µS/cm)' }
}); });
Plotly.newPlot('MV02_sp-plot', [ Plotly.newPlot('MV02-plot', [
{ x: time0, y: [0], name: 'MV02_sp', mode: 'lines' }, { x: time0, y: [0], name: 'MV02_sp', mode: 'lines' },
{ x: time0, y: [0], name: 'MV02', mode: 'lines' } { x: time0, y: [0], name: 'MV02', mode: 'lines' }
], { ], {
title: 'MV02: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: { range: [0, 100] } title: 'MV02: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: {}
}); });
Plotly.newPlot('MV03_sp-plot', [ Plotly.newPlot('MV03-plot', [
{ x: time0, y: [0], name: 'MV03_sp', mode: 'lines' }, { x: time0, y: [0], name: 'MV03_sp', mode: 'lines' },
{ x: time0, y: [0], name: 'MV03', mode: 'lines' } { x: time0, y: [0], name: 'MV03', mode: 'lines' }
], { ], {
title: 'MV03: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: { range: [0, 100] } title: 'MV03: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: {}
}); });
Plotly.newPlot('MV04_sp-05-plot', [ Plotly.newPlot('MV04_sp-05-plot', [
{ x: time0, y: [0], name: 'MV04_sp', mode: 'lines' }, { x: time0, y: [0], name: 'MV04_sp', mode: 'lines' },
{ x: time0, y: [0], name: 'MV04', mode: 'lines' }, { x: time0, y: [0], name: 'MV04', mode: 'lines' },
{ x: time0, y: [0], name: 'MV05_sp', mode: 'lines' }, { x: time0, y: [0], name: 'MV05_sp', mode: 'lines' },
{ x: time0, y: [0], name: 'MV05', mode: 'lines' } { x: time0, y: [0], name: 'MV05', mode: 'lines' }
], { ], {
title: 'MV04 & MV05: Setpoints and Actuals', xaxis: { type: 'date' }, yaxis: { range: [0, 100] } title: 'MV04 & MV05: Setpoints and Actuals', xaxis: { type: 'date' }, yaxis: { range: [0, 100] }
}); });
Plotly.newPlot('MV06_sp-plot', [ Plotly.newPlot('MV06-plot', [
{ x: time0, y: [0], name: 'MV06_sp', mode: 'lines' }, { x: time0, y: [0], name: 'MV06_sp', mode: 'lines' },
{ x: time0, y: [0], name: 'MV06', mode: 'lines' } { x: time0, y: [0], name: 'MV06', mode: 'lines' }
], { ], {
title: 'MV06: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: { range: [0, 100] } title: 'MV06: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: {}
}); });
Plotly.newPlot('MV07_sp-plot', [ Plotly.newPlot('MV07-plot', [
{ x: time0, y: [0], name: 'MV07_sp', mode: 'lines' }, { x: time0, y: [0], name: 'MV07_sp', mode: 'lines' },
{ x: time0, y: [0], name: 'MV07', mode: 'lines' } { x: time0, y: [0], name: 'MV07', mode: 'lines' }
], { ], {
title: 'MV07: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: { range: [0, 100] } title: 'MV07: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: {}
}); });
Plotly.newPlot('MV08_sp-plot', [ Plotly.newPlot('MV08-plot', [
{ x: time0, y: [0], name: 'MV08_sp', mode: 'lines' }, { x: time0, y: [0], name: 'MV08_sp', mode: 'lines' },
{ x: time0, y: [0], name: 'MV08', mode: 'lines' } { x: time0, y: [0], name: 'MV08', mode: 'lines' }
], { ], {
title: 'MV08: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: { range: [0, 100] } title: 'MV08: Setpoint vs Actual', xaxis: { type: 'date' }, yaxis: { range: [0, 100] }
}); });
setInterval(updatePlots, 500); setInterval(updatePlots, 500);
} }
window.onload = function() { window.onload = function () {
initPlots(); initPlots();
fetchPUStatus(); fetchPUStatus();
setInterval(fetchPUStatus, 5000); setInterval(fetchPUStatus, 5000);
}; };
</script> </script>
</body> </body>
</html> </html>