Corrected merge issues, fixes html pages
This commit is contained in:
parent
d8e044f59c
commit
f84095fc20
81
main.py
81
main.py
|
|
@ -7,6 +7,9 @@ from fastapi import Request, APIRouter
|
||||||
import subprocess
|
import subprocess
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
|
if platform.system() in ['Darwin']: # macOS or Windows
|
||||||
|
from MockCAN import CANBackend
|
||||||
|
else :
|
||||||
from classCAN import CANBackend # Your real backend
|
from classCAN import CANBackend # Your real backend
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
@ -71,10 +74,72 @@ def get_monitor_data():
|
||||||
data = can_backend.get_latest_data()
|
data = can_backend.get_latest_data()
|
||||||
print(f"[MONITOR] Latest SDO: {data}")
|
print(f"[MONITOR] Latest SDO: {data}")
|
||||||
return {
|
return {
|
||||||
"Qperm": [data.get("FM2", 0.0), data.get("FM2", 0.0), 0.0],
|
"PU_1": {
|
||||||
"Pdilute": [data.get("PS1", 0.0), 0.0, 0.0],
|
"Qperm": data.get("FM2", 0.0),
|
||||||
"Conductivity": [0.0, 0.0, 0.0],
|
"Qdilute": data.get("FM3", 0.0),
|
||||||
"Pro": [0.0, 0.0, 0.0],
|
"Qdrain": data.get("FM4", 0.0),
|
||||||
|
"Qrecirc": data.get("FM5", 0.0),
|
||||||
|
"Pro": data.get("PS1", 0.0),
|
||||||
|
"Pdilute": data.get("PS2", 0.0),
|
||||||
|
"Prentate": data.get("PS3", 0.0),
|
||||||
|
"Conductivity": data.get("Cond", 0.0),
|
||||||
|
"MV02": data.get("MV02", 0.0),
|
||||||
|
"MV02_sp": data.get("MV02_sp", 0.0),
|
||||||
|
"MV03": data.get("MV03", 0.0),
|
||||||
|
"MV03_sp": data.get("MV03_sp", 0.0),
|
||||||
|
"MV05": data.get("MV05", 0.0),
|
||||||
|
"MV05_sp": data.get("MV05_sp", 0.0),
|
||||||
|
"MV06": data.get("MV06", 0.0),
|
||||||
|
"MV06_sp": data.get("MV06_sp", 0.0),
|
||||||
|
"MV07": data.get("MV07", 0.0),
|
||||||
|
"MV07_sp": data.get("MV07_sp", 0.0),
|
||||||
|
"MV08": data.get("MV08", 0.0),
|
||||||
|
"MV08_sp": data.get("MV08_sp", 0.0)
|
||||||
|
},
|
||||||
|
"PU_2": {
|
||||||
|
"Qperm": data.get("FM2", 0.0),
|
||||||
|
"Qdilute": data.get("FM3", 0.0),
|
||||||
|
"Qdrain": data.get("FM4", 0.0),
|
||||||
|
"Qrecirc": data.get("FM5", 0.0),
|
||||||
|
"Pro": data.get("PS1", 0.0),
|
||||||
|
"Pdilute": data.get("PS2", 0.0),
|
||||||
|
"Prentate": data.get("PS3", 0.0),
|
||||||
|
"Conductivity": data.get("Cond", 0.0),
|
||||||
|
"MV02": data.get("MV02", 0.0),
|
||||||
|
"MV02_sp": data.get("MV02_sp", 0.0),
|
||||||
|
"MV03": data.get("MV03", 0.0),
|
||||||
|
"MV03_sp": data.get("MV03_sp", 0.0),
|
||||||
|
"MV05": data.get("MV05", 0.0),
|
||||||
|
"MV05_sp": data.get("MV05_sp", 0.0),
|
||||||
|
"MV06": data.get("MV06", 0.0),
|
||||||
|
"MV06_sp": data.get("MV06_sp", 0.0),
|
||||||
|
"MV07": data.get("MV07", 0.0),
|
||||||
|
"MV07_sp": data.get("MV07_sp", 0.0),
|
||||||
|
"MV08": data.get("MV08", 0.0),
|
||||||
|
"MV08_sp": data.get("MV08_sp", 0.0)
|
||||||
|
},
|
||||||
|
"PU_3": {
|
||||||
|
"Qperm": data.get("FM2", 0.0),
|
||||||
|
"Qdilute": data.get("FM3", 0.0),
|
||||||
|
"Qdrain": data.get("FM4", 0.0),
|
||||||
|
"Qrecirc": data.get("FM5", 0.0),
|
||||||
|
"Pro": data.get("PS1", 0.0),
|
||||||
|
"Pdilute": data.get("PS2", 0.0),
|
||||||
|
"Prentate": data.get("PS3", 0.0),
|
||||||
|
"Conductivity": data.get("Cond", 0.0),
|
||||||
|
"MV02": data.get("MV02", 0.0),
|
||||||
|
"MV02_sp": data.get("MV02_sp", 0.0),
|
||||||
|
"MV03": data.get("MV03", 0.0),
|
||||||
|
"MV03_sp": data.get("MV03_sp", 0.0),
|
||||||
|
"MV05": data.get("MV05", 0.0),
|
||||||
|
"MV05_sp": data.get("MV05_sp", 0.0),
|
||||||
|
"MV06": data.get("MV06", 0.0),
|
||||||
|
"MV06_sp": data.get("MV06_sp", 0.0),
|
||||||
|
"MV07": data.get("MV07", 0.0),
|
||||||
|
"MV07_sp": data.get("MV07_sp", 0.0),
|
||||||
|
"MV08": data.get("MV08", 0.0),
|
||||||
|
"MV08_sp": data.get("MV08_sp", 0.0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@app.get("/can_status")
|
@app.get("/can_status")
|
||||||
|
|
@ -88,6 +153,14 @@ async def read_root():
|
||||||
with open("static/index.html", "r") as file:
|
with open("static/index.html", "r") as file:
|
||||||
return HTMLResponse(content=file.read(), status_code=200)
|
return HTMLResponse(content=file.read(), status_code=200)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/monitor-page", response_class=HTMLResponse)
|
||||||
|
async def read_monitor_page():
|
||||||
|
"""Serve monitor HTML page."""
|
||||||
|
with open("static/monitor.html", "r") as file:
|
||||||
|
return HTMLResponse(content=file.read(), status_code=200)
|
||||||
|
|
||||||
|
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -210,9 +210,9 @@
|
||||||
<div class="monitor-block">
|
<div class="monitor-block">
|
||||||
<h2><i class="fas fa-bolt"></i> Conductivity</h2>
|
<h2><i class="fas fa-bolt"></i> Conductivity</h2>
|
||||||
<div class="monitor-values" id="Conductivity">
|
<div class="monitor-values" id="Conductivity">
|
||||||
<div class="monitor-value">#1<br>0.0 µS/cm</div>
|
<div class="monitor-value">#1<br>0.0 µS/cm</div>
|
||||||
<div class="monitor-value">#2<br>0.0 µS/cm</div>
|
<div class="monitor-value">#2<br>0.0 µS/cm</div>
|
||||||
<div class="monitor-value">#3<br>0.0 µS/cm</div>
|
<div class="monitor-value">#3<br>0.0 µS/cm</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="monitor-block">
|
<div class="monitor-block">
|
||||||
|
|
@ -269,14 +269,38 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function updateMonitorData() {
|
async function updateMonitorData() {
|
||||||
const response = await fetch('/monitor');
|
const response = await fetch('/monitor');
|
||||||
const data = await response.json();
|
const data = await response.json(); // data = { PU_1: {...}, PU_2: {...}, PU_3: {...} }
|
||||||
updateMonitorValues('Qperm', data.Qperm, 'L/h');
|
|
||||||
updateMonitorValues('Pdilute', data.Pdilute, 'bar');
|
for (const [puId, puData] of Object.entries(data)) {
|
||||||
updateMonitorValues('Conductivity', data.Conductivity, 'µS/cm');
|
const container = document.getElementById(puId);
|
||||||
updateMonitorValues('Pro', data.Pro, 'units');
|
if (!container) continue;
|
||||||
|
|
||||||
|
container.innerHTML = `
|
||||||
|
<h3>${puId}</h3>
|
||||||
|
<div class="monitor-value">Q_perm<br>${puData.Qperm.toFixed(1)} L/h</div>
|
||||||
|
<div class="monitor-value">Q_dilute<br>${puData.Qdilute.toFixed(1)} L/h</div>
|
||||||
|
<div class="monitor-value">Q_drain<br>${puData.Qdrain.toFixed(1)} L/h</div>
|
||||||
|
<div class="monitor-value">Q_recirc<br>${puData.Qrecirc.toFixed(1)} L/h</div>
|
||||||
|
|
||||||
|
<div class="monitor-value">P_ro<br>${puData.Pro.toFixed(1)} bar</div>
|
||||||
|
<div class="monitor-value">P_dilute<br>${puData.Pdilute.toFixed(1)} bar</div>
|
||||||
|
<div class="monitor-value">P_rentate<br>${puData.Prentate.toFixed(1)} bar</div>
|
||||||
|
|
||||||
|
<div class="monitor-value">Conductivity<br>${puData.Conductivity.toFixed(1)} µS/cm</div>
|
||||||
|
|
||||||
|
<div class="monitor-value">MV02<br>${puData.MV02.toFixed(1)} % (sp: ${puData.MV02_sp.toFixed(1)})</div>
|
||||||
|
<div class="monitor-value">MV03<br>${puData.MV03.toFixed(1)} % (sp: ${puData.MV03_sp.toFixed(1)})</div>
|
||||||
|
<div class="monitor-value">MV05<br>${puData.MV05.toFixed(1)} % (sp: ${puData.MV05_sp.toFixed(1)})</div>
|
||||||
|
<div class="monitor-value">MV06<br>${puData.MV06.toFixed(1)} % (sp: ${puData.MV06_sp.toFixed(1)})</div>
|
||||||
|
<div class="monitor-value">MV07<br>${puData.MV07.toFixed(1)} % (sp: ${puData.MV07_sp.toFixed(1)})</div>
|
||||||
|
<div class="monitor-value">MV08<br>${puData.MV08.toFixed(1)} % (sp: ${puData.MV08_sp.toFixed(1)})</div>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateMonitorValues(id, values, unit) {
|
function updateMonitorValues(id, values, unit) {
|
||||||
const container = document.getElementById(id);
|
const container = document.getElementById(id);
|
||||||
|
|
@ -291,5 +315,40 @@
|
||||||
// Update monitor data every second
|
// Update monitor data every second
|
||||||
setInterval(updateMonitorData, 1000);
|
setInterval(updateMonitorData, 1000);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
async function fetchMonitorData() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/monitor');
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
const keys = ["PU_1", "PU_2", "PU_3"];
|
||||||
|
const fields = {
|
||||||
|
"Qperm": "L/h",
|
||||||
|
"Pdilute": "bar",
|
||||||
|
"Conductivity": "µS/cm",
|
||||||
|
"Pro": "bar"
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const field in fields) {
|
||||||
|
const container = document.getElementById(field);
|
||||||
|
if (!container) continue;
|
||||||
|
|
||||||
|
container.innerHTML = keys.map((pu, i) => {
|
||||||
|
const value = data[pu][field] ?? 0.0;
|
||||||
|
return `<div class="monitor-value">#${i + 1}<br>${value.toFixed(1)} ${fields[field]}</div>`;
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur lors de la récupération des données de /monitor :', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(fetchMonitorData, 1000);
|
||||||
|
fetchMonitorData(); // Premier appel immédiat
|
||||||
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user