From d75e8fcebd98bde7a00b8b739df1f00387df2e60 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Sun, 3 Jul 2011 12:43:50 +1000 Subject: [PATCH] More hours() assert fixes --- SleepLib/day.cpp | 1 + SleepLib/loader_plugins/cms50_loader.cpp | 2 + SleepLib/loader_plugins/prs1_loader.cpp | 5 +- SleepLib/loader_plugins/resmed_loader.cpp | 54 ++++++--------------- SleepLib/loader_plugins/resmed_loader.h | 1 + SleepLib/session.cpp | 57 ++++++++--------------- SleepLib/session.h | 13 ++++-- 7 files changed, 49 insertions(+), 84 deletions(-) diff --git a/SleepLib/day.cpp b/SleepLib/day.cpp index d6d226d3..fd8fd4ab 100644 --- a/SleepLib/day.cpp +++ b/SleepLib/day.cpp @@ -230,6 +230,7 @@ EventDataType Day::weighted_avg(MachineCode code,int field) if (s2==0) return 0; return (s1/s2); } +// Total session time in milliseconds qint64 Day::total_time() { d_totaltime=0; diff --git a/SleepLib/loader_plugins/cms50_loader.cpp b/SleepLib/loader_plugins/cms50_loader.cpp index 122dd241..08501f30 100644 --- a/SleepLib/loader_plugins/cms50_loader.cpp +++ b/SleepLib/loader_plugins/cms50_loader.cpp @@ -201,7 +201,9 @@ bool CMS50Loader::OpenSPORFile(QString path,Machine *mach,Profile *profile) int PCnt=0,SCnt=0; //wxDateTime qint64 tt=starttime; + //fixme: Need two lasttime values here.. qint64 lasttime=starttime; + bool first_p=true,first_s=true; for (int i=2;isummary[CPAP_PressureMaxAchieved]=sess->max_event_field(CPAP_Pressure,0); if (sess->summary.find(CPAP_PressureMin)==sess->summary.end()) { sess->summary[CPAP_BrokenSummary]=true; - sess->set_last(sess->first()); + //sess->set_last(sess->first()); if (sess->summary[CPAP_PressureMinAchieved]==sess->summary[CPAP_PressureMaxAchieved]) { sess->summary[CPAP_Mode]=MODE_CPAP; } else { @@ -470,7 +470,8 @@ bool PRS1Loader::OpenSummary(Session *session,QString filename) //float hours=float(duration)/3600.0; //session->set_hours(hours); - session->set_last(date+(duration*1000)); + + session->set_last(date+qint64(duration)*1000L); session->summary[CPAP_PressureMinAchieved]=buffer[0x16]/10.0; session->summary[CPAP_PressureMaxAchieved]=buffer[0x17]/10.0; diff --git a/SleepLib/loader_plugins/resmed_loader.cpp b/SleepLib/loader_plugins/resmed_loader.cpp index daae1e34..601d579f 100644 --- a/SleepLib/loader_plugins/resmed_loader.cpp +++ b/SleepLib/loader_plugins/resmed_loader.cpp @@ -106,6 +106,8 @@ bool EDFParser::Parse() if (!ok) return false; + enddate=startdate+dur_data_record*qint64(num_data_records); + // this could be loaded quicker by transducer_type[signal] etc.. @@ -374,19 +376,11 @@ bool ResmedLoader::LoadEVE(Session *sess,EDFParser &edf) //Event *e; totaldur=edf.GetNumDataRecords()*edf.GetDuration(); + sess->set_first(edf.startdate); + if (edf.enddate>edf.startdate) sess->set_last(edf.enddate); for (int s=0;snr*edf.GetNumDataRecords()*2; - if (!sess->first()) { - sess->set_first(edf.startdate); - if (totaldur>0) { - sess->set_last(edf.startdate+totaldur); - //sess->set_hours(totaldur/3600.0); - } - } - -// totaldur/=3600.0; - //t.sprintf("EVE: %li %.2f",recs,totaldur); //qDebug() << edf.edfsignals[s]->label << " " << t; data=(char *)edf.edfsignals[s]->data; pos=0; @@ -427,7 +421,6 @@ bool ResmedLoader::LoadEVE(Session *sess,EDFParser &edf) qDebug() << "Faulty EDF EVE file (at %" << pos << ") " << edf.filename; break; } - //duration*=1000; } while ((data[pos]==20) && (posAddEvent(new Event(tt,code,fields,1)); } else { if (t!="recording starts") { @@ -473,9 +466,12 @@ bool ResmedLoader::LoadEVE(Session *sess,EDFParser &edf) bool ResmedLoader::LoadBRP(Session *sess,EDFParser &edf) { QString t; + sess->set_first(edf.startdate); + sess->set_last(edf.enddate); + qint64 duration=edf.GetNumDataRecords()*edf.GetDuration(); + for (int s=0;snr*edf.GetNumDataRecords(); - qint64 duration=edf.GetNumDataRecords()*edf.GetDuration(); MachineCode code; if (edf.edfsignals[s]->label=="Flow") code=CPAP_FlowRate; else if (edf.edfsignals[s]->label=="Mask Pres") code=CPAP_MaskPressure; @@ -483,11 +479,6 @@ bool ResmedLoader::LoadBRP(Session *sess,EDFParser &edf) qDebug() << "Unknown Signal " << edf.edfsignals[s]->label; continue; } - if (!sess->first()) { - sess->set_first(edf.startdate); - sess->set_last(edf.startdate+duration); - //sess->set_hours(duration/3600.0); - } Waveform *w=new Waveform(edf.startdate,code,edf.edfsignals[s]->data,recs,duration,edf.edfsignals[s]->digital_minimum,edf.edfsignals[s]->digital_maximum); edf.edfsignals[s]->data=NULL; // so it doesn't get deleted when edf gets trashed. sess->AddWaveform(w); @@ -502,31 +493,22 @@ void ResmedLoader::ToTimeDelta(Session *sess,EDFParser &edf, qint16 *data, Machi double rate=(duration/recs); // milliseconds per record double tt=edf.startdate; EventDataType c,last; - //return; - Event *e=new Event(tt,code,&c,1); for (int i=0;iAddEvent(e); - event_cnt++; + sess->AddEvent(new Event(tt,code,&c,1)); first=false; } else { if (last!=c) { - e=new Event(tt,code,&c,1); - sess->AddEvent(e); - event_cnt++; - + sess->AddEvent(new Event(tt,code,&c,1)); } } tt+=rate; last=c; } - e=new Event(tt,code,&c,1); - sess->AddEvent(e); // add one at the end.. - event_cnt++; + sess->AddEvent(new Event(tt,code,&c,1)); // add one at the end.. } bool ResmedLoader::LoadSAD(Session *sess,EDFParser &edf) { @@ -543,15 +525,12 @@ bool ResmedLoader::LoadPLD(Session *sess,EDFParser &edf) //qDebug(edf.edfsignals[MaskPres]->label.toLatin1()); + sess->set_first(edf.startdate); + sess->set_last(edf.enddate); + qint64 duration=edf.GetNumDataRecords()*edf.GetDuration(); QString t; for (int s=0;snr*edf.GetNumDataRecords(); - qint64 duration=edf.GetNumDataRecords()*edf.GetDuration(); - if (!sess->first()) { - sess->set_first(edf.startdate); - sess->set_last(edf.startdate+duration); - //sess->set_hours(duration/3600.0); - } MachineCode code; // if (s==TherapyPres) { // for (int i=0;idata[i]); @@ -564,19 +543,16 @@ bool ResmedLoader::LoadPLD(Session *sess,EDFParser &edf) ToTimeDelta(sess,edf,edf.edfsignals[s]->data, code,recs,duration,50.0); //50.0 } else if (edf.edfsignals[s]->label=="MV") { code=CPAP_MinuteVentilation; - //ToTimeDelta(mach,sess,edf,edf.edfsignals[s]->data, code,recs,duration,1.0); Waveform *w=new Waveform(edf.startdate,code,edf.edfsignals[s]->data,recs,duration,edf.edfsignals[s]->digital_minimum,edf.edfsignals[s]->digital_maximum); edf.edfsignals[s]->data=NULL; // so it doesn't get deleted when edf gets trashed. sess->AddWaveform(w); } else if (edf.edfsignals[s]->label=="RR") { code=CPAP_RespiratoryRate; - //ToTimeDelta(mach,sess,edf,edf.edfsignals[s]->data, code,recs,duration,1.0); Waveform *w=new Waveform(edf.startdate,code,edf.edfsignals[s]->data,recs,duration,edf.edfsignals[s]->digital_minimum,edf.edfsignals[s]->digital_maximum); edf.edfsignals[s]->data=NULL; // so it doesn't get deleted when edf gets trashed. sess->AddWaveform(w); } else if (edf.edfsignals[s]->label=="Vt") { code=CPAP_TidalVolume; - //ToTimeDelta(mach,sess,edf,edf.edfsignals[s]->data, code,recs,duration,1.0); Waveform *w=new Waveform(edf.startdate,code,edf.edfsignals[s]->data,recs,duration,edf.edfsignals[s]->digital_minimum,edf.edfsignals[s]->digital_maximum); edf.edfsignals[s]->data=NULL; // so it doesn't get deleted when edf gets trashed. sess->AddWaveform(w); diff --git a/SleepLib/loader_plugins/resmed_loader.h b/SleepLib/loader_plugins/resmed_loader.h index d7531b5b..7d05f887 100644 --- a/SleepLib/loader_plugins/resmed_loader.h +++ b/SleepLib/loader_plugins/resmed_loader.h @@ -90,6 +90,7 @@ public: QString recordingident; QString serialnumber; qint64 startdate; + qint64 enddate; QString reserved44; }; diff --git a/SleepLib/session.cpp b/SleepLib/session.cpp index d2a0ad69..86c03a98 100644 --- a/SleepLib/session.cpp +++ b/SleepLib/session.cpp @@ -44,7 +44,7 @@ double Session::min_event_field(MachineCode mc,int field) double min=0; vector::iterator i; for (i=events[mc].begin(); i!=events[mc].end(); i++) { - if (field>(*i)->e_fields) throw BoundsError(); + assert(field<(*i)->e_fields); if (first) { first=false; min=(*(*i))[field]; @@ -62,7 +62,7 @@ double Session::max_event_field(MachineCode mc,int field) double max=0; vector::iterator i; for (i=events[mc].begin(); i!=events[mc].end(); i++) { - if (field>(*i)->e_fields) throw BoundsError(); + assert(field<(*i)->e_fields); if (first) { first=false; max=(*(*i))[field]; @@ -81,7 +81,7 @@ double Session::sum_event_field(MachineCode mc,int field) vector::iterator i; for (i=events[mc].begin(); i!=events[mc].end(); i++) { - if (field>(*i)->e_fields) throw BoundsError(); + assert(field<(*i)->e_fields); sum+=(*(*i))[field]; } return sum; @@ -95,7 +95,7 @@ double Session::avg_event_field(MachineCode mc,int field) vector::iterator i; for (i=events[mc].begin(); i!=events[mc].end(); i++) { - if (field>(*i)->e_fields) throw BoundsError(); + assert(field<(*i)->e_fields); sum+=(*(*i))[field]; cnt++; } @@ -157,11 +157,11 @@ double Session::weighted_avg_event_field(MachineCode mc,int field) for (i=events[mc].begin(); i!=events[mc].end(); i++) { Event & e =(*(*i)); val=e[field]*mult; - if (field > e.e_fields) throw BoundsError(); + assert(fieldmax_slots) { qWarning("max_slots to small in Session::weighted_avg_event_fied()"); return 0; @@ -207,13 +207,13 @@ void Session::AddEvent(Event * e) void Session::AddWaveform(Waveform *w) { waveforms[w->code()].push_back(w); - /* if (s_last.isValid()) { + if (!s_last) { if (w->start()start(); if (w->end()>s_last) s_last=w->end(); } else { s_first=w->start(); s_last=w->end(); - } */ + } // Could parse the flow data for Breaths per minute info here.. } @@ -243,26 +243,7 @@ void Session::TrashWaveforms() } -const int max_pack_size=128; -/*template -int pack(char * buf,T * var) -{ - int c=0; - int s=sizeof(T); - if (s>max_pack_size) return 0; - - char * dat=(char *)var; - if (IsPlatformLittleEndian()) { - for (int i=0; is_first); + if (!s_last) s_last=d; + else if (s_last