More hours() assert fixes

This commit is contained in:
Mark Watkins 2011-07-03 12:43:50 +10:00
parent cd1b5329ef
commit d75e8fcebd
7 changed files with 49 additions and 84 deletions

View File

@ -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;

View File

@ -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;i<num_records;i+=2) {

View File

@ -339,7 +339,7 @@ int PRS1Loader::OpenMachine(Machine *m,QString path,Profile *profile)
sess->summary[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;

View File

@ -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;s<edf.GetNumSignals();s++) {
recs=edf.edfsignals[s]->nr*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) && (pos<recs)) {
t="";
@ -448,7 +441,7 @@ bool ResmedLoader::LoadEVE(Session *sess,EDFParser &edf)
else if (t=="hypopnea") code=CPAP_Hypopnea;
else if (t=="central apnea") code=CPAP_ClearAirway;
if (code!=MC_UNKNOWN) {
fields[0]=duration;///1000.0;
fields[0]=duration;
sess->AddEvent(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;s<edf.GetNumSignals();s++) {
long recs=edf.edfsignals[s]->nr*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;i<recs;i++) {
c=data[i]/divisor;
if (first) {
e=new Event(tt,code,&c,1);
sess->AddEvent(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;s<edf.GetNumSignals();s++) {
long recs=edf.edfsignals[s]->nr*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;i<recs;i++) qDebug("%04i %i",i,edf.edfsignals[s]->data[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);

View File

@ -90,6 +90,7 @@ public:
QString recordingident;
QString serialnumber;
qint64 startdate;
qint64 enddate;
QString reserved44;
};

View File

@ -44,7 +44,7 @@ double Session::min_event_field(MachineCode mc,int field)
double min=0;
vector<Event *>::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<Event *>::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<Event *>::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<Event *>::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(field<e.e_fields);
if (first) {
first=false;
} else {
int d=(e.e_time-last)/1000;
int d=(e.e_time-last)/1000L;
if (lastval>max_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()<s_first) s_first=w->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 <class T>
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; i<s; i++) {
buf[i]=dat[i];
}
} else {
for (int i=0; i<s; i++) {
buf[s-i]=dat[i];
}
}
return s;
} */
//const int max_pack_size=128;
bool Session::Store(QString path)
// Storing Session Data in our format
@ -300,8 +281,8 @@ bool Session::StoreSummary(QString filename)
f.Pack((quint16)0); // File Type 0 == Summary File
f.Pack((quint16)0); // File Version
quint32 starttime=s_first/1000;
quint32 duration=(s_last-s_first)/1000;
quint32 starttime=s_first/1000L;
quint32 duration=(s_last-s_first)/1000L;
f.Pack(starttime); // Session Start Time
f.Pack(duration); // Duration of sesion in seconds.
@ -393,10 +374,10 @@ bool Session::LoadSummary(QString filename)
if (!f.Unpack(t32)) throw UnpackError(); // Start time
s_first=qint64(t32)*1000;
s_first=qint64(t32)*1000L;
if (!f.Unpack(t32)) throw UnpackError(); // Duration // (16bit==Limited to 18 hours)
s_last=s_first+qint64(t32)*1000;
s_last=s_first+qint64(t32)*1000L;
if (!f.Unpack(sumsize)) throw UnpackError(); // Summary size (number of Machine Code lists)
@ -449,8 +430,8 @@ bool Session::StoreEvents(QString filename)
f.Pack((quint16)1); // File type 1 == Event
f.Pack((quint16)0); // File Version
quint32 starttime=s_first/1000;
quint32 duration=(s_last-s_first)/1000;
quint32 starttime=s_first/1000L;
quint32 duration=(s_last-s_first)/1000L;
f.Pack(starttime);
f.Pack(duration);
@ -527,9 +508,9 @@ bool Session::LoadEvents(QString filename)
// dont give a crap yet..
if (!f.Unpack(t32)) throw UnpackError(); // Start time
s_first=qint64(t32)*1000;
s_first=qint64(t32)*1000L;
if (!f.Unpack(t32)) throw UnpackError(); // Duration // (16bit==Limited to 18 hours)
s_last=s_first+qint64(t32)*1000;
s_last=s_first+qint64(t32)*1000L;
qint16 evsize;
if (!f.Unpack(evsize)) throw UnpackError(); // Summary size (number of Machine Code lists)
@ -590,8 +571,8 @@ bool Session::StoreWaveforms(QString filename)
f.Pack((quint16)2); // File type 2 == Waveform
f.Pack((quint16)0); // File Version
quint32 starttime=s_first/1000;
quint32 duration=(s_last-s_first)/1000;
quint32 starttime=s_first/1000L;
quint32 duration=(s_last-s_first)/1000L;
f.Pack(starttime);
f.Pack(duration);

View File

@ -50,23 +50,26 @@ public:
const SessionID & session() {
return s_session;
};
const qint64 & first() {
qint64 first() {
return s_first;
};
const qint64 & last() {
qint64 last() {
return s_last;
};
void SetSessionID(SessionID s) {
s_session=s;
};
void set_first(qint64 d) {
s_first=d;
if (!s_first) s_first=d;
else if (d<s_first) s_first=d;
};
void set_last(qint64 d) {
s_last=d;
assert(d>s_first);
if (!s_last) s_last=d;
else if (s_last<d) s_last=d;
};
float hours() {
double hours() {
double t=(s_last-s_first)/3600000.0;
return t;
};