Skip to content
Snippets Groups Projects
Commit 10c2acb0 authored by Robert L. Read's avatar Robert L. Read
Browse files

significant bug fixed in breath computation

parent 2079155b
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ Breath Plot: COVID-19 Respiration Analysis Software
<!-- Load plotly.js into the DOM -->
<script src='https://cdn.plot.ly/plotly-latest.min.js'></script>
<script src='./js/respiration_math.js'></script>
<script src='/respiration_math.js'></script>
<title>Public Invention Respiration Analysis</title>
......@@ -585,7 +585,7 @@ var intervalID = null;
// This sould be better as time, but is easier
// to do as number of samples.
var MAX_SAMPLES_TO_STORE_S = 160;
var MAX_SAMPLES_TO_STORE_S = 2000;
var MAX_REFRESH = false;
var samples = [];
var INITS_ONLY = true;
......@@ -1380,7 +1380,7 @@ function retrieveAndPlot(){
samples = samples.filter((s, index, self) =>
s.ms >= (last_ms - DESIRED_DURATION_S*1000));
}
console.log(samples);
// console.log(samples);
if (samples.length > 0)
process(samples);
console.log("END",LAST_SAMPLE_DATE);
......
......@@ -122,7 +122,7 @@ function compute_fio2_mean(secs,samples) {
}
}
// WARNING! With a low number of breaths, this may be wrong.
function compute_respiration_rate(secs,samples,transitions,breaths) {
// In order to compute the number of breaths
// in the last s seconds, I compute those breaths
......@@ -175,6 +175,7 @@ function compute_respiration_rate(secs,samples,transitions,breaths) {
i--;
}
if ((cnt > 1) && (first_inhale_ms != last_inhale_ms)) {
// I now think this math is specious!!
var inhalation_duration = last_inhale_ms - first_inhale_ms;
var inhalation_duration_min = inhalation_duration / (60.0 * 1000.0);
var rr = (cnt - 1) / inhalation_duration_min;
......@@ -588,7 +589,7 @@ function testWorkSynthetic(){ // breaths give us inspiration transition points
var vole = 0;
var breaths = [];
var expiring = true;
var expiring = false;
for(var i = 0; i < transitions.length; i++) {
// We're looking for the end of the inhalation here!!
......@@ -676,6 +677,12 @@ function computeMovingWindowTrace(samples,t,v) {
var voli = 0;
var vole = 0;
// This code was robust when I breathed through a mask,
// but on clean simulations with negative flow, seemes to
// go awry...
// It think really it makes more sense to find the first
// transition from a non-inspiring state to an inspiring state
// and start there.
for(var i = 0; i < transitions.length; i++) {
// We're looking for the end of the inhalation here!!
if (((i -1) >= 0) && transitions[i-1].state == 1 && (transitions[i].state == 0 || transitions[i].state == -1 )) {
......@@ -698,7 +705,7 @@ function computeMovingWindowTrace(samples,t,v) {
vole = integrateSamples(last,transitions[i].sample,flows);
last = transitions[i].sample;
}
if (!expiring && transitions[i].state == -1) {
if (!expiring && (transitions[i].state == -1)) {
expiring = true;
voli = integrateSamples(last,transitions[i].sample,flows);
last = transitions[i].sample;
......
No preview for this file type
......@@ -8,6 +8,10 @@ var express = require('express');
const cors = require('cors');
var app = express();
app.use(cors());
// NOTE: We could enumerate porst with "SerialPort.list()"...
// that would be a little friendlier for people who can't find
// the filename of their serial port!
const SerialPort = require('serialport'); //https://serialport.io/docs/guide-usage
const Readline = require('@serialport/parser-readline');
......@@ -43,6 +47,9 @@ sport.on('error', function(err) {
console.log('Error: ', err.message)
})
// Note: I now believe we need to listen here for
// Acknowledgements and do something special with them to
// thottle the serial buffer.
parser.on('data', data =>{
// Let's see if the data is a PIRDS event...
......@@ -140,11 +147,20 @@ app.get('/api/pircs', function(req, res) {
res.setHeader("Content-Type", "application/json");
res.setHeader('Access-Control-Allow-Origin', '*');
res.status(200).send(x);
// The documentaiton supports this:
// function writeAndDrain (data, callback) {
// port.write(data)
// port.drain(callback)
// }
// Howewver, we are fundamentally asynchronous in processing
// requests, so it is unclear how this would work!
// Possibly we could call drain first!
sport.drain( () =>
sport.write(x, (err) => {
if (err) {
return console.log('Error on write: ', err.message);
}
});
}));
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment