Skip to content
Snippets Groups Projects
Commit 53ab0295 authored by Stephen Farry's avatar Stephen Farry
Browse files

Merge branch 'betterLoops' into 'master'

Sorted last-data into acending row order and improved loop plots

See merge request hev-sw/hev-sw!51
parents 8878e911 43a8dc12
Branches
No related merge requests found
...@@ -545,6 +545,8 @@ def last_data(rowid): ...@@ -545,6 +545,8 @@ def last_data(rowid):
for index, item in enumerate(readback_variables): for index, item in enumerate(readback_variables):
data[item] = el[index] data[item] = el[index]
fetched_all.append(data) fetched_all.append(data)
fetched_all.sort(key=lambda x : x["ROWID"]) # force rows into acending order
response = make_response(json.dumps(fetched_all).encode('utf-8') ) response = make_response(json.dumps(fetched_all).encode('utf-8') )
response.content_type = 'application/json' response.content_type = 'application/json'
return response return response
......
// to quote the AAMI:
//For Pressure-Volume loops, the graph
//is required to use delivered volume on the vertical axis
//and airway pressure on the horizontal axis. Positive
//values should increase in up/right directions. Every
//breath resets the graph, setting the volume back at the
//origin.
//For Flow-Volume loops the graph is required to use flow
//rate on the vertical axis and delivered volume on the
//horizontal axis. Positive values should increase in the
//up/right directions. Every breath resets the graph,
//setting the volume back at the origin. The document also
//suggests that there could be another version using
//exhalation flow, if possible.
//3 loop displays: Pressure-Volume, Flow-Volume and Pressure-Flow. //3 loop displays: Pressure-Volume, Flow-Volume and Pressure-Flow.
var chart_PV; var chart_PV;
var chart_FV; var chart_FV;
...@@ -6,6 +22,10 @@ var chart_PF; ...@@ -6,6 +22,10 @@ var chart_PF;
// last row accessed from the database // last row accessed from the database
var last_row_accessed = 0; var last_row_accessed = 0;
// is the plot in the exhale part of the cycle
var inExhaleFill = false;
var inExhale = false;
var holdLoop = false; // global if loop plot to stop at end of this loop var holdLoop = false; // global if loop plot to stop at end of this loop
var stopLoop = false; // global if loop plotting is stopped var stopLoop = false; // global if loop plotting is stopped
...@@ -13,7 +33,7 @@ var stopLoop = false; // global if loop plotting is stopped ...@@ -13,7 +33,7 @@ var stopLoop = false; // global if loop plotting is stopped
function HoldLoop() { function HoldLoop() {
console.info("Holding loop"); console.info("Holding loop");
holdLoop = true; holdLoop = true;
stopLoop = false; // run on either to end of loop stopLoop = false; // run to end of loop
// toggle button state to allow a start or stop of the loop // toggle button state to allow a start or stop of the loop
document.getElementById("LoopHoldButton").disabled = true; document.getElementById("LoopHoldButton").disabled = true;
document.getElementById("LoopStartButton").disabled = false; document.getElementById("LoopStartButton").disabled = false;
...@@ -21,7 +41,7 @@ function HoldLoop() { ...@@ -21,7 +41,7 @@ function HoldLoop() {
function RunLoop() { function RunLoop() {
console.info("Running loop"); console.info("Running loop");
holdLoop = false; holdLoop = false;
stopLoop = false; // run on either to end of loop stopLoop = false; // running again
// toggle button state to allow a start or stop of the loop // toggle button state to allow a start or stop of the loop
document.getElementById("LoopHoldButton").disabled = false; document.getElementById("LoopHoldButton").disabled = false;
document.getElementById("LoopStartButton").disabled = true; document.getElementById("LoopStartButton").disabled = true;
...@@ -35,7 +55,6 @@ function RunLoop() { ...@@ -35,7 +55,6 @@ function RunLoop() {
chart_PF.update(); chart_PF.update();
} }
/** /**
* Request new data from the server, add it to the graph and set a timeout * Request new data from the server, add it to the graph and set a timeout
* to request again * to request again
...@@ -46,12 +65,24 @@ function requestChartVar() { ...@@ -46,12 +65,24 @@ function requestChartVar() {
success: function(data) { success: function(data) {
if (data.length > 0 ) { if (data.length > 0 ) {
last_row_accessed = data[0]['ROWID']; last_row_accessed = data[0]['ROWID'];
if (stopLoop) { if (stopLoop) {
return; // nothing to do if stopped return; // nothing to do if stopped
} }
for ( let i = data.length-1 ; i >= 0; i--) { for ( let i = data.length-1 ; i >= 0; i--) {
var point = data[i]; var point = data[i];
if( point["fsm_state"] == 14 ) { // start of loop FIXME if( point["payload_type"] != "DATA" ) continue; // ignore all other data packets
// loop could be INHALE -> PAUSE -> EXHALE_FILL -> INHALE -> EXHALE -> BUFF_PRE_INHALE -> new loop
// may miss some of the shorter steps (PAUSE & BUFF_PRE_INHALE)
if( point["fsm_state"] == "EXHALE_FILL" ){
inExhaleFill = true; // in exhale part of loop
}
if( point["fsm_state"] == "EXHALE" ){
inExhale = true; // in exhale part of loop
}
if( point["fsm_state"] == "INHALE" && inExhale ) { // start of loop (exhale->inhale transition)
inExhale = false;
inExhaleFill = false;
if( holdLoop ) { if( holdLoop ) {
stopLoop = true; stopLoop = true;
holdLoop = false; holdLoop = false;
...@@ -69,45 +100,48 @@ function requestChartVar() { ...@@ -69,45 +100,48 @@ function requestChartVar() {
chart_PV.data.datasets[0].data.length = 0; chart_PV.data.datasets[0].data.length = 0;
chart_VF.data.datasets[0].data.length = 0; chart_VF.data.datasets[0].data.length = 0;
chart_PF.data.datasets[0].data.length = 0; chart_PF.data.datasets[0].data.length = 0;
chart_PV.data.datasets[1].data.length = 0;
chart_VF.data.datasets[1].data.length = 0;
chart_PF.data.datasets[1].data.length = 0;
} }
}else if( chart_PV.data.datasets[0].data.length > 100 ){
chart_PV.data.datasets[0].data.shift();
chart_VF.data.datasets[0].data.shift();
chart_PF.data.datasets[0].data.shift();
} }
if( ! stopLoop ){ // skip updates if loop is stopped if( chart_PV.data.datasets[0].data.length > 1000 ){ // protect against not seeing a new loop
//var pressure = point["airway_pressure"]; chart_PV.data.datasets[0].data.length = 100;
chart_VF.data.datasets[0].data.length = 100;
chart_PF.data.datasets[0].data.length = 100;
console.warning("Too many points to plot in inhale, is loop stopped?")
}
if( chart_PV.data.datasets[1].data.length > 1000 ){ // protect against not seeing a new loop
chart_PV.data.datasets[1].data.length = 100;
chart_VF.data.datasets[1].data.length = 100;
chart_PF.data.datasets[1].data.length = 100;
console.warning("Too many points to plot in exhale, is loop stopped?")
}
if( ! stopLoop ){
// if the loop is running update the points
var pressure = point["pressure_patient"]; var pressure = point["pressure_patient"];
var volume = point["volume"]; var volume = point["volume"];
var flow = point["flow"]; var flow = point["flow"];
// to quote the AAMI:
//For Pressure-Volume loops, the graph
//is required to use delivered volume on the vertical axis
//and airway pressure on the horizontal axis. Positive
//values should increase in up/right directions. Every
//breath resets the graph, setting the volume back at the
//origin.
//For Flow-Volume loops the graph is required to use flow
//rate on the vertical axis and delivered volume on the
//horizontal axis. Positive values should increase in the
//up/right directions. Every breath resets the graph,
//setting the volume back at the origin. The document also
//suggests that there could be another version using
//exhalation flow, if possible.
// loops: // loops:
chart_PV.data.datasets[0].data.push({x: pressure, y: volume}); if( (! inExhale) && (!inExhaleFill) ) {
chart_VF.data.datasets[0].data.push({x: volume, y: flow}); // inhale points
chart_PF.data.datasets[0].data.push({x: pressure, y: flow}); chart_PV.data.datasets[0].data.push({x: pressure, y: volume});
chart_VF.data.datasets[0].data.push({x: volume, y: flow});
// now run chart updates chart_PF.data.datasets[0].data.push({x: pressure, y: flow});
chart_PV.update(); }else{
chart_VF.update(); // exhale points
chart_PF.update(); chart_PV.data.datasets[1].data.push({x: pressure, y: volume});
chart_VF.data.datasets[1].data.push({x: volume, y: flow});
chart_PF.data.datasets[1].data.push({x: pressure, y: flow});
}
} }
} }
// now run chart updates: outside loop (only need to update plot every 0.2s)
chart_PV.update();
chart_VF.update();
chart_PF.update();
} }
}, },
cache: false cache: false
...@@ -122,11 +156,17 @@ $(document).ready(function() { ...@@ -122,11 +156,17 @@ $(document).ready(function() {
chart_PV = new Chart(ctx_PV, { chart_PV = new Chart(ctx_PV, {
type: 'scatter', type: 'scatter',
data: {datasets: [{data: [], data: {datasets: [{data: [],
label: "Pressure - Volume", label: "Inhale",
borderColor: "rgb(51,99,255)", borderColor: "rgb(51,99,255)",
pointBackgroundColor : "rgb(51,99,255)", pointBackgroundColor : "rgb(51,99,255)",
fill: false, fill: false,
showLine: true }, showLine: false },
{data: [],
label: "Exhale : Pressure - Volume",
borderColor: "rgb(255,99,51)",
pointBackgroundColor : "rgb(255,99,51)",
fill: false,
showLine: false }
]}, ]},
options: {elements: { point: { radius: 5}}, options: {elements: { point: { radius: 5}},
legend: { display: true, labels: {fontSize: 24 } }, legend: { display: true, labels: {fontSize: 24 } },
...@@ -144,11 +184,17 @@ $(document).ready(function() { ...@@ -144,11 +184,17 @@ $(document).ready(function() {
chart_VF = new Chart(ctx_VF, { chart_VF = new Chart(ctx_VF, {
type: 'scatter', type: 'scatter',
data: {datasets: [{data: [], data: {datasets: [{data: [],
label: "Volume - Flow", label: "Inhale",
borderColor: "rgb(51,99,255)", borderColor: "rgb(51,99,255)",
pointBackgroundColor : "rgb(51,99,255)", pointBackgroundColor : "rgb(51,99,255)",
fill: false, fill: false,
showLine: true }]} showLine: false },
{data: [],
label: "Exhale : Volume - Flow",
borderColor: "rgb(255,99,51)",
pointBackgroundColor : "rgb(255,99,51)",
fill: false,
showLine: false }]}
,options: {elements: { point: { radius: 5}}, ,options: {elements: { point: { radius: 5}},
legend: { display: true, labels: {fontSize: 24 } }, legend: { display: true, labels: {fontSize: 24 } },
scales: {xAxes: [{display: true, scales: {xAxes: [{display: true,
...@@ -165,11 +211,17 @@ $(document).ready(function() { ...@@ -165,11 +211,17 @@ $(document).ready(function() {
chart_PF = new Chart(ctx_PF, { chart_PF = new Chart(ctx_PF, {
type: 'scatter', type: 'scatter',
data: {datasets: [{data: [], data: {datasets: [{data: [],
label: "Pressure - Flow", label: "Inhale",
borderColor: "rgb(51,99,255)", borderColor: "rgb(51,99,255)",
pointBackgroundColor : "rgb(51,99,255)", pointBackgroundColor : "rgb(51,99,255)",
fill: false, fill: false,
showLine: true }]} showLine: false },
{data: [],
label: "Exhale : Pressure - Flow",
borderColor: "rgb(255,99,51)",
pointBackgroundColor : "rgb(255,99,51)",
fill: false,
showLine: false }]}
,options: {elements: { point: { radius: 5, fill: true}}, ,options: {elements: { point: { radius: 5, fill: true}},
legend: { display: true, labels: {fontSize: 24 } }, legend: { display: true, labels: {fontSize: 24 } },
scales: {xAxes: [{display: true, scales: {xAxes: [{display: true,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment