From b42e4246bf14d074d51c57a1e048adafc7350627 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Mon, 9 Jan 2012 20:05:24 +1000 Subject: [PATCH] User Flagging Improvements.. (also, event search is now on) --- SleepLib/calcs.cpp | 173 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 133 insertions(+), 40 deletions(-) diff --git a/SleepLib/calcs.cpp b/SleepLib/calcs.cpp index 0b42329d..3235e386 100644 --- a/SleepLib/calcs.cpp +++ b/SleepLib/calcs.cpp @@ -552,48 +552,39 @@ void FlowParser::flagEvents() int numbreaths=breaths.size(); EventDataType val,mx,mn; - QVector br(numbreaths); + QVector br; -// QVector bstart(numbreaths); -// QVector bend(numbreaths); -// QVector bvalue(numbreaths); + QVector bstart; + QVector bend; + //QVector bvalue; + + bstart.reserve(numbreaths*2); + bend.reserve(numbreaths*2); + //bvalue.reserve(numbreaths*2); + br.reserve(numbreaths*2); double start=m_flow->first(); - double sps=1000.0/m_rate; + // double sps=1000.0/m_rate; double st,mt,et, dur; qint64 len; for (int i=0;iuserFlowRestriction()/100.0); - EventDataType duration=PROFILE.cpap->userEventDuration(); - QVector good; - EventList * uf1=NULL; - //EventList * uf2=m_session->AddEventList(CPAP_UserFlag2,EVL_Event); - // EventList * uf3=m_session->AddEventList(CPAP_UserFlag3,EVL_Event); - - double lastst=start, lastet=start; - good.reserve(numbreaths); - bool bad=false; - int bs,bm,be; + int bs,bm,be, bs1, bm1, be1; for (int i=0;i cutoffval) { - bs=i; +// if (qAbs(mx) > cutoffval) { + bs1=bs; + for (;bs1 cutoffval) { + break; + } + } + + bm1=bm; + for (;bm1>bs;bm1--) { + if (qAbs(m_filtered[bm1]) > cutoffval) { + break; + } + } + if (bm1>=bs1) { + bstart.push_back(bs1); + bend.push_back(bm1); + } + // } + // if (qAbs(mn) > cutoffval) { + bm1=bm; + for (;bm1 cutoffval) { + break; + } + } + be1=be; + for (;be1>bm;be1--) { + if (qAbs(m_filtered[be1]) > cutoffval) { + break; + } + } + if (be1>=bm1) { + bstart.push_back(bm1); + bend.push_back(be1); + } +// } + } + + + EventDataType duration=PROFILE.cpap->userEventDuration(); + //double lastst=start, lastet=start; + //EventDataType v; + int bsize=bstart.size(); + EventList * uf1=NULL; + // EventList * uf2=m_session->AddEventList(CPAP_UserFlag2,EVL_Event); + // EventList * uf3=m_session->AddEventList(CPAP_UserFlag3,EVL_Event); + + for (int i=0;i=duration) { + if (!SearchApnea(m_session,st-len/2,15000)) { + if (!uf1) { + uf1=m_session->AddEventList(CPAP_UserFlag1,EVL_Event); + } + uf1->AddEvent(et-len/2,dur); + } + } + } + + + +/* QVector good; + + + good.reserve(numbreaths); + bool bad=false; + int bs,bm,be; + + for (int idx=0;idx cutoffval) continue; + + int j=bs; + for (;j>0;j--) { + if (qAbs(m_filtered[j]) > cutoffval) { + bs=j; break; } } - i=be; - for (;i>bm;i--) { - if (qAbs(m_filtered[i]) > cutoffval) { - be=i; + + if (bs==be) continue; + j=be; + for (;j cutoffval) { + be=j; break; } } + st=start + bs * m_rate; mt=start + bm * m_rate; et=start + be * m_rate; - len=st-lastet; + len=et-st; dur=len/1000.0; if (dur>=duration) { //if (!SearchApnea(m_session,st-len/2,15000)) { if (!uf1) { uf1=m_session->AddEventList(CPAP_UserFlag1,EVL_Event); } - uf1->AddEvent(st-len/2,dur); + uf1->AddEvent(et-len/2,dur); //} } // Uncomment to use UserFlags to show waveform crossover points // Good for debugging this stuff. (Make sure to add the EventLists up above) - if (val > cutoffval) { + //if (val > cutoffval) { //uf2->AddEvent(st,0); //uf2->AddEvent(mt,0); //uf3->AddEvent(et,0); lastet=et; lastst=st; - } + //} } return; - +*/ //EventList *uf1=NULL; // int lastbad=-1;