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:
from classCAN import CANBackend # Your real backend
logging.basicConfig(level=logging.INFO)
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("uvicorn.access").setLevel(logging.WARNING)
@ -392,6 +392,7 @@ async def auto_test_pu3():
# PATIENT SKID HELPERS
async def update_latest_flow():
global active_PUs
async with aiohttp.ClientSession() as session:
while True:
try:
@ -400,6 +401,9 @@ async def update_latest_flow():
latest_flow = int(data["log"]["flow"])
logging.debug(f"Updated flow: {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:
logging.error(f"Error fetching flow: {e}")

View File

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