120 lines
3.1 KiB
HTML
120 lines
3.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: 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 - DS</h1>
|
|
<div class="status-container">
|
|
<p>Current Status: <span id="currentStatus">Loading...</span></p>
|
|
</div>
|
|
<div class="plot-container">
|
|
<div id="tank-level-plot" class="large-plot"></div>
|
|
<div id="flow-plot" class="large-plot"></div>
|
|
</div>
|
|
<script>
|
|
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 dsData = allData['DS'];
|
|
const t = new Date(dsData.timestamp);
|
|
|
|
Plotly.extendTraces('tank-level-plot', {
|
|
x: [[t]],
|
|
y: [[dsData.TankLevel]]
|
|
}, [0], maxPoints);
|
|
|
|
Plotly.extendTraces('flow-plot', {
|
|
x: [[t], [t], [t]],
|
|
y: [[dsData.Qconso], [dsData.Qinlet], [dsData.Qoutlet]]
|
|
}, [0, 1, 2], maxPoints);
|
|
|
|
} catch (e) {
|
|
console.error("Error updating plots:", e);
|
|
}
|
|
}
|
|
|
|
async function fetchDSStatus() {
|
|
try {
|
|
const res = await fetch("/api/ds_status");
|
|
const data = await res.json();
|
|
const status = data['DS'] || "Unknown";
|
|
document.getElementById("currentStatus").textContent = status;
|
|
} catch (e) {
|
|
console.error("Error fetching DS status:", e);
|
|
document.getElementById("currentStatus").textContent = "Error fetching status";
|
|
}
|
|
}
|
|
|
|
function initPlots() {
|
|
const time0 = [new Date()];
|
|
|
|
Plotly.newPlot('tank-level-plot', [
|
|
{ x: time0, y: [0], name: 'Tank Level', mode: 'lines' }
|
|
], {
|
|
title: 'Tank Level',
|
|
xaxis: { type: 'date' },
|
|
yaxis: { title: 'Level' }
|
|
});
|
|
|
|
Plotly.newPlot('flow-plot', [
|
|
{ x: time0, y: [0], name: 'Qconso', mode: 'lines' },
|
|
{ x: time0, y: [0], name: 'Qinlet', mode: 'lines' },
|
|
{ x: time0, y: [0], name: 'Qoutlet', mode: 'lines' }
|
|
], {
|
|
title: 'Flow Measurements',
|
|
xaxis: { type: 'date' },
|
|
yaxis: { title: 'Flow (L/h)' }
|
|
});
|
|
|
|
setInterval(updatePlots, 500);
|
|
}
|
|
|
|
window.onload = function () {
|
|
initPlots();
|
|
fetchDSStatus();
|
|
setInterval(fetchDSStatus, 5000);
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|