diff --git a/sleepyhead/SleepLib/calcs.cpp b/sleepyhead/SleepLib/calcs.cpp index d117c686..327459b8 100644 --- a/sleepyhead/SleepLib/calcs.cpp +++ b/sleepyhead/SleepLib/calcs.cpp @@ -35,6 +35,12 @@ bool SearchApnea(Session *session, qint64 time, qint64 dist) if (session->SearchEvent(CPAP_Hypopnea, time, dist)) return true; + if (session->SearchEvent(CPAP_UserFlag1, time, dist)) + return true; + + if (session->SearchEvent(CPAP_UserFlag2, time, dist)) + return true; + return false; } @@ -614,29 +620,21 @@ void FlowParser::calc(bool calcResp, bool calcTv, bool calcTi, bool calcTe, bool } } -void FlowParser::flagEvents() +void FlowParser::flagUserEvents(ChannelID code, EventDataType restriction, EventDataType duration) { - if (!p_profile->cpap->userEventFlagging()) { return; } - int numbreaths = breaths.size(); - - if (numbreaths < 5) { return; } - EventDataType val, mx, mn; QVector br; 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 st, et, dur; //mt + double st, et, dur; qint64 len; bool allowDuplicates = p_profile->cpap->userEventDuplicates(); @@ -649,23 +647,13 @@ void FlowParser::flagEvents() br.push_back(qAbs(p->min)); } -// for (int i = 0; i < numbreaths; i++) { -// mx = breaths[i].max; -// mn = breaths[i].min; -// br.push_back(qAbs(mx)); -// br.push_back(qAbs(mn)); -// } - - //EventList * uf2=m_session->AddEventList(CPAP_UserFlag2,EVL_Event); - //EventList * uf3=m_session->AddEventList(CPAP_UserFlag3,EVL_Event); - const EventDataType perc = 0.6F; int idx = float(br.size()) * perc; nth_element(br.begin(), br.begin() + idx, br.end() - 1); - EventDataType peak = br[idx]; //*(br.begin()+idx); + EventDataType peak = br[idx]; ; - EventDataType cutoffval = peak * (p_profile->cpap->userFlowRestriction() / 100.0F); + EventDataType cutoffval = peak * (restriction / 100.0F); int bs, bm, be, bs1, bm1, be1; @@ -675,16 +663,8 @@ void FlowParser::flagEvents() be = p->end; mx = p->max; mn = p->min; -// for (int i = 0; i < numbreaths; i++) { -// bs = breaths[i].start; -// bm = breaths[i].middle; -// be = breaths[i].end; - -// mx = breaths[i].max; -// mn = breaths[i].min; val = mx - mn; - // if (qAbs(mx) > cutoffval) { bs1 = bs; for (; bs1 < be; bs1++) { @@ -706,8 +686,6 @@ void FlowParser::flagEvents() bend.push_back(bm1); } - // } - // if (qAbs(mn) > cutoffval) { bm1 = bm; for (; bm1 < be; bm1++) { @@ -729,20 +707,12 @@ void FlowParser::flagEvents() bend.push_back(be1); } - // } st = start + bs1 * m_rate; et = start + be1 * m_rate; - // uf2->AddEvent(st,0); - // uf3->AddEvent(et,0); - } - - EventDataType duration = p_profile->cpap->userEventDuration(); - //double lastst=start, lastet=start; - //EventDataType v; int bsize = bstart.size(); - EventList *uf1 = nullptr; + EventList *uf = nullptr; for (int i = 0; i < bsize - 1; i++) { bs = bend[i]; @@ -755,16 +725,28 @@ void FlowParser::flagEvents() if (dur >= duration) { if (allowDuplicates || !SearchApnea(m_session, et - len / 2, 15000)) { - if (!uf1) { - uf1 = m_session->AddEventList(CPAP_UserFlag1, EVL_Event); + if (!uf) { + uf = m_session->AddEventList(code, EVL_Event); } - uf1->AddEvent(et, dur); + uf->AddEvent(et, dur); } } } } +void FlowParser::flagEvents() +{ + if (!p_profile->cpap->userEventFlagging()) { return; } + + int numbreaths = breaths.size(); + + if (numbreaths < 5) { return; } + + flagUserEvents(CPAP_UserFlag1, p_profile->cpap->userFlowRestriction(), p_profile->cpap->userEventDuration()); + flagUserEvents(CPAP_UserFlag2, p_profile->cpap->userFlowRestriction2(), p_profile->cpap->userEventDuration2()); +} + void calcRespRate(Session *session, FlowParser *flowparser) { if (session->machine()->GetType() != MT_CPAP) { return; } diff --git a/sleepyhead/SleepLib/calcs.h b/sleepyhead/SleepLib/calcs.h index 841a7902..066eea3d 100644 --- a/sleepyhead/SleepLib/calcs.h +++ b/sleepyhead/SleepLib/calcs.h @@ -115,6 +115,7 @@ class FlowParser // Minute vent needs Resp & TV calcs made here.. void calc(bool calcResp, bool calcTv, bool calcTi, bool calcTe, bool calcMv); void flagEvents(); + void flagUserEvents(ChannelID code, EventDataType restriction, EventDataType duration); /*void calcTidalVolume(); void calcRespRate(); diff --git a/sleepyhead/SleepLib/profiles.h b/sleepyhead/SleepLib/profiles.h index a18de531..436de67d 100644 --- a/sleepyhead/SleepLib/profiles.h +++ b/sleepyhead/SleepLib/profiles.h @@ -273,6 +273,8 @@ const QString STR_CS_DateDiagnosed = "DateDiagnosed"; const QString STR_CS_UserEventFlagging = "UserEventFlagging"; const QString STR_CS_UserFlowRestriction = "UserFlowRestriction"; const QString STR_CS_UserEventDuration = "UserEventDuration"; +const QString STR_CS_UserFlowRestriction2 = "UserFlowRestriction2"; +const QString STR_CS_UserEventDuration2 = "UserEventDuration2"; const QString STR_CS_UserEventDuplicates = "UserEventDuplicates"; const QString STR_CS_AHIWindow = "AHIWindow"; const QString STR_CS_AHIReset = "AHIReset"; @@ -514,7 +516,9 @@ class CPAPSettings : public ProfileSettings initPref(STR_CS_Notes, QString()); initPref(STR_CS_DateDiagnosed, QDate()); initPref(STR_CS_UserFlowRestriction, 20.0); - initPref(STR_CS_UserEventDuration, 10.0); + initPref(STR_CS_UserEventDuration, 8.0); + initPref(STR_CS_UserFlowRestriction2, 50.0); + initPref(STR_CS_UserEventDuration2, 8.0); initPref(STR_CS_UserEventDuplicates, false); initPref(STR_CS_UserEventFlagging, false); initPref(STR_CS_AHIWindow, 60.0); @@ -541,6 +545,8 @@ class CPAPSettings : public ProfileSettings QDate dateDiagnosed() const { return getPref(STR_CS_DateDiagnosed).toDate(); } double userFlowRestriction() const { return getPref(STR_CS_UserFlowRestriction).toDouble(); } double userEventDuration() const { return getPref(STR_CS_UserEventDuration).toDouble(); } + double userFlowRestriction2() const { return getPref(STR_CS_UserFlowRestriction2).toDouble(); } + double userEventDuration2() const { return getPref(STR_CS_UserEventDuration2).toDouble(); } bool userEventDuplicates() const { return getPref(STR_CS_UserEventDuplicates).toBool(); } double AHIWindow() const { return getPref(STR_CS_AHIWindow).toDouble(); } bool AHIReset() const { return getPref(STR_CS_AHIReset).toBool(); } @@ -563,6 +569,8 @@ class CPAPSettings : public ProfileSettings void setMaskType(MaskType masktype) { setPref(STR_CS_MaskType, (int)masktype); } void setUserFlowRestriction(double flow) { setPref(STR_CS_UserFlowRestriction, flow); } void setUserEventDuration(double duration) { setPref(STR_CS_UserEventDuration, duration); } + void setUserFlowRestriction2(double flow) { setPref(STR_CS_UserFlowRestriction2, flow); } + void setUserEventDuration2(double duration) { setPref(STR_CS_UserEventDuration2, duration); } void setAHIWindow(double window) { setPref(STR_CS_AHIWindow, window); } void setAHIReset(bool reset) { setPref(STR_CS_AHIReset, reset); } void setUserEventFlagging(bool flagging) { setPref(STR_CS_UserEventFlagging, flagging); } diff --git a/sleepyhead/preferencesdialog.cpp b/sleepyhead/preferencesdialog.cpp index 912e5c24..74a865d6 100644 --- a/sleepyhead/preferencesdialog.cpp +++ b/sleepyhead/preferencesdialog.cpp @@ -242,6 +242,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Profile *_profile) : ui->customEventGroupbox->setChecked(profile->cpap->userEventFlagging()); ui->apneaDuration->setValue(profile->cpap->userEventDuration()); ui->apneaFlowRestriction->setValue(profile->cpap->userFlowRestriction()); + ui->apneaDuration2->setValue(profile->cpap->userEventDuration2()); + ui->apneaFlowRestriction2->setValue(profile->cpap->userFlowRestriction2()); ui->userEventDuplicates->setChecked(profile->cpap->userEventDuplicates()); ui->userEventDuplicates->setVisible(false); @@ -355,7 +357,9 @@ bool PreferencesDialog::Save() if (profile->cpap->userEventFlagging() && (profile->cpap->userEventDuration() != ui->apneaDuration->value() || + profile->cpap->userEventDuration2() != ui->apneaDuration2->value() || profile->cpap->userEventDuplicates() != ui->userEventDuplicates->isChecked() || + profile->cpap->userFlowRestriction2() != ui->apneaFlowRestriction2->value() || profile->cpap->userFlowRestriction() != ui->apneaFlowRestriction->value())) { recalc_events = true; } @@ -478,6 +482,9 @@ bool PreferencesDialog::Save() profile->cpap->setUserEventDuration(ui->apneaDuration->value()); profile->cpap->setUserFlowRestriction(ui->apneaFlowRestriction->value()); + profile->cpap->setUserEventDuration2(ui->apneaDuration2->value()); + profile->cpap->setUserFlowRestriction2(ui->apneaFlowRestriction2->value()); + profile->cpap->setUserEventDuplicates(ui->userEventDuplicates->isChecked()); PREF[STR_GEN_SkipLogin] = ui->skipLoginScreen->isChecked(); diff --git a/sleepyhead/preferencesdialog.ui b/sleepyhead/preferencesdialog.ui index 5e21eff8..c772f102 100644 --- a/sleepyhead/preferencesdialog.ui +++ b/sleepyhead/preferencesdialog.ui @@ -51,7 +51,7 @@ - 0 + 1 @@ -878,19 +878,6 @@ This option must be enabled before import, otherwise a purge is required. 4 - - - - - 0 - 0 - - - - Flow Restriction - - - @@ -924,6 +911,19 @@ A value of 20% works well for detecting apneas. + + + + + 0 + 0 + + + + Flow Restriction + + + @@ -975,7 +975,41 @@ p, li { white-space: pre-wrap; } - + + + + % + + + 10.000000000000000 + + + + + + + #2 + + + + + + + s + + + 10.000000000000000 + + + + + + + #1 + + + + Allow duplicates near machine events.