Always precalc RDI where available rather than force recalculation each time it's changed, version bump to avoid upgrade problems for the stray mac version

This commit is contained in:
Mark Watkins 2012-01-10 20:00:08 +10:00
parent 99b0d8c846
commit f9c1fa27c5
8 changed files with 120 additions and 44 deletions

View File

@ -727,6 +727,8 @@ void calcRespRate(Session *session, FlowParser * flowparser)
EventDataType calcAHI(Session *session,qint64 start, qint64 end)
{
bool rdi=PROFILE.general->calculateRDI();
double hours,ahi,cnt;
if (start<0) {
// much faster..
@ -736,6 +738,10 @@ EventDataType calcAHI(Session *session,qint64 start, qint64 end)
+session->count(CPAP_ClearAirway)
+session->count(CPAP_Apnea);
if (rdi) {
cnt+=session->count(CPAP_RERA);
}
ahi=cnt/hours;
} else {
hours=double(end-start)/3600000L;
@ -745,6 +751,10 @@ EventDataType calcAHI(Session *session,qint64 start, qint64 end)
+session->rangeCount(CPAP_ClearAirway,start,end)
+session->rangeCount(CPAP_Apnea,start,end);
if (rdi) {
cnt+=session->rangeCount(CPAP_RERA,start,end);
}
ahi=cnt/hours;
}
return ahi;
@ -752,6 +762,10 @@ EventDataType calcAHI(Session *session,qint64 start, qint64 end)
int calcAHIGraph(Session *session)
{
bool calcrdi=session->machine()->GetClass()=="PRS1";
//PROFILE.general->calculateRDI()
const qint64 window_step=30000; // 30 second windows
double window_size=p_profile->cpap->AHIWindow();
qint64 window_size_ms=window_size*60000L;
@ -759,27 +773,46 @@ int calcAHIGraph(Session *session)
bool zeroreset=p_profile->cpap->AHIReset();
if (session->machine()->GetType()!=MT_CPAP) return 0;
if (session->eventlist.contains(CPAP_AHI)) return 0; // abort if already there
bool hasahi=session->eventlist.contains(CPAP_AHI);
bool hasrdi=session->eventlist.contains(CPAP_RDI);
if (hasahi && hasrdi)
return 0; // abort if already there
if (!(!hasahi && !hasrdi)) {
session->destroyEvent(CPAP_AHI);
session->destroyEvent(CPAP_RDI);
}
if (!session->channelExists(CPAP_Obstructive) &&
!session->channelExists(CPAP_Hypopnea) &&
!session->channelExists(CPAP_Apnea) &&
!session->channelExists(CPAP_ClearAirway)) return 0;
!session->channelExists(CPAP_ClearAirway) &&
!session->channelExists(CPAP_RERA)
) return 0;
qint64 first=session->first(),
last=session->last(),
f;
EventList *AHI=new EventList(EVL_Event);
AHI->setGain(0.02);
session->eventlist[CPAP_AHI].push_back(AHI);
EventDataType ahi;
EventList *RDI=NULL;
if (calcrdi) {
RDI=new EventList(EVL_Event);
RDI->setGain(0.02);
session->eventlist[CPAP_RDI].push_back(RDI);
}
EventDataType ahi,rdi;
qint64 ti=first,lastti=first;
double avg=0;
double avgahi=0;
double avgrdi=0;
int cnt=0;
double events;
@ -796,12 +829,18 @@ int calcAHIGraph(Session *session)
+session->rangeCount(CPAP_ClearAirway,ti,t)
+session->rangeCount(CPAP_Apnea,ti,t);
//ahi=calcAHI(session,ti,t)* hours;
ahi = events / hours;
AHI->AddEvent(t,ahi * 50);
avg+=ahi;
avgahi+=ahi;
if (calcrdi) {
events+=session->rangeCount(CPAP_RERA,ti,t);
rdi=events / hours;
RDI->AddEvent(t,rdi * 50);
avgrdi+=rdi;
}
cnt++;
}
lastti=ti;
@ -810,26 +849,46 @@ int calcAHIGraph(Session *session)
} else {
for (ti=first;ti<last;ti+=window_step) {
// if (ti>last) {
//// AHI->AddEvent(last,ahi);
//// avg+=ahi;
//// cnt++;
// break;
// }
f=ti-window_size_ms;
ahi=calcAHI(session,f,ti);
avg+=ahi;
cnt++;
//hours=window_size; //double(ti-f)/3600000L;
events=session->rangeCount(CPAP_Obstructive,f,ti)
+session->rangeCount(CPAP_Hypopnea,f,ti)
+session->rangeCount(CPAP_ClearAirway,f,ti)
+session->rangeCount(CPAP_Apnea,f,ti);
ahi=events/hours;
avgahi+=ahi;
AHI->AddEvent(ti,ahi * 50);
if (calcrdi) {
events+=session->rangeCount(CPAP_RERA,f,ti);
rdi=events/hours;
RDI->AddEvent(ti,rdi * 50);
avgrdi+=rdi;
}
cnt++;
lastti=ti;
ti+=window_step;
}
}
AHI->AddEvent(lastti,0);
if (!cnt) avg=0; else avg/=double(cnt);
session->setAvg(CPAP_AHI,avg);
if (calcrdi)
RDI->AddEvent(lastti,0);
return AHI->count();
if (!cnt) {
avgahi=0;
avgrdi=0;
} else {
avgahi/=double(cnt);
avgrdi/=double(cnt);
}
cnt++;
session->setAvg(CPAP_AHI,avgahi);
if (calcrdi)
session->setAvg(CPAP_RDI,avgrdi);
return cnt;
}
int calcLeaks(Session *session)

View File

@ -336,7 +336,7 @@ bool Machine::Save()
Session *s=m_savelist.at(i);
s->UpdateSummaries();
s->Store(path);
s->TrashEvents();
//s->TrashEvents();
savelistCnt++;
}

View File

@ -58,6 +58,10 @@ public:
const QString & description() { return m_description; }
const QString & label() { return m_label; }
const QString & units() { return m_unit; }
void setLabel(QString label) { m_label=label; }
void setUnit(QString unit) { m_unit=unit; }
void setDescription(QString desc) { m_description=desc; }
QString option(int i) {
if (m_options.contains(i))
return m_options[i];

View File

@ -234,7 +234,8 @@ Daily::Daily(QWidget *parent,gGraphView * shared)
pc->addPlot(CPAP_IPAPHi,Qt::darkRed,square);
if (PROFILE.general->calculateRDI()) {
AHI->AddLayer(AddCPAP(new AHIChart(QColor("#37a24b"))));
AHI->AddLayer(AddCPAP(new gLineChart(CPAP_RDI,QColor("light green"),square)));
// AHI->AddLayer(AddCPAP(new AHIChart(QColor("#37a24b"))));
} else {
AHI->AddLayer(AddCPAP(new gLineChart(CPAP_AHI,QColor("light green"),square)));
}

View File

@ -260,6 +260,12 @@ void MainWindow::Startup()
void MainWindow::on_action_Import_Data_triggered()
{
if (m_inRecalculation) {
Notify("Access to Import has been blocked while recalculations are in progress.");
return;
}
QStringList importLocations;
{
QString filename=PROFILE.Get("{DataFolder}/ImportLocations.txt");
@ -2483,13 +2489,9 @@ void MainWindow::doReprocessEvents()
Session *sess;
Day *day;
//FlowParser flowparser;
if (m_restartRequired) {
QMessageBox::information(this,"Restart Required",QString("The application will automatically restart after the following reindexing operation"),QMessageBox::Ok);
}
mainwin->Notify("Performance will be degraded during these recalculations.","Recalculating Indices");
bool isopen;
// For each day in history
int daycount=first.daysTo(date);
int idx=0;
@ -2501,12 +2503,12 @@ void MainWindow::doReprocessEvents()
qprogress->setValue(0);
qprogress->setVisible(true);
}
QDate current=daily->getDate();
do {
day=PROFILE.GetDay(date,MT_CPAP);
if (day) {
for (int i=0;i<day->size();i++) {
sess=(*day)[i];
isopen=sess->eventsLoaded();
// Load the events
sess->OpenEvents();
@ -2521,6 +2523,7 @@ void MainWindow::doReprocessEvents()
// AHI flags
sess->destroyEvent(CPAP_AHI);
sess->destroyEvent(CPAP_RDI);
sess->SetChanged(true);
//sess->machine()->SaveSession(sess);
@ -2534,6 +2537,7 @@ void MainWindow::doReprocessEvents()
// }
} while (date>=first);
qstatus->setText(tr("Recalculating Summaries"));
for (int i=0;i<machines.size();i++) {
machines.at(i)->Save();
@ -2541,12 +2545,15 @@ void MainWindow::doReprocessEvents()
qstatus->setText(tr(""));
qprogress->setVisible(false);
if (!m_restartRequired) {
if (overview) overview->ReloadGraphs();
daily->ReloadGraphs();
} else {
RestartApplication();
}
m_inRecalculation=false;
mainwin->Notify("Recalculations are now complete.","Recalculating Indices");
if (m_restartRequired) {
QMessageBox::information(this,"Restart Required",QString("Recalculations are complete, the application now needs to restart to display the changes."),QMessageBox::Ok);
RestartApplication();
return;
} else {
Notify("Recalculations are now complete.","Task Completed");
daily->LoadDate(current);
if (overview) overview->ReloadGraphs();
}
}

View File

@ -89,12 +89,13 @@ Overview::Overview(QWidget *parent,gGraphView * shared) :
layout->layout();
// TODO: Automate graph creation process
ChannelID ahicode=PROFILE.general->calculateRDI() ? CPAP_RDI : CPAP_AHI;
// The following code (to the closing marker) is crap --->
if (PROFILE.general->calculateRDI())
if (ahicode==CPAP_RDI)
AHI=createGraph(tr("RDI"),"Respiratory\nDisturbance\nIndex");
else
AHI=createGraph(tr("AHI"),tr("Apnea\nHypopnea\nIndex"));
UC=createGraph(tr("Usage"),tr("Usage\n(hours)"));
@ -103,7 +104,11 @@ Overview::Overview(QWidget *parent,gGraphView * shared) :
SET=createGraph(tr("Settings"),("Settings"));
LK=createGraph(tr("Leaks"),tr("Leak Rate\n(L/min)"));
NPB=createGraph(tr("% in PB"),tr("Periodic\nBreathing\n(% of night)"));
AHIHR=createGraph(tr("AHI/Hour"),tr("AHI Events/Hour\n(ahi/hr)"));
if (ahicode==CPAP_RDI) {
AHIHR=createGraph(tr("Peak RDI"),tr("Peak RDI\nShows RDI Clusters\n(RDI/hr)"));
} else {
AHIHR=createGraph(tr("Peak AHI"),tr("Peak AHI\nShows AHI Clusters\n(AHI/hr)"));
}
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)"));
@ -117,9 +122,9 @@ Overview::Overview(QWidget *parent,gGraphView * shared) :
BMI=createGraph(STR_TR_BMI,tr("Body\nMass\nIndex"));
ZOMBIE=createGraph(tr("Zombie"),tr("How you felt\n(0-10)"));
ahihr=new SummaryChart(tr("AHI/Hr"),GT_LINE);
ahihr->addSlice(CPAP_AHI,QColor("blue"),ST_MAX);
ahihr->addSlice(CPAP_AHI,QColor("orange"),ST_WAVG);
ahihr=new SummaryChart(tr("Events/Hr"),GT_LINE);
ahihr->addSlice(ahicode,QColor("blue"),ST_MAX);
ahihr->addSlice(ahicode,QColor("orange"),ST_WAVG);
AHIHR->AddLayer(ahihr);
weight=new SummaryChart(STR_TR_Weight,GT_LINE);
@ -164,7 +169,7 @@ Overview::Overview(QWidget *parent,gGraphView * shared) :
ses->addSlice(NoChannel,QColor("blue"),ST_SESSIONS);
SES->AddLayer(ses);
if (PROFILE.general->calculateRDI())
if (ahicode==CPAP_RDI)
bc=new SummaryChart(tr("RDI"),GT_BAR);
else
bc=new SummaryChart(tr("AHI"),GT_BAR);

View File

@ -292,7 +292,7 @@ bool PreferencesDialog::Save()
needs_restart=true;
}
if (profile->general->calculateRDI() != ui->AddRERAtoAHI->isChecked()) {
recalc_events=true;
//recalc_events=true;
needs_restart=true;
}
if (profile->cpap->userEventFlagging() &&
@ -312,7 +312,7 @@ bool PreferencesDialog::Save()
recalc_events=true;
if (recalc_events) {
if (QMessageBox::question(this,tr("Data Reindex Required"),tr("A data reindexing proceedure is required to apply these changes.\n\nAre you sure you want to make these changes?"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::No) {
if (QMessageBox::question(this,tr("Data Reindex Required"),tr("A data reindexing proceedure is required to apply these changes. This operation may take a couple of minutes to complete.\n\nAre you sure you want to make these changes?"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::No) {
return false;
}
} else if (needs_restart) {

View File

@ -5,7 +5,7 @@
const int major_version=0;
const int minor_version=9;
const int revision_number=0;
const int revision_number=1;
const QString VersionString=QString().sprintf("%i.%i.%i",major_version,minor_version,revision_number);
const QString ReleaseStatus="beta";