NorthStar-HMI/static/monitor.html
2025-08-05 13:23:03 +02:00

255 lines
7.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<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>
body {
font-family: Arial, sans-serif;
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;
border-radius: 5px;
margin: 10px auto;
text-align: center;
font-size: 18px;
}
</style>
</head>
<body>
<h1 id="pageTitle">Live Monitoring Dashboard</h1>
<div class="status-container">
<p>Current Status: <span id="currentStatus">Loading...</span></p>
</div>
<div class="plot-container">
<div id="flow-plot-1" class="large-plot"></div>
<div id="pressure-plot-1" class="large-plot"></div>
<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="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-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}`;
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);
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('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('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('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";
}
}
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-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-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('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-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('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-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-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);
}
window.onload = function () {
initPlots();
fetchPUStatus();
setInterval(fetchPUStatus, 5000);
};
</script>
</body>
</html>