diff --git a/SleepLib/day.cpp b/SleepLib/day.cpp index 1d8ef4ee..045538c6 100644 --- a/SleepLib/day.cpp +++ b/SleepLib/day.cpp @@ -6,6 +6,7 @@ #include "day.h" #include "profiles.h" +#include Day::Day(Machine *m) :machine(m) @@ -146,11 +147,15 @@ EventDataType Day::settings_wavg(ChannelID code) tmp=(s1/s2); return tmp; } + + + + + + EventDataType Day::percentile(ChannelID code,EventDataType percentile) { // Cache this calculation - - //if (percentile>=1) return 0; // probably better to crash and burn. QVector::iterator s; @@ -174,21 +179,28 @@ EventDataType Day::percentile(ChannelID code,EventDataType percentile) if (!size) return 0; size--; - qSort(ar); - int p=EventDataType(size)*percentile; - float p2=EventDataType(size)*percentile; - float diff=p2-p; - EventDataType val=ar[p]; - if (diff>0) { - int s=p+1; - if (s>size-1) s=size-1; - EventDataType v2=ar[s]; - EventDataType v3=v2-val; - if (v3>0) { - val+=v3*diff; - } - } + QVector::iterator first=ar.begin(); + QVector::iterator last=ar.end(); + QVector::iterator middle = first + int((last-first) * percentile); + std::nth_element(first,middle,last); + EventDataType val=*middle; + +// qSort(ar); +// int p=EventDataType(size)*percentile; +// float p2=EventDataType(size)*percentile; +// float diff=p2-p; +// EventDataType val=ar[p]; +// if (diff>0) { +// int s=p+1; +// if (s>size-1) s=size-1; +// EventDataType v2=ar[s]; +// EventDataType v3=v2-val; +// if (v3>0) { +// val+=v3*diff; +// } + +// } return val; } diff --git a/SleepLib/loader_plugins/resmed_loader.cpp b/SleepLib/loader_plugins/resmed_loader.cpp index 35beba74..badd823c 100644 --- a/SleepLib/loader_plugins/resmed_loader.cpp +++ b/SleepLib/loader_plugins/resmed_loader.cpp @@ -762,20 +762,20 @@ int ResmedLoader::Open(QString & path,Profile *profile) if (stredf.lookup.contains("Tid Vol Med")) { sig=stredf.lookup["Tid Vol Med"]; valmed=sig->data[dn]; - sess->setMedian(CPAP_TidalVolume,valmed*sig->gain); - sess->m_gain[CPAP_TidalVolume]=sig->gain; + sess->setMedian(CPAP_TidalVolume,valmed*sig->gain*1000.0); + sess->m_gain[CPAP_TidalVolume]=sig->gain*1000.0; sess->m_valuesummary[CPAP_TidalVolume][valmed]=51; } if (stredf.lookup.contains("Tid Vol 95")) { sig=stredf.lookup["Tid Vol 95"]; val95=sig->data[dn]; - sess->set95p(CPAP_TidalVolume,val95*sig->gain); + sess->set95p(CPAP_TidalVolume,val95*sig->gain*1000.0); sess->m_valuesummary[CPAP_TidalVolume][val95]=45; } if (stredf.lookup.contains("Tid Vol Max")) { sig=stredf.lookup["Tid Vol Max"]; valmax=sig->data[dn]; - sess->setMax(CPAP_TidalVolume,valmax*sig->gain); + sess->setMax(CPAP_TidalVolume,valmax*sig->gain*1000.0); sess->m_valuesummary[CPAP_TidalVolume][valmax]=4; } diff --git a/SleepLib/profiles.cpp b/SleepLib/profiles.cpp index 7235925e..a44916ae 100644 --- a/SleepLib/profiles.cpp +++ b/SleepLib/profiles.cpp @@ -845,28 +845,34 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac if (idx>array.size()-1) idx=array.size()-1; return array[idx]; */ - - int size=array.size(); - if (!size) - return 0; - size--; - qSort(array); - int p=EventDataType(size)*percent; - float p2=EventDataType(size)*percent; - float diff=p2-p; - val=array[p]; - if (diff>0) { - int s=p+1; - if (s>size-1) s=size-1; - EventDataType v2=array[s]; - EventDataType v3=v2-val; - if (v3>0) { - val+=v3*diff; - } - - } + QVector::iterator first=array.begin(); + QVector::iterator last=array.end(); + QVector::iterator middle = first + int((last-first) * percent); + std::nth_element(first,middle,last); + val=*middle; return val; +// int size=array.size(); +// if (!size) +// return 0; +// size--; +// qSort(array); +// int p=EventDataType(size)*percent; +// float p2=EventDataType(size)*percent; +// float diff=p2-p; +// val=array[p]; +// if (diff>0) { +// int s=p+1; +// if (s>size-1) s=size-1; +// EventDataType v2=array[s]; +// EventDataType v3=v2-val; +// if (v3>0) { +// val+=v3*diff; +// } + +// } + +// return val; } diff --git a/SleepLib/session.cpp b/SleepLib/session.cpp index 7e76ed2c..1fbb1e40 100644 --- a/SleepLib/session.cpp +++ b/SleepLib/session.cpp @@ -567,8 +567,7 @@ void Session::updateCountSummary(ChannelID code) qint32 len; for (int i=0;igain(); m_gain[id]=gain; - } else m_gain[id]=0; - - if ((id!=CPAP_FlowRate) && (id!=CPAP_MaskPressure)) + } + if (!((id==CPAP_FlowRate) || (id==CPAP_MaskPressure))) updateCountSummary(id); Min(id); diff --git a/daily.cpp b/daily.cpp index f469348f..d232b611 100644 --- a/daily.cpp +++ b/daily.cpp @@ -934,6 +934,9 @@ void Daily::Load(QDate date) ChannelID code=chans[i]; if (cpap && cpap->channelHasData(code)) { + if (code==CPAP_RespRate) { + int i=5; + } //if (code==CPAP_LeakTotal) suboffset=PROFILEIntentionalLeak"].toDouble(); else suboffset=0; QString tooltip=schema::channel[code].description(); if (!schema::channel[code].units().isEmpty()) tooltip+=" ("+schema::channel[code].units()+")"; diff --git a/docs/channels.xml b/docs/channels.xml index fba680dd..7f928d91 100644 --- a/docs/channels.xml +++ b/docs/channels.xml @@ -45,11 +45,11 @@ Important: One id code per item, DO NOT CHANGE ID NUMBERS!!! - - + + - + diff --git a/overview.cpp b/overview.cpp index f243b42d..02c42e44 100644 --- a/overview.cpp +++ b/overview.cpp @@ -107,6 +107,7 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : RR=createGraph(tr("Resp. Rate"),tr("Respiratory\nRate\n(breaths/min)")); TV=createGraph(tr("Tidal Volume"),tr("Tidal\nVolume\n(ml)")); MV=createGraph(tr("Minute Vent."),tr("Minute\nVentilation\n(L/min)")); + TGMV=createGraph(tr("Target Vent."),tr("Target\nVentilation\n(L/min)")); PTB=createGraph(tr("Pat. Trig. Br."),tr("Patient\nTriggered\nBreaths\n(%)")); SES=createGraph(tr("Sessions"),tr("Sessions\n(count)")); PULSE=createGraph(tr("Pulse Rate"),tr("Pulse Rate\n(bpm)")); @@ -146,7 +147,7 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : spo2=new SummaryChart(STR_TR_SpO2,GT_LINE); spo2->setMachineType(MT_OXIMETER); spo2->addSlice(OXI_SPO2,QColor("cyan"),ST_WAVG,true); - spo2->addSlice(OXI_SPO2,QColor("light blue"),ST_90P,true,0.95); + spo2->addSlice(OXI_SPO2,QColor("light blue"),ST_PERC,true,0.95); spo2->addSlice(OXI_SPO2,QColor("blue"),ST_MIN,true); SPO2->AddLayer(spo2); @@ -190,21 +191,32 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : rr->addSlice(CPAP_RespRate,QColor("light blue"),ST_MIN,true); rr->addSlice(CPAP_RespRate,QColor("light green"),ST_PERC,true,0.95); rr->addSlice(CPAP_RespRate,QColor("blue"),ST_WAVG,true); - rr->addSlice(CPAP_RespRate,QColor("green"),ST_MAX,true); + rr->addSlice(CPAP_RespRate,QColor("green"),ST_PERC,true,0.999); + // rr->addSlice(CPAP_RespRate,QColor("green"),ST_MAX,true); RR->AddLayer(rr); tv=new SummaryChart(tr("L/b"),GT_LINE); tv->addSlice(CPAP_TidalVolume,QColor("light blue"),ST_MIN,true); tv->addSlice(CPAP_TidalVolume,QColor("light green"),ST_PERC,true,0.95); tv->addSlice(CPAP_TidalVolume,QColor("blue"),ST_WAVG,true); + tv->addSlice(CPAP_TidalVolume,QColor("green"),ST_PERC,true,0.999); TV->AddLayer(tv); mv=new SummaryChart(tr("L/m"),GT_LINE); mv->addSlice(CPAP_MinuteVent,QColor("light blue"),ST_MIN,true); mv->addSlice(CPAP_MinuteVent,QColor("light green"),ST_PERC,true,0.95); mv->addSlice(CPAP_MinuteVent,QColor("blue"),ST_WAVG,true); + mv->addSlice(CPAP_MinuteVent,QColor("green"),ST_PERC,true,0.999); MV->AddLayer(mv); + tgmv=new SummaryChart(tr("L/m"),GT_LINE); + tgmv->addSlice(CPAP_TgMV,QColor("light blue"),ST_MIN,true); + tgmv->addSlice(CPAP_TgMV,QColor("light green"),ST_PERC,true,0.95); + tgmv->addSlice(CPAP_TgMV,QColor("blue"),ST_WAVG,true); + tgmv->addSlice(CPAP_TgMV,QColor("green"),ST_PERC,true,0.999); + TGMV->AddLayer(tgmv); + + ptb=new SummaryChart(tr("%PTB"),GT_LINE); ptb->addSlice(CPAP_PTB,QColor("yellow"),ST_MIN,true); @@ -238,10 +250,10 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : lk=new SummaryChart(tr("Avg Leak"),GT_LINE); lk->addSlice(CPAP_Leak,QColor("dark grey"),ST_PERC,false,0.95); + lk->addSlice(CPAP_Leak,QColor("light blue"),ST_PERC,false,0.5); lk->addSlice(CPAP_Leak,QColor("dark blue"),ST_WAVG,false); - lk->addSlice(CPAP_Leak,QColor("grey"),ST_MAX,false); + lk->addSlice(CPAP_Leak,QColor("grey"),ST_PERC,false,0.999); //lk->addSlice(CPAP_Leak,QColor("dark yellow")); - //pr->addSlice(CPAP_IPAP,QColor("red")); LK->AddLayer(lk); NPB->AddLayer(npb=new SummaryChart(tr("% PB"),GT_BAR)); diff --git a/overview.h b/overview.h index d6ae251a..327472fc 100644 --- a/overview.h +++ b/overview.h @@ -58,8 +58,8 @@ public: \param QString units The units of measurements to show in the popup */ gGraph * createGraph(QString name,QString units="",YTickerType yttype=YT_Number); - gGraph *AHI, *AHIHR, *UC, *US, *PR,*LK,*NPB,*SET,*SES,*RR,*MV,*TV,*PTB,*PULSE,*SPO2,*WEIGHT,*ZOMBIE, *BMI; - SummaryChart *bc,*uc, *us, *pr,*lk,*npb,*set,*ses,*rr,*mv,*tv,*ptb,*pulse,*spo2,*weight,*zombie, *bmi, *ahihr; + gGraph *AHI, *AHIHR, *UC, *US, *PR,*LK,*NPB,*SET,*SES,*RR,*MV,*TV,*PTB,*PULSE,*SPO2,*WEIGHT,*ZOMBIE, *BMI, *TGMV; + SummaryChart *bc,*uc, *us, *pr,*lk,*npb,*set,*ses,*rr,*mv,*tv,*ptb,*pulse,*spo2,*weight,*zombie, *bmi, *ahihr, *tgmv; //! \breif List of SummaryCharts shown on the overview page QVector OverviewCharts;