diff --git a/main.py b/main.py index e9558a9..eaedc77 100644 --- a/main.py +++ b/main.py @@ -247,7 +247,7 @@ async def update_latest_data(): current_data = latest_data[f"PU_{pu}"] logging.debug(f"[MONITOR BUFFER] PU{pu}: {current_data}") # logging.info(f"[MONITOR BUFFER] latest_data: {latest_data}") - await asyncio.sleep(0.1) + await asyncio.sleep(0.05) @app.get("/monitor") @@ -348,7 +348,7 @@ async def record_data_loop(): recording_file.flush() last_flush_time = datetime.datetime.now() - await asyncio.sleep(0.1) # 10 Hz + await asyncio.sleep(0.05) # 10 Hz ## AUTOMATIC TESTING diff --git a/static/multi_pu_dashboard.html b/static/multi_pu_dashboard.html index 364551a..cc2188a 100644 --- a/static/multi_pu_dashboard.html +++ b/static/multi_pu_dashboard.html @@ -67,6 +67,8 @@ function initAllPlots() { xaxis: { title: 'Time', type: 'date' }, yaxis: { title: plot.id.includes('P') ? 'Pressure (bar)' : 'Flow (L/h)' }, }; + + // Add ref line if present if (plot.ref !== undefined) { data.push({ x: [time0[0], time0[0]], @@ -77,9 +79,23 @@ function initAllPlots() { showlegend: true }); } + + // Add QSkid trace only for Qperm plot + if (plot.id === 'Qperm-plot') { + data.push({ + x: time0.slice(), + y: zero.slice(), + name: 'QSkid', + mode: 'lines', + line: { color: 'black', width: 2, dash: 'dot' }, + legendgroup: 'PatientSkid' + }); + } + Plotly.newPlot(plot.id, data, layout); }); } + async function updateAllPlots() { try { const res = await fetch('/monitor'); @@ -110,6 +126,16 @@ async function updateAllPlots() { y: [[plot.ref]] }, [puList.length], maxPoints); // the ref line is always the last trace } + + // Extend PatientSkid.QSkid only for Qperm plot + if (plot.id === 'Qperm-plot') { + const qSkid = SkidData["QSkid"]; + const skidX = [[timestamp]]; + const skidY = [[qSkid !== undefined ? qSkid : null]]; + const qSkidTraceIndex = puList.length + (plot.ref !== undefined ? 1 : 0); // last trace index + Plotly.extendTraces(plot.id, { x: skidX, y: skidY }, [qSkidTraceIndex], maxPoints); + } + }); } catch (err) { console.error("Failed to update plots:", err);