From e8d11f33370d1e8b16ed3b6a17913dc700b700b4 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Tue, 13 Dec 2011 04:37:34 +1000 Subject: [PATCH] PRS1 Apnea Flagging Experiment --- SleepLib/calcs.cpp | 58 ++++++++++++++++++++++++++++++++++++---------- daily.cpp | 4 +++- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/SleepLib/calcs.cpp b/SleepLib/calcs.cpp index 6ba46ce4..3bdca176 100644 --- a/SleepLib/calcs.cpp +++ b/SleepLib/calcs.cpp @@ -10,7 +10,7 @@ // Support function for calcRespRate() -int filterFlow(EventList *in, EventList *out, EventList *tv, EventList *mv, double rate, EventList *uf1) +int filterFlow(EventList *in, EventList *out, EventList *tv, EventList *mv, double rate, EventList *uf1, EventList *uf2) { int size=in->count(); @@ -183,7 +183,7 @@ int filterFlow(EventList *in, EventList *out, EventList *tv, EventList *mv, doub } else { if (c<=min) { min=c; - peakmin=time+rate; + peakmin=time; } } @@ -193,16 +193,47 @@ int filterFlow(EventList *in, EventList *out, EventList *tv, EventList *mv, doub time+=rate; } if (!breaths.size()) { - return 0; } - double avg; + double avgmax=0; for (int i=0;iAddEvent(breaths_max_peak[i],0,min); + max=breaths_max[i]; + avgmax+=max; + } + avgmax/=EventDataType(breaths_max.size()); + + double avgmin=0; + for (int i=0;iAddEvent(breaths_min_peak[i],0,min); + } + avgmin/=EventDataType(breaths_min.size()); + + QVector goodb; + for (int i=0;i avgmax*0.2) { + goodb.push_back(time); + } + } + for (int i=0;i=10000) { + time=goodb[i-1]+len/2; + uf1->AddEvent(time,0,1); + } } - avg/=EventDataType(breaths_max.size()); qint64 window=60000; qint64 t1=in->first()-window/2; @@ -316,7 +347,7 @@ int calcRespRate(Session *session) if (session->eventlist.contains(CPAP_RespRate)) return 0; // already exists? - EventList *flow, *rr=NULL, *tv=NULL, *mv=NULL, *uf=NULL; + EventList *flow, *rr=NULL, *tv=NULL, *mv=NULL, *uf=NULL, *uf2=NULL; if (!session->eventlist.contains(CPAP_TidalVolume)) { tv=new EventList(EVL_Event); @@ -332,8 +363,11 @@ int calcRespRate(Session *session) if (rr) session->eventlist[CPAP_RespRate].push_back(rr); if (tv) session->eventlist[CPAP_TidalVolume].push_back(tv); if (mv) session->eventlist[CPAP_MinuteVent].push_back(mv); - //uf=new EventList(EVL_Event,1,0,0,0,0,true); - //session->eventlist["UserFlag1"].push_back(uf1); + uf=new EventList(EVL_Event,1,0,0,0,0,true); + session->eventlist["UserFlag1"].push_back(uf); + + //uf2=new EventList(EVL_Event,1,0,0,0,0,true); + //session->eventlist["UserFlag2"].push_back(uf2); int cnt=0; for (int ws=0; ws < session->eventlist[CPAP_FlowRate].size(); ws++) { @@ -344,7 +378,7 @@ int calcRespRate(Session *session) if (flow->count()==103200) { int i=5; } - cnt+=filterFlow(flow,rr,tv,mv,flow->rate(),uf); + cnt+=filterFlow(flow,rr,tv,mv,flow->rate(),uf,uf2); if (tv->count()==0) { int i=5; diff --git a/daily.cpp b/daily.cpp index 24da70e8..6b7558f9 100644 --- a/daily.cpp +++ b/daily.cpp @@ -144,6 +144,7 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw) fg->AddLayer((new gFlagsLine(CPAP_RERA,QColor("gold"),"RE"))); fg->AddLayer((new gFlagsLine(CPAP_VSnore,QColor("red"),"VS"))); fg->AddLayer((new gFlagsLine("UserFlag1",QColor("yellow"),"UF1"))); + fg->AddLayer((new gFlagsLine("UserFlag2",QColor("green"),"UF2"))); //fg->AddLayer((new gFlagsLine(PRS1_0B,QColor("dark green"),"U0B"))); //fg->AddLayer((new gFlagsLine(CPAP_VSnore2,QColor("red"),"VS2"))); SF->setBlockZoom(true); @@ -174,7 +175,8 @@ Daily::Daily(QWidget *parent,gGraphView * shared, MainWindow *mw) FRW->AddLayer(AddCPAP(new gLineOverlayBar(CPAP_FlowLimit,QColor("black"),"FL"))); FRW->AddLayer(AddCPAP(los->add(new gLineOverlayBar(CPAP_Obstructive,QColor("#40c0ff"),"OA")))); FRW->AddLayer(AddCPAP(los->add(new gLineOverlayBar(CPAP_ClearAirway,QColor("purple"),"CA")))); - FRW->AddLayer(AddCPAP(new gLineOverlayBar("UserFlag1",QColor("yellow"),"UF",FT_Bar))); + FRW->AddLayer(AddCPAP(new gLineOverlayBar("UserFlag1",QColor("yellow"),"U1",FT_Bar))); + FRW->AddLayer(AddCPAP(new gLineOverlayBar("UserFlag2",QColor("orange"),"U2",FT_Bar))); FRW->AddLayer(AddOXI(new gLineOverlayBar(OXI_SPO2Drop,QColor("red"),"O2"))); FRW->AddLayer(AddOXI(new gLineOverlayBar(OXI_PulseChange,QColor("blue"),"PC",FT_Dot)));