From 2ef90283d6351f5af1e33df25e5791e1d3492d48 Mon Sep 17 00:00:00 2001 From: Etienne Chassaing <60154720+cetiennec@users.noreply.github.com> Date: Wed, 20 Aug 2025 15:10:25 +0200 Subject: [PATCH] Automatic PROD MODE html update --- main.py | 4 +-- templates/control.html | 66 +++++++++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/main.py b/main.py index e1e36a8..596ffa1 100644 --- a/main.py +++ b/main.py @@ -81,7 +81,7 @@ def format_PU_data(data): "timestamp": datetime.datetime.now().isoformat(), "Qperm": np.round(data.get("FM2", 0.0), 1), "Qdilute": np.round(data.get("FM1", 0.0), 1), - "Qdrain": max(np.round(data.get("FM4", 0.0), 1),350.0), + "Qdrain": np.round(data.get("FM4", 0.0), 1), "Qrecirc": np.round(data.get("FM3", 0.0), 1), "QdrainEDI": np.round(data.get("FM2", 0.0), 1) - np.round(data.get("FM1", 0.0), 1), "Pro": np.round(data.get("PS2", 0.0), 2), @@ -104,7 +104,7 @@ def format_PU_data(data): "MV07_sp": np.round(data.get("MV07_sp", 0.0), 1), "MV08": np.round(data.get("MV08", 0.0), 1), "MV08_sp": np.round(data.get("MV08_sp", 0.0), 1), - "Qdrain_sp" : 60*np.round(data.get("Qdrain_sp", 0.0), 2), + "Qdrain_sp" : max(60*np.round(data.get("Qdrain_sp", 0.0), 2),350.0), } def format_DS_data(data): diff --git a/templates/control.html b/templates/control.html index 18cd510..c372ceb 100644 --- a/templates/control.html +++ b/templates/control.html @@ -430,34 +430,48 @@ btn.classList.remove('in-progress', 'ready', 'production'); }); if (state === 'PRE-PRODUCTION') { - buttonEl.classList.add('in-progress'); - buttonEl.textContent = `Waiting... PU ${puNumber}`; - buttonEl.disabled = true; - const checkReady = async () => { - const res = await fetch(`/api/pu_status`); - const states = await res.json(); - const currentState = states[`PU${puNumber}`]; - if (currentState === 'SYSTEM_MODE_READY') { - buttonEl.classList.remove('in-progress'); - buttonEl.classList.add('ready'); - buttonEl.textContent = `START PRODUCTION PU ${puNumber}`; - buttonEl.disabled = false; - buttonEl.onclick = async () => { - await sendCommand("PRODUCTION", puNumber, buttonEl); - buttonEl.classList.remove('ready'); - buttonEl.classList.add('production'); - buttonEl.textContent = `PRODUCTION ON PU ${puNumber}`; - buttonEl.disabled = true; - }; - } else { - setTimeout(checkReady, 1000); - } - }; - checkReady(); - } else if (state === 'PRODUCTION') { + buttonEl.classList.add('in-progress'); + buttonEl.textContent = `Waiting... PU ${puNumber}`; + buttonEl.disabled = true; + + const checkReady = async () => { + const res = await fetch(`/api/pu_status`); + const states = await res.json(); + const currentState = states[`PU${puNumber}`]; + + if (currentState === 'SYSTEM_MODE_READY') { + buttonEl.classList.remove('in-progress'); + buttonEl.classList.add('ready'); + buttonEl.textContent = `START PRODUCTION PU ${puNumber}`; + buttonEl.disabled = false; + + buttonEl.onclick = async () => { + await sendCommand("PRODUCTION", puNumber, buttonEl); + buttonEl.classList.remove('ready'); buttonEl.classList.add('production'); buttonEl.textContent = `PRODUCTION ON PU ${puNumber}`; - } else if (state === 'IDLE' || state === 'FIRST_START') { + buttonEl.disabled = true; + }; + } else if (currentState === 'PRODUCTION') { + // ✅ Directly update if already in production + buttonEl.classList.remove('in-progress'); + buttonEl.classList.add('production'); + buttonEl.textContent = `PRODUCTION ON PU ${puNumber}`; + buttonEl.disabled = true; + } else { + setTimeout(checkReady, 1000); + } + }; + + checkReady(); + + } else if (state === 'PRODUCTION') { + // ✅ Handles initial load case + buttonEl.classList.add('production'); + buttonEl.textContent = `PRODUCTION ON PU ${puNumber}`; + buttonEl.disabled = true; + } + else if (state === 'IDLE' || state === 'FIRST_START') { buttonEl.classList.remove('in-progress', 'ready', 'production'); buttonEl.classList.add('production'); buttonEl.textContent = `${state.replace('_', ' ')} PU ${puNumber}`;