NorthStar-HMI/static/monitor.html

185 lines
6.1 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: 22%;
height: 200px;
}
h1 {
text-align: center;
}
#puSelector {
display: block;
margin: 10px auto 20px auto;
font-size: 16px;
padding: 5px 10px;
}
</style>
</head>
<body>
<h1>Live Monitoring Dashboard</h1>
<label for="puSelector" style="text-align:center; display:block;">Select PU:</label>
<select id="puSelector">
<option value="1">PU 1</option>
<option value="2">PU 2</option>
<option value="3">PU 3</option>
</select>
<div class="plot-container">
<div id="flow-plot" class="large-plot"></div>
<div id="pressure-plot" class="large-plot"></div>
<div id="mv02-plot" class="small-plot"></div>
<div id="mv03-plot" class="small-plot"></div>
<div id="mv04-05-plot" class="small-plot"></div>
<div id="mv06-plot" class="small-plot"></div>
<div id="mv07-plot" class="small-plot"></div>
<div id="mv08-plot" class="small-plot"></div>
</div>
<script>
const maxPoints = 100;
const time = () => new Date();
let selectedPU = 1;
document.getElementById("puSelector").addEventListener("change", function () {
selectedPU = parseInt(this.value);
});
function getLastMinuteRange() {
const now = new Date();
const oneMinuteAgo = new Date(now.getTime() - 60 * 1000);
return [oneMinuteAgo, now];
}
async function updatePlots() {
try {
const response = await fetch(`/monitor?pu_number=${selectedPU}`);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const pu = await response.json(); // <- Directly using it
const t = time();
Plotly.extendTraces('flow-plot', {
x: [[t], [t], [t], [t]],
y: [[pu.Qperm], [pu.Qdilute], [pu.Qdrain], [pu.Qrecirc]]
}, [0, 1, 2, 3], maxPoints);
Plotly.extendTraces('pressure-plot', {
x: [[t], [t], [t]],
y: [[pu.Pro], [pu.Pdilute], [pu.Prentate]]
}, [0, 1, 2], maxPoints);
Plotly.extendTraces('mv02-plot', { x: [[t]], y: [[pu.MV02]] }, [0]);
Plotly.extendTraces('mv03-plot', { x: [[t]], y: [[pu.MV03]] }, [0]);
Plotly.extendTraces('mv04-05-plot', {
x: [[t], [t]],
y: [[pu.MV04], [pu.MV05]]
}, [0, 1]);
Plotly.extendTraces('mv06-plot', { x: [[t]], y: [[pu.MV06]] }, [0]);
Plotly.extendTraces('mv07-plot', { x: [[t]], y: [[pu.MV07]] }, [0]);
Plotly.extendTraces('mv08-plot', { x: [[t]], y: [[pu.MV08]] }, [0]);
const range = getLastMinuteRange();
const plotIds = [
'flow-plot', 'pressure-plot', 'mv02-plot', 'mv03-plot',
'mv04-05-plot', 'mv06-plot', 'mv07-plot', 'mv08-plot'
];
plotIds.forEach(id => {
Plotly.relayout(id, { 'xaxis.range': range });
});
} catch (error) {
console.error("Error updating plots:", error);
}
}
function initPlots() {
const time0 = [time()];
Plotly.newPlot('flow-plot', [
{ x: time0, y: [0], name: 'Qperm', mode: 'lines', line: { color: 'blue' } },
{ x: time0, y: [0], name: 'Qdilute', mode: 'lines', line: { color: 'green' } },
{ x: time0, y: [0], name: 'Qdrain', mode: 'lines', line: { color: 'red' } },
{ x: time0, y: [0], name: 'Qrecirc', mode: 'lines', line: { color: 'orange' } }
], {
title: 'Flow Rates Over Time',
xaxis: { title: 'Time', type: 'date' },
yaxis: { title: 'Flow (L/h)', range: [0, 2000] }
});
Plotly.newPlot('pressure-plot', [
{ x: time0, y: [0], name: 'Pro', mode: 'lines', line: { color: 'purple' } },
{ x: time0, y: [0], name: 'Pdilute', mode: 'lines', line: { color: 'teal' } },
{ x: time0, y: [0], name: 'Prentate', mode: 'lines', line: { color: 'gray' } }
], {
title: 'Pressure Over Time',
xaxis: { title: 'Time', type: 'date' },
yaxis: { title: 'Pressure (bar)', range: [0, 15] }
});
Plotly.newPlot('mv02-plot', [{
x: time0, y: [0], name: 'MV02', mode: 'lines'
}], {
title: 'MV02 (%)', yaxis: { range: [0, 100] }, xaxis: { type: 'date' }
});
Plotly.newPlot('mv03-plot', [{
x: time0, y: [0], name: 'MV03', mode: 'lines'
}], {
title: 'MV03 (%)', yaxis: { range: [0, 100] }, xaxis: { type: 'date' }
});
Plotly.newPlot('mv04-05-plot', [
{ x: time0, y: [0], name: 'MV04', mode: 'lines' },
{ x: time0, y: [0], name: 'MV05', mode: 'lines' }
], {
title: 'MV04 + MV05 (%)', yaxis: { range: [0, 100] }, xaxis: { type: 'date' }
});
Plotly.newPlot('mv06-plot', [{
x: time0, y: [0], name: 'MV06', mode: 'lines'
}], {
title: 'MV06 (%)', yaxis: { range: [0, 100] }, xaxis: { type: 'date' }
});
Plotly.newPlot('mv07-plot', [{
x: time0, y: [0], name: 'MV07', mode: 'lines'
}], {
title: 'MV07 (%)', yaxis: { range: [0, 100] }, xaxis: { type: 'date' }
});
Plotly.newPlot('mv08-plot', [{
x: time0, y: [0], name: 'MV08', mode: 'lines'
}], {
title: 'MV08 (%)', yaxis: { range: [0, 100] }, xaxis: { type: 'date' }
});
setInterval(updatePlots, 1000);
}
window.onload = initPlots;
</script>
</body>
</html>