From e746834eb111dbe2c8ffc2306da09fe451b42ae1 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Fri, 13 Jan 2012 09:34:52 +1000 Subject: [PATCH] Can now set preference calculations for mid (median, average, wavg), percentile (90/95%/etc) and max (true max/99%) --- Graphs/gSummaryChart.cpp | 23 +++++++----- daily.cpp | 77 ++++++++++++++++++++++++++++++++++------ docs/release_notes.html | 1 + docs/update_notes.html | 2 ++ mainwindow.cpp | 20 +++++++---- overview.cpp | 60 +++++++++++++------------------ 6 files changed, 121 insertions(+), 62 deletions(-) diff --git a/Graphs/gSummaryChart.cpp b/Graphs/gSummaryChart.cpp index 8a401553..27254085 100644 --- a/Graphs/gSummaryChart.cpp +++ b/Graphs/gSummaryChart.cpp @@ -62,24 +62,31 @@ void SummaryChart::SetDay(Day * nullday) m_type.clear(); m_typeval.clear(); + float perc=PROFILE.general->prefCalcPercentile(); + int mididx=PROFILE.general->prefCalcMiddle(); + SummaryType mid; + if (mididx==0) mid=ST_PERC; + if (mididx==1) mid=ST_WAVG; + if (mididx==2) mid=ST_AVG; + if (cpapmode>=MODE_ASV) { addSlice(CPAP_EPAP,QColor("green"),ST_SETMIN); addSlice(CPAP_IPAPLo,QColor("light blue"),ST_SETMIN); - addSlice(CPAP_IPAP,QColor("cyan"),ST_PERC,0.5); - addSlice(CPAP_IPAP,QColor("dark cyan"),ST_PERC,0.95); + addSlice(CPAP_IPAP,QColor("cyan"),mid,0.5); + addSlice(CPAP_IPAP,QColor("dark cyan"),ST_PERC,perc); //addSlice(CPAP_IPAP,QColor("light blue"),ST_PERC,0.95); addSlice(CPAP_IPAPHi,QColor("blue"),ST_SETMAX); } else if (cpapmode>=MODE_BIPAP) { addSlice(CPAP_EPAP,QColor("green"),ST_SETMIN); - addSlice(CPAP_EPAP,QColor("light green"),ST_PERC,0.95); - addSlice(CPAP_IPAP,QColor("light cyan"),ST_PERC,0.5); - addSlice(CPAP_IPAP,QColor("light blue"),ST_PERC,0.95); + addSlice(CPAP_EPAP,QColor("light green"),ST_PERC,perc); + addSlice(CPAP_IPAP,QColor("light cyan"),mid,0.5); + addSlice(CPAP_IPAP,QColor("light blue"),ST_PERC,perc); addSlice(CPAP_IPAP,QColor("blue"),ST_SETMAX); } else if (cpapmode>=MODE_APAP) { addSlice(CPAP_PressureMin,QColor("orange"),ST_SETMIN); - addSlice(CPAP_Pressure,QColor("dark green"),ST_PERC,0.5); - addSlice(CPAP_Pressure,QColor("grey"),ST_PERC,0.95); + addSlice(CPAP_Pressure,QColor("dark green"),mid,0.5); + addSlice(CPAP_Pressure,QColor("grey"),ST_PERC,perc); addSlice(CPAP_PressureMax,QColor("red"),ST_SETMAX); } else { addSlice(CPAP_Pressure,QColor("dark green"),ST_SETWAVG); @@ -167,7 +174,7 @@ void SummaryChart::SetDay(Day * nullday) if (code==CPAP_Pressure) { if ((cpapmode>MODE_CPAP) && (mode==MODE_CPAP)) { hascode=false; - if ((type==ST_PERC) && (typeval==0.5)) { + if ((type==ST_WAVG) || (type==ST_AVG) || ((type==ST_PERC) && (typeval==0.5))) { type=ST_SETWAVG; hascode=true; } diff --git a/daily.cpp b/daily.cpp index a05ee5ce..6a9a2fe4 100644 --- a/daily.cpp +++ b/daily.cpp @@ -717,6 +717,11 @@ void Daily::Load(QDate date) bool isBrick=false; updateGraphCombo(); + int mididx=PROFILE.general->prefCalcMiddle(); + SummaryType ST_mid; + if (mididx==0) ST_mid=ST_PERC; + if (mididx==1) ST_mid=ST_WAVG; + if (mididx==2) ST_mid=ST_AVG; if (cpap) { float hours=cpap->hours(); @@ -936,6 +941,15 @@ void Daily::Load(QDate date) html+="\n"; float percentile=PROFILE.general->prefCalcPercentile()/100.0; + + SummaryType ST_max=PROFILE.general->prefCalcMax() ? ST_MAX : ST_PERC; + const EventDataType maxperc=0.995; + + QString midname; + if (ST_mid==ST_WAVG) midname=tr("Avg"); + else if (ST_mid==ST_AVG) midname=tr("Avg"); + else if (ST_mid==ST_PERC) midname=tr("Med"); + if ((cpap && !isBrick && (cpap->hours()>0)) || oxi) { html+="\n"; @@ -944,7 +958,7 @@ void Daily::Load(QDate date) html+=QString("") .arg(tr("Channel")) .arg(tr("Min")) - .arg(tr("Med")) + .arg(midname) .arg(tr("%1%").arg(percentile*100,0,'f',0)) .arg(tr("Max")); ChannelID chans[]={ @@ -956,7 +970,7 @@ void Daily::Load(QDate date) int numchans=sizeof(chans)/sizeof(ChannelID); //int suboffset=0; int ccnt=0; - EventDataType wavg,med,perc,mx,mn; + EventDataType tmp,med,perc,mx,mn; for (int i=0;iMax(code); + if (ST_max==ST_MAX) { + mx=cpap->Max(code); + } else { + mx=cpap->percentile(code,maxperc); + } mn=cpap->Min(code); perc=cpap->percentile(code,percentile); - med=cpap->percentile(code,0.5); - wavg=cpap->wavg(code); - if (wavg>0 || mx==0) { - tooltip+=QString("
Avg: %1").arg(wavg,0,'f',2); + + if (ST_mid==ST_PERC) { + med=cpap->percentile(code,0.5); + tmp=cpap->wavg(code); + if (tmp>0 || mx==0) { + tooltip+=QString("
W-Avg: %1").arg(tmp,0,'f',2); + } + } else if (ST_mid==ST_WAVG) { + med=cpap->wavg(code); + tmp=cpap->percentile(code,0.5); + if (tmp>0 || mx==0) { + tooltip+=QString("
Median: %1").arg(tmp,0,'f',2); + } + } else if (ST_mid==ST_AVG) { + med=cpap->avg(code); + tmp=cpap->percentile(code,0.5); + if (tmp>0 || mx==0) { + tooltip+=QString("
Median: %1").arg(tmp,0,'f',2); + } } html+=QString("
") @@ -988,15 +1021,37 @@ void Daily::Load(QDate date) if (oxi && oxi->channelHasData(code)) { QString tooltip=schema::channel[code].description(); if (!schema::channel[code].units().isEmpty()) tooltip+=" ("+schema::channel[code].units()+")"; - wavg=oxi->wavg(code); + //wavg=oxi->wavg(code); mx=oxi->Max(code); mn=oxi->Min(code); perc=oxi->percentile(code,percentile); - med=oxi->percentile(code,0.5); - if ((med>0 && wavg>0) || (med==0)) { - tooltip+=QString("
Avg: %1").arg(wavg,0,'f',2); + //med=oxi->percentile(code,0.5); + + if (ST_mid==ST_PERC) { + med=oxi->percentile(code,0.5); + tmp=oxi->wavg(code); + if (tmp>0 || mx==0) { + tooltip+=QString("
W-Avg: %1").arg(tmp,0,'f',2); + } + } else if (ST_mid==ST_WAVG) { + med=oxi->wavg(code); + tmp=oxi->percentile(code,0.5); + if (tmp>0 || mx==0) { + tooltip+=QString("
Median: %1").arg(tmp,0,'f',2); + } + } else if (ST_mid==ST_AVG) { + med=oxi->avg(code); + tmp=oxi->percentile(code,0.5); + if (tmp>0 || mx==0) { + tooltip+=QString("
Median: %1").arg(tmp,0,'f',2); + } } + +// if ((med>0 && wavg>0) || (med==0)) { +// tooltip+=QString("
Avg: %1").arg(wavg,0,'f',2); +// } + html+=QString("") .arg(QString("%2%3") .arg(QString::number(code)).arg(schema::channel[code].label()).arg(tooltip)) diff --git a/docs/release_notes.html b/docs/release_notes.html index 3537bb2b..88b3ef73 100644 --- a/docs/release_notes.html +++ b/docs/release_notes.html @@ -13,6 +13,7 @@
  • Fixes Overview AHI chart showing "No Data" on 0.00 days.
  • Fixes crash after using Preferences before importing first data.
  • Fixes first minute of Resp. Rate & Minute Vent calcs not showing data. (You will have to Data->Advanced->Purge CPAP Data and then reimport if you want this, as recalc won't do it)
  • +
  • Cursor up/down zoom did not take into account hidden graphs
  • Would you like to help test breaky stuff?

    Advanced users who are willing, can now help test future updates, so we can hopefully avoid unleashing unintentonally buggy versions on everyone else.

    diff --git a/docs/update_notes.html b/docs/update_notes.html index c4136edd..034d90c8 100644 --- a/docs/update_notes.html +++ b/docs/update_notes.html @@ -11,6 +11,8 @@
  • Preliminary ZEO CSV Support
  • Fixes Overview AHI chart showing "No Data" on 0.00 days.
  • Fixes crash after using Preferences before importing first data.
  • +
  • Cursor up/down zoom did not take into account hidden graphs
  • +
  • Fixes first minute of Resp. Rate & Minute Vent calcs not showing data. (You will have to Data->Advanced->Purge CPAP Data and then reimport if you want this, as recalc won't do it)
  • Have fun!

    diff --git a/mainwindow.cpp b/mainwindow.cpp index c59f8db3..c6d825dc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -649,7 +649,13 @@ void MainWindow::on_summaryButton_clicked() CPAPMode cpapmode=(CPAPMode)p_profile->calcSettingsMax(CPAP_Mode,MT_CPAP,firstcpap,lastcpap); - float percentile=0.95; + float percentile=PROFILE.general->prefCalcPercentile()/100.0; + +// int mididx=PROFILE.general->prefCalcMiddle(); +// SummaryType ST_mid; +// if (mididx==0) ST_mid=ST_PERC; +// if (mididx==1) ST_mid=ST_WAVG; +// if (mididx==2) ST_mid=ST_AVG; QString ahitxt; if (PROFILE.general->calculateRDI()) { @@ -726,7 +732,7 @@ void MainWindow::on_summaryButton_clicked() .arg(p_profile->calcMin(CPAP_EPAP,MT_CPAP,cpap6month,lastcpap),0,'f',decimals) .arg(p_profile->calcMin(CPAP_EPAP,MT_CPAP,cpapyear,lastcpap),0,'f',decimals); html+=QString("") - .arg(tr("95% EPAP")) + .arg(tr("%1% EPAP").arg(percentile*100.0,0,'f',0)) .arg(p_profile->calcPercentile(CPAP_EPAP,percentile,MT_CPAP),0,'f',decimals) .arg(p_profile->calcPercentile(CPAP_EPAP,percentile,MT_CPAP,cpapweek,lastcpap),0,'f',decimals) .arg(p_profile->calcPercentile(CPAP_EPAP,percentile,MT_CPAP,cpapmonth,lastcpap),0,'f',decimals) @@ -740,7 +746,7 @@ void MainWindow::on_summaryButton_clicked() .arg(p_profile->calcMax(CPAP_IPAP,MT_CPAP,cpap6month,lastcpap),0,'f',decimals) .arg(p_profile->calcMax(CPAP_IPAP,MT_CPAP,cpapyear,lastcpap),0,'f',decimals); html+=QString("") - .arg(tr("95% IPAP")) + .arg(tr("%1% IPAP").arg(percentile*100.0,0,'f',0)) .arg(p_profile->calcPercentile(CPAP_IPAP,percentile,MT_CPAP),0,'f',decimals) .arg(p_profile->calcPercentile(CPAP_IPAP,percentile,MT_CPAP,cpapweek,lastcpap),0,'f',decimals) .arg(p_profile->calcPercentile(CPAP_IPAP,percentile,MT_CPAP,cpapmonth,lastcpap),0,'f',decimals) @@ -755,7 +761,7 @@ void MainWindow::on_summaryButton_clicked() .arg(p_profile->calcWavg(CPAP_Pressure,MT_CPAP,cpap6month,lastcpap),0,'f',decimals) .arg(p_profile->calcWavg(CPAP_Pressure,MT_CPAP,cpapyear,lastcpap),0,'f',decimals); html+=QString("") - .arg(tr("95% Pressure")) + .arg(tr("%1% Pressure").arg(percentile*100.0,0,'f',0)) .arg(p_profile->calcPercentile(CPAP_Pressure,percentile,MT_CPAP),0,'f',decimals) .arg(p_profile->calcPercentile(CPAP_Pressure,percentile,MT_CPAP,cpapweek,lastcpap),0,'f',decimals) .arg(p_profile->calcPercentile(CPAP_Pressure,percentile,MT_CPAP,cpapmonth,lastcpap),0,'f',decimals) @@ -996,11 +1002,11 @@ void MainWindow::on_summaryButton_clicked() rx.prelset=prelset; rx.machine=mach; if (modecalcPercentile(CPAP_Pressure,0.9,MT_CPAP,first,last); + rx.per1=p_profile->calcPercentile(CPAP_Pressure,percentile,MT_CPAP,first,last); rx.per2=0; } else if (modecalcPercentile(CPAP_EPAP,0.9,MT_CPAP,first,last); - rx.per2=p_profile->calcPercentile(CPAP_IPAP,0.9,MT_CPAP,first,last); + rx.per1=p_profile->calcPercentile(CPAP_EPAP,percentile,MT_CPAP,first,last); + rx.per2=p_profile->calcPercentile(CPAP_IPAP,percentile,MT_CPAP,first,last); } else { rx.per1=p_profile->calcPercentile(CPAP_EPAP,percentile,MT_CPAP,first,last); rx.per2=p_profile->calcPercentile(CPAP_IPAPHi,percentile,MT_CPAP,first,last); diff --git a/overview.cpp b/overview.cpp index 926f546b..d28cc176 100644 --- a/overview.cpp +++ b/overview.cpp @@ -99,6 +99,14 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : UC=createGraph(tr("Usage"),tr("Usage\n(hours)")); float percentile=PROFILE.general->prefCalcPercentile()/100.0; + int mididx=PROFILE.general->prefCalcMiddle(); + SummaryType ST_mid; + if (mididx==0) ST_mid=ST_PERC; + if (mididx==1) ST_mid=ST_WAVG; + if (mididx==2) ST_mid=ST_AVG; + + SummaryType ST_max=PROFILE.general->prefCalcMax() ? ST_MAX : ST_PERC; + const EventDataType maxperc=0.995; US=createGraph(tr("Session Times"),tr("Session Times\n(hours)"),YT_Time); @@ -147,14 +155,14 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : pulse=new SummaryChart(tr("Pulse Rate"),GT_LINE); pulse->setMachineType(MT_OXIMETER); - pulse->addSlice(OXI_Pulse,QColor("red"),ST_WAVG); + pulse->addSlice(OXI_Pulse,QColor("red"),ST_mid,0.5); pulse->addSlice(OXI_Pulse,QColor("pink"),ST_MIN); pulse->addSlice(OXI_Pulse,QColor("orange"),ST_MAX); PULSE->AddLayer(pulse); spo2=new SummaryChart(STR_TR_SpO2,GT_LINE); spo2->setMachineType(MT_OXIMETER); - spo2->addSlice(OXI_SPO2,QColor("cyan"),ST_WAVG); + spo2->addSlice(OXI_SPO2,QColor("cyan"),ST_mid,0.5); spo2->addSlice(OXI_SPO2,QColor("light blue"),ST_PERC,percentile); spo2->addSlice(OXI_SPO2,QColor("blue"),ST_MIN); SPO2->AddLayer(spo2); @@ -195,76 +203,56 @@ Overview::Overview(QWidget *parent,gGraphView * shared) : rr=new SummaryChart(tr("breaths/min"),GT_LINE); rr->addSlice(CPAP_RespRate,QColor("light blue"),ST_MIN); - rr->addSlice(CPAP_RespRate,QColor("blue"),ST_PERC,0.5); + rr->addSlice(CPAP_RespRate,QColor("blue"),ST_mid,0.5); rr->addSlice(CPAP_RespRate,QColor("light green"),ST_PERC,percentile); - rr->addSlice(CPAP_RespRate,QColor("green"),ST_PERC,0.999); + rr->addSlice(CPAP_RespRate,QColor("green"),ST_max,maxperc); // rr->addSlice(CPAP_RespRate,QColor("green"),ST_MAX); RR->AddLayer(rr); tv=new SummaryChart(tr("L/b"),GT_LINE); tv->addSlice(CPAP_TidalVolume,QColor("light blue"),ST_MIN); - tv->addSlice(CPAP_TidalVolume,QColor("blue"),ST_PERC,0.5); + tv->addSlice(CPAP_TidalVolume,QColor("blue"),ST_mid,0.5); tv->addSlice(CPAP_TidalVolume,QColor("light green"),ST_PERC,percentile); - tv->addSlice(CPAP_TidalVolume,QColor("green"),ST_PERC,0.999); + tv->addSlice(CPAP_TidalVolume,QColor("green"),ST_max,maxperc); TV->AddLayer(tv); mv=new SummaryChart(tr("L/m"),GT_LINE); mv->addSlice(CPAP_MinuteVent,QColor("light blue"),ST_MIN); - mv->addSlice(CPAP_MinuteVent,QColor("blue"),ST_PERC,0.5); + mv->addSlice(CPAP_MinuteVent,QColor("blue"),ST_mid,0.5); mv->addSlice(CPAP_MinuteVent,QColor("light green"),ST_PERC,percentile); - mv->addSlice(CPAP_MinuteVent,QColor("green"),ST_PERC,0.999); + mv->addSlice(CPAP_MinuteVent,QColor("green"),ST_max,maxperc); MV->AddLayer(mv); tgmv=new SummaryChart(tr("L/m"),GT_LINE); tgmv->addSlice(CPAP_TgMV,QColor("light blue"),ST_MIN); - tgmv->addSlice(CPAP_TgMV,QColor("blue"),ST_PERC,0.5); + tgmv->addSlice(CPAP_TgMV,QColor("blue"),ST_mid,0.5); tgmv->addSlice(CPAP_TgMV,QColor("light green"),ST_PERC,percentile); - tgmv->addSlice(CPAP_TgMV,QColor("green"),ST_PERC,0.999); + tgmv->addSlice(CPAP_TgMV,QColor("green"),ST_max,maxperc); TGMV->AddLayer(tgmv); ptb=new SummaryChart(tr("%PTB"),GT_LINE); ptb->addSlice(CPAP_PTB,QColor("yellow"),ST_MIN); - ptb->addSlice(CPAP_PTB,QColor("blue"),ST_PERC,0.5); + ptb->addSlice(CPAP_PTB,QColor("blue"),ST_mid,0.5); ptb->addSlice(CPAP_PTB,QColor("light gray"),ST_PERC,percentile); ptb->addSlice(CPAP_PTB,QColor("orange"),ST_WAVG); PTB->AddLayer(ptb); pr=new SummaryChart(STR_TR_Pressure,GT_LINE); - //PR->setRecMinY(4.0); - //PR->setRecMaxY(12.0); - - //CPAPMode mode=(CPAPMode)(int)PROFILE.calcSettingsMax(CPAP_Mode,MT_CPAP,PROFILE.FirstDay(MT_CPAP),PROFILE.LastDay(MT_CPAP)); - -// //if (mode>=MODE_BIPAP) { -// pr->addSlice(CPAP_EPAP,QColor("green"),ST_SETMIN,true); -// pr->addSlice(CPAP_EPAP,QColor("light green"),ST_PERC,true,percentile); - -// pr->addSlice(CPAP_IPAP,QColor("light blue"),ST_PERC,true,percentile); -// pr->addSlice(CPAP_IPAP,QColor("blue"),ST_SETMAX,true); -// //} else if (mode>MODE_CPAP) { -// pr->addSlice(CPAP_PressureMin,QColor("orange"),ST_SETMIN,true); -// pr->addSlice(CPAP_Pressure,QColor("dark green"),ST_WAVG,true); -// //pr->addSlice(CPAP_Pressure,QColor("grey"),ST_90P,true); -// pr->addSlice(CPAP_Pressure,QColor("grey"),ST_PERC,true,percentile); -// pr->addSlice(CPAP_PressureMax,QColor("red"),ST_SETMAX,true); -// //} else { - -// pr->addSlice(CPAP_Pressure,QColor("dark green"),ST_SETWAVG,true); -// //} + // Added in summarychart.. Slightly annoying.. PR->AddLayer(pr); lk=new SummaryChart(tr("Leaks"),GT_LINE); - lk->addSlice(CPAP_Leak,QColor("light blue"),ST_PERC,0.5); + lk->addSlice(CPAP_Leak,QColor("light blue"),ST_mid,0.5); lk->addSlice(CPAP_Leak,QColor("dark grey"),ST_PERC,percentile); //lk->addSlice(CPAP_Leak,QColor("dark blue"),ST_WAVG); - lk->addSlice(CPAP_Leak,QColor("grey"),ST_PERC,0.999); + lk->addSlice(CPAP_Leak,QColor("grey"),ST_max,maxperc); //lk->addSlice(CPAP_Leak,QColor("dark yellow")); LK->AddLayer(lk); totlk=new SummaryChart(tr("Total Leaks"),GT_LINE); - totlk->addSlice(CPAP_LeakTotal,QColor("light blue"),ST_PERC,0.5); + totlk->addSlice(CPAP_LeakTotal,QColor("light blue"),ST_mid,0.5); totlk->addSlice(CPAP_LeakTotal,QColor("dark grey"),ST_PERC,percentile); - totlk->addSlice(CPAP_LeakTotal,QColor("grey"),ST_PERC,0.999); + totlk->addSlice(CPAP_LeakTotal,QColor("grey"),ST_max,maxperc); //tot->addSlice(CPAP_Leak,QColor("dark blue"),ST_WAVG); //tot->addSlice(CPAP_Leak,QColor("dark yellow")); TOTLK->AddLayer(totlk);
     
    %1%2%3%4%5
    %1%6%2%3%4%5
    %1%2%3%4%5
    %1%2%3%4%5%6
    %1%2%3%4%5%6
    %1%2%3%4%5%6