ResMed Backup cleanup and Purge CPAP Day fix

This commit is contained in:
Mark Watkins 2013-10-22 21:42:57 +10:00
parent 9dd253136d
commit 0a67a16baa
15 changed files with 238 additions and 112 deletions

View File

@ -149,7 +149,7 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
qint64 clockdrift=qint64(PROFILE.cpap->clockDrift()) * 1000L; qint64 clockdrift=qint64(PROFILE.cpap->clockDrift()) * 1000L;
qint64 drift=0; qint64 drift=0;
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) { for (QList<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) {
if (!(*s)->enabled()) if (!(*s)->enabled())
continue; continue;
drift=((*s)->machine()->GetType()==MT_CPAP) ? clockdrift : 0; drift=((*s)->machine()->GetType()==MT_CPAP) ? clockdrift : 0;

View File

@ -723,7 +723,7 @@ void AHIChart::SetDay(Day *d)
if (!d) return; if (!d) return;
m_miny=9999; m_miny=9999;
QVector<Session *>::iterator s; QList<Session *>::iterator s;
qint64 first=d->first(); qint64 first=d->first();
qint64 last=d->last(); qint64 last=d->last();
qint64 f; qint64 f;

View File

@ -74,7 +74,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
qint64 drift=0; qint64 drift=0;
// For each session, process it's eventlist // For each session, process it's eventlist
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) { for (QList<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
cei=(*s)->eventlist.find(m_code); cei=(*s)->eventlist.find(m_code);
@ -236,7 +236,7 @@ void gLineOverlaySummary::paint(gGraph & w,int left, int top, int width, int hei
double time=0; double time=0;
// Calculate the session time. // Calculate the session time.
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) { for (QList<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
first=(*s)->first(); first=(*s)->first();
last=(*s)->last(); last=(*s)->last();

View File

@ -37,7 +37,7 @@ void gSegmentChart::SetDay(Day *d)
if (!m_day) return; if (!m_day) return;
for (int c=0;c<m_codes.size();c++) { for (int c=0;c<m_codes.size();c++) {
m_values[c]=0; m_values[c]=0;
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end();s++) { for (QList<Session *>::iterator s=m_day->begin();s!=m_day->end();++s) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
int cnt=(*s)->count(m_codes[c]); int cnt=(*s)->count(m_codes[c]);
@ -213,7 +213,7 @@ void gTAPGraph::SetDay(Day *d)
//bool changed; //bool changed;
EventDataType gain=1,offset=0; EventDataType gain=1,offset=0;
QHash<ChannelID,QVector<EventList *> >::iterator ei; QHash<ChannelID,QVector<EventList *> >::iterator ei;
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end();s++) { for (QList<Session *>::iterator s=m_day->begin();s!=m_day->end();++s) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
if ((ei=(*s)->eventlist.find(m_code))==(*s)->eventlist.end()) continue; if ((ei=(*s)->eventlist.find(m_code))==(*s)->eventlist.end()) continue;

View File

@ -17,8 +17,8 @@ Day::Day(Machine *m)
} }
Day::~Day() Day::~Day()
{ {
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();++s) {
delete (*s); delete (*s);
} }
@ -55,7 +55,7 @@ void Day::AddSession(Session *s)
EventDataType Day::settings_sum(ChannelID code) EventDataType Day::settings_sum(ChannelID code)
{ {
EventDataType val=0; EventDataType val=0;
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
@ -72,7 +72,7 @@ EventDataType Day::settings_max(ChannelID code)
{ {
EventDataType val=0,tmp; EventDataType val=0,tmp;
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
@ -91,7 +91,7 @@ EventDataType Day::settings_min(ChannelID code)
bool fir=true; bool fir=true;
// Cache this? // Cache this?
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
@ -115,7 +115,7 @@ EventDataType Day::settings_avg(ChannelID code)
EventDataType val=0; EventDataType val=0;
int cnt=0; int cnt=0;
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
@ -132,7 +132,7 @@ EventDataType Day::settings_avg(ChannelID code)
EventDataType Day::settings_wavg(ChannelID code) EventDataType Day::settings_wavg(ChannelID code)
{ {
double s0=0,s1=0,s2=0,tmp; double s0=0,s1=0,s2=0,tmp;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
Session & sess=*(*s); Session & sess=*(*s);
@ -164,7 +164,7 @@ EventDataType Day::percentile(ChannelID code,EventDataType percentile)
// } // }
// Cache this calculation? // Cache this calculation?
QVector<Session *>::iterator s; QList<Session *>::iterator s;
QHash<EventStoreType, qint64> wmap; QHash<EventStoreType, qint64> wmap;
@ -289,7 +289,7 @@ EventDataType Day::avg(ChannelID code)
double val=0; double val=0;
// Cache this? // Cache this?
int cnt=0; int cnt=0;
QVector<Session *>::iterator s; QList<Session *>::iterator s;
// Don't assume sessions are in order. // Don't assume sessions are in order.
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
@ -309,7 +309,7 @@ EventDataType Day::sum(ChannelID code)
{ {
// Cache this? // Cache this?
EventDataType val=0; EventDataType val=0;
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
@ -326,7 +326,7 @@ EventDataType Day::wavg(ChannelID code)
{ {
double s0=0,s1=0,s2=0; double s0=0,s1=0,s2=0;
qint64 d; qint64 d;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
Session & sess=*(*s); Session & sess=*(*s);
@ -354,7 +354,7 @@ qint64 Day::total_time()
//range.reserve(size()*2); //range.reserve(size()*2);
for (QVector<Session *>::iterator s=begin();s!=end();s++) { for (QList<Session *>::iterator s=begin();s!=end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
Session & sess=*(*s); Session & sess=*(*s);
@ -390,7 +390,7 @@ qint64 Day::total_time()
bool Day::hasEnabledSessions() bool Day::hasEnabledSessions()
{ {
bool b=false; bool b=false;
for (QVector<Session *>::iterator s=begin();s!=end();s++) { for (QList<Session *>::iterator s=begin();s!=end();s++) {
if ((*s)->enabled()) { if ((*s)->enabled()) {
b=true; b=true;
break; break;
@ -404,7 +404,7 @@ bool Day::hasEnabledSessions()
double val=0; double val=0;
int cnt=0; int cnt=0;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
Session & sess=*(*s); Session & sess=*(*s);
if (sess.eventlist.find(code)!=sess.eventlist.end()) { if (sess.eventlist.find(code)!=sess.eventlist.end()) {
val+=sess.percentile(code,percent); val+=sess.percentile(code,percent);
@ -421,7 +421,7 @@ qint64 Day::first(ChannelID code)
qint64 date=0; qint64 date=0;
qint64 tmp; qint64 tmp;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
tmp=(*s)->first(code); tmp=(*s)->first(code);
if (!tmp) continue; if (!tmp) continue;
@ -439,7 +439,7 @@ qint64 Day::last(ChannelID code)
qint64 date=0; qint64 date=0;
qint64 tmp; qint64 tmp;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
tmp=(*s)->last(code); tmp=(*s)->last(code);
if (!tmp) continue; if (!tmp) continue;
@ -456,7 +456,7 @@ EventDataType Day::Min(ChannelID code)
EventDataType min=0; EventDataType min=0;
EventDataType tmp; EventDataType tmp;
bool first=true; bool first=true;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
if (!(*s)->m_min.contains(code)) if (!(*s)->m_min.contains(code))
@ -475,7 +475,7 @@ EventDataType Day::Min(ChannelID code)
bool Day::hasData(ChannelID code, SummaryType type) bool Day::hasData(ChannelID code, SummaryType type)
{ {
bool has=false; bool has=false;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
Session *sess=*s; Session *sess=*s;
switch(type) { switch(type) {
@ -529,7 +529,7 @@ EventDataType Day::Max(ChannelID code)
EventDataType max=0; EventDataType max=0;
EventDataType tmp; EventDataType tmp;
bool first=true; bool first=true;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
if (!(*s)->m_max.contains(code)) continue; if (!(*s)->m_max.contains(code)) continue;
@ -641,7 +641,7 @@ bool Day::channelHasData(ChannelID id)
void Day::OpenEvents() void Day::OpenEvents()
{ {
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
(*s)->OpenEvents(); (*s)->OpenEvents();
@ -649,7 +649,7 @@ void Day::OpenEvents()
} }
void Day::CloseEvents() void Day::CloseEvents()
{ {
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
(*s)->TrashEvents(); (*s)->TrashEvents();
@ -661,7 +661,7 @@ qint64 Day::first()
qint64 date=0; qint64 date=0;
qint64 tmp; qint64 tmp;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
tmp=(*s)->first(); tmp=(*s)->first();
if (!tmp) continue; if (!tmp) continue;
@ -681,7 +681,7 @@ qint64 Day::last()
qint64 date=0; qint64 date=0;
qint64 tmp; qint64 tmp;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) { for (QList<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
tmp=(*s)->last(); tmp=(*s)->last();
if (!tmp) continue; if (!tmp) continue;
@ -694,3 +694,10 @@ qint64 Day::last()
return date; return date;
// return d_last; // return d_last;
} }
void Day::removeSession(Session * sess)
{
if (sessions.removeAll(sess)<1) {
int i=5;
}
}

View File

@ -117,9 +117,9 @@ public:
Session *operator [](int i) { return sessions[i]; } Session *operator [](int i) { return sessions[i]; }
//! \brief Return the first session as a QVector<Session*>::iterator //! \brief Return the first session as a QVector<Session*>::iterator
QVector<Session *>::iterator begin() { return sessions.begin(); } QList<Session *>::iterator begin() { return sessions.begin(); }
//! \brief Return the end session record as a QVector<Session*>::iterator //! \brief Return the end session record as a QVector<Session*>::iterator
QVector<Session *>::iterator end() { return sessions.end(); } QList<Session *>::iterator end() { return sessions.end(); }
//! \brief Finds and returns the index of a session, otherwise -1 if it's not there //! \brief Finds and returns the index of a session, otherwise -1 if it's not there
int find(Session * sess) { return sessions.indexOf(sess); } int find(Session * sess) { return sessions.indexOf(sess); }
@ -138,7 +138,7 @@ public:
void CloseEvents(); void CloseEvents();
//! \brief Returns this days sessions list //! \brief Returns this days sessions list
QVector<Session *> & getSessions() { return sessions; } QList<Session *> & getSessions() { return sessions; }
//! \brief Returns true if this Day contains loaded Event Data for this channel. //! \brief Returns true if this Day contains loaded Event Data for this channel.
bool channelExists(ChannelID id); bool channelExists(ChannelID id);
@ -152,9 +152,11 @@ public:
//! \brief Returns true if this day contains the supplied settings Channel id //! \brief Returns true if this day contains the supplied settings Channel id
bool settingExists(ChannelID id); bool settingExists(ChannelID id);
void removeSession(Session * sess);
protected: protected:
//! \brief A Vector containing all sessions for this day //! \brief A Vector containing all sessions for this day
QVector<Session *> sessions; QList<Session *> sessions;
QHash<ChannelID, QHash<EventDataType, EventDataType> > perc_cache; QHash<ChannelID, QHash<EventDataType, EventDataType> > perc_cache;
//qint64 d_first,d_last; //qint64 d_first,d_last;
private: private:

View File

@ -480,7 +480,7 @@ int ResmedLoader::Open(QString & path,Profile *profile)
QFile::copy(strpath,strmonthly); QFile::copy(strpath,strmonthly);
} }
// Meh.. // Meh.. these can be calculated if ever needed for ResScan SDcard export
QFile::copy(path+"STR.crc",backup_path+"STR.crc"); QFile::copy(path+"STR.crc",backup_path+"STR.crc");
} }
@ -614,14 +614,15 @@ int ResmedLoader::Open(QString & path,Profile *profile)
if (!fi.isReadable()) if (!fi.isReadable())
continue; continue;
// Accept only .edf and .edf.gz files if (filename.endsWith(STR_ext_gz)) {
if (filename.right(4).toLower() != "."+STR_ext_EDF) { filename.chop(3);
if (filename.right(7).toLower() != "."+STR_ext_EDF+STR_ext_gz)
continue;
gz=true; gz=true;
} else gz=false; } else gz=false;
// Accept only .edf and .edf.gz files
if (filename.right(4).toLower() != "."+STR_ext_EDF)
continue;
fullname=fi.canonicalFilePath(); fullname=fi.canonicalFilePath();
// Extract the session date out of the filename // Extract the session date out of the filename
@ -660,29 +661,33 @@ int ResmedLoader::Open(QString & path,Profile *profile)
} }
} }
fullname=backup(fullname, backup_path);
// Push current filename to ordered-by-sessionid list // Push current filename to ordered-by-sessionid list
if (si!=sessfiles.end()) { if (si!=sessfiles.end()) {
// Ignore if already compressed version of the same file exists.. (just in case) // Ignore if already compressed version of the same file exists.. (just in case)
if (!gz) {
if (si.value().contains(fullname+STR_ext_gz,Qt::CaseInsensitive))
continue;
} else {
QString str=fullname;
str.chop(3);
if (si.value().contains(str,Qt::CaseInsensitive))
continue;
}
si.value().push_back(fullname); bool skip=false;
// check for any other versions of the same file.
for (int i=0;i<si.value().size();i++) {
QString st=si.value().at(i).section("/",-1);
if (st.endsWith(STR_ext_gz))
st.chop(3);
if (st==filename)
skip=true;
}
if (!skip)
si.value().push_back(fullname);
} else { } else {
sessfiles[sessionid].push_back(fullname); sessfiles[sessionid].push_back(fullname);
} }
if ((i % 20)==0) { // if ((i % 10)==0) {
// Update the progress bar // Update the progress bar
if (qprogress) qprogress->setValue((float(i+1)/float(size)*10.0)); if (qprogress) qprogress->setValue((float(i+1)/float(size)*10.0));
QApplication::processEvents(); QApplication::processEvents();
} // }
} }
} }
@ -1123,6 +1128,7 @@ int ResmedLoader::Open(QString & path,Profile *profile)
// Create the session // Create the session
sess=new Session(m,sessionid); sess=new Session(m,sessionid);
QString oldbkfile;
// Process EDF File List // Process EDF File List
for (int i=0;i<si.value().size();++i) { for (int i=0;i<si.value().size();++i) {
fullname=si.value()[i]; fullname=si.value()[i];
@ -1130,56 +1136,64 @@ int ResmedLoader::Open(QString & path,Profile *profile)
gz=(filename.right(3).toLower()==STR_ext_gz); gz=(filename.right(3).toLower()==STR_ext_gz);
yearstr=filename.left(4); // yearstr=filename.left(4);
bkuppath=backup_path; // bkuppath=backup_path;
int year=yearstr.toInt(&ok,10); // int year=yearstr.toInt(&ok,10);
if (ok) { // if (ok) {
bkuppath+=yearstr+"/"; // bkuppath+=yearstr+"/";
dir.mkpath(bkuppath); // dir.mkpath(bkuppath);
} // }
// Copy the EDF file to the backup folder // // Copy the EDF file to the backup folder
if (create_backups) { // if (create_backups) {
backupfile=bkuppath+filename; // oldbkfile=backup_path+filename;
bool dobackup=true; // backupfile=bkuppath+filename;
if (!gz && QFile::exists(backupfile+STR_ext_gz)) {
dobackup=false; // gzipped edf.. assume it's already a backup
} else if (QFile::exists(backupfile)) {
if (gz) {
// don't bother, it's already there and compressed.
dobackup=false;
} else {
// non compressed file is there..
if (compress_backups) {
// remove old edf file, as we are writing a compressed one
QFile::remove(backupfile);
} else { // don't bother copying it.
dobackup=false;
}
}
}
if (dobackup) {
if (!gz) {
compress_backups ?
compressFile(fullname, backupfile)
:
QFile::copy(fullname, backupfile);
} else {
// already compressed, just copy it.
QFile::copy(fullname, backupfile);
}
}
if (!gz) { // bool dobackup=true;
backfile=filename.replace(".edf",".crc",Qt::CaseInsensitive);
} else {
backfile=filename.replace(".edf.gz",".crc",Qt::CaseInsensitive);
}
backupfile=bkuppath+backfile; // if (QFile::exists(oldbkfile+STR_ext_gz))
crcfile=newpath+backfile; // QFile::remove(oldbkfile+STR_ext_gz);
QFile::copy(crcfile, backupfile); // if (QFile::exists(oldbkfile))
} // QFile::remove(oldbkfile);
// if (!gz && QFile::exists(backupfile+STR_ext_gz)) {
// dobackup=false; // gzipped edf.. assume it's already a backup
// } else if (QFile::exists(backupfile)) {
// if (gz) {
// // don't bother, it's already there and compressed.
// dobackup=false;
// } else {
// // non compressed file is there..
// if (compress_backups) {
// // remove old edf file, as we are writing a compressed one
// QFile::remove(backupfile);
// } else { // don't bother copying it.
// dobackup=false;
// }
// }
// }
// if (dobackup) {
// if (!gz) {
// compress_backups ?
// compressFile(fullname, backupfile)
// :
// QFile::copy(fullname, backupfile);
// } else {
// // already compressed, just copy it.
// QFile::copy(fullname, backupfile);
// }
// }
// if (!gz) {
// backfile=filename.replace(".edf",".crc",Qt::CaseInsensitive);
// } else {
// backfile=filename.replace(".edf.gz",".crc",Qt::CaseInsensitive);
// }
// backupfile=bkuppath+backfile;
// crcfile=newpath+backfile;
// QFile::copy(crcfile, backupfile);
// }
EDFParser edf(fullname); EDFParser edf(fullname);
@ -1618,6 +1632,74 @@ int ResmedLoader::Open(QString & path,Profile *profile)
return 1; return 1;
} }
QString ResmedLoader::backup(QString fullname, QString backup_path, bool compress)
{
QString filename,yearstr,newname,oldname;
bool ok, gz=(fullname.right(3).toLower()==STR_ext_gz);
filename=fullname.section("/",-1);
if (gz)
filename.chop(3);
yearstr=filename.left(4);
yearstr.toInt(&ok,10);
if (!ok) {
qDebug() << "Invalid EDF filename given to ResMedLoader::backup()";
return "";
}
newname=backup_path+RMS9_STR_datalog+"/"+yearstr;
QDir dir;
dir.mkpath(newname);
newname+="/"+filename;
QString tmpname=newname;
if (compress)
newname+=STR_ext_gz;
// First make sure the correct backup exists.
if (!QFile::exists(newname)) {
if (compress) {
gz ?
QFile::copy(fullname,newname) // Already compressed.. copy it to the right location
:
compressFile(fullname,newname);
} else {
// dont really care if it's compressed and not meant to be, leave it that way
QFile::copy(fullname,newname);
}
} // else backup already exists...
// Now the correct backup is in place, we can trash any
if (compress) {
// Remove any uncompressed duplicate
if (QFile::exists(tmpname))
QFile::remove(tmpname);
} else {
// Delete the non compressed copy and choose it instead.
if (QFile::exists(tmpname+STR_ext_gz)) {
QFile::remove(tmpname);
newname=tmpname+STR_ext_gz;
}
}
// Remove any traces from old backup directory structure
oldname=backup_path+RMS9_STR_datalog+"/"+filename;
if (QFile::exists(oldname))
QFile::remove(oldname);
if (QFile::exists(oldname+STR_ext_gz))
QFile::remove(oldname+STR_ext_gz);
return newname;
}
bool ResmedLoader::LoadEVE(Session *sess,EDFParser &edf) bool ResmedLoader::LoadEVE(Session *sess,EDFParser &edf)
{ {
// EVEnt records have useless duration record. // EVEnt records have useless duration record.

View File

@ -215,6 +215,8 @@ protected:
//! This contains the Pressure, Leak, Respiratory Rate, Minute Ventilation, Tidal Volume, etc.. //! This contains the Pressure, Leak, Respiratory Rate, Minute Ventilation, Tidal Volume, etc..
bool LoadPLD(Session *sess,EDFParser &edf); bool LoadPLD(Session *sess,EDFParser &edf);
QString backup(QString file, QString backup_path, bool compress=false);
QMap<SessionID,QStringList> sessfiles; QMap<SessionID,QStringList> sessfiles;
#ifdef DEBUG_EFFICIENCY #ifdef DEBUG_EFFICIENCY
QHash<ChannelID,qint64> channel_efficiency; QHash<ChannelID,qint64> channel_efficiency;

View File

@ -173,7 +173,7 @@ QDate Machine::AddSession(Session *s,Profile *p)
dd->AddSession(s); dd->AddSession(s);
if (combine_next_day) { if (combine_next_day) {
for (QVector<Session *>::iterator i=nextday.value()->begin();i!=nextday.value()->end();i++) { for (QList<Session *>::iterator i=nextday.value()->begin();i!=nextday.value()->end();i++) {
dd->AddSession(*i); dd->AddSession(*i);
} }
QMap<QDate,QList<Day *> >::iterator nd=p->daylist.find(date.addDays(1)); QMap<QDate,QList<Day *> >::iterator nd=p->daylist.find(date.addDays(1));

View File

@ -810,7 +810,7 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac
Day * day=GetGoodDay(date,mt); Day * day=GetGoodDay(date,mt);
if (day) { if (day) {
for (int i=0;i<day->size();i++) { for (int i=0;i<day->size();i++) {
for (QVector<Session *>::iterator s=day->begin();s!=day->end();s++) { for (QList<Session *>::iterator s=day->begin();s!=day->end();s++) {
if (!(*s)->enabled()) if (!(*s)->enabled())
continue; continue;

View File

@ -60,7 +60,7 @@ public:
bool SearchEvent(ChannelID code, qint64 time, qint64 dist=15000); bool SearchEvent(ChannelID code, qint64 time, qint64 dist=15000);
//! \brief Return the sessionID //! \brief Return the sessionID
const SessionID & session() { inline const SessionID & session() {
return s_session; return s_session;
} }

View File

@ -54,6 +54,8 @@ Daily::Daily(QWidget *parent,gGraphView * shared)
ZombieMeterMoved=false; ZombieMeterMoved=false;
BookmarksChanged=false; BookmarksChanged=false;
lastcpapday=NULL;
QList<int> a; QList<int> a;
a.push_back(300); a.push_back(300);
a.push_back(this->width()-300); a.push_back(this->width()-300);
@ -80,6 +82,7 @@ Daily::Daily(QWidget *parent,gGraphView * shared)
// sessbar->setMinimumHeight(sessbar->height()); // sessbar->setMinimumHeight(sessbar->height());
// } // }
sessbar=NULL;
webView=new MyWebView(this); webView=new MyWebView(this);
@ -514,7 +517,7 @@ void Daily::UpdateEventsTree(QTreeWidget *tree,Day *day)
bool userflags=p_profile->cpap->userEventFlagging(); bool userflags=p_profile->cpap->userEventFlagging();
qint64 drift=0, clockdrift=PROFILE.cpap->clockDrift()*1000L; qint64 drift=0, clockdrift=PROFILE.cpap->clockDrift()*1000L;
for (QVector<Session *>::iterator s=day->begin();s!=day->end();s++) { for (QList<Session *>::iterator s=day->begin();s!=day->end();++s) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
QHash<ChannelID,QVector<EventList *> >::iterator m; QHash<ChannelID,QVector<EventList *> >::iterator m;
@ -789,7 +792,7 @@ QString Daily::getSessionInformation(Day * cpap, Day * oxi, Day * stage)
break; break;
} }
html+="</i></td></tr>\n"; html+="</i></td></tr>\n";
for (QVector<Session *>::iterator s=day->begin();s!=day->end();s++) { for (QList<Session *>::iterator s=day->begin();s!=day->end();++s) {
if ((day->machine_type()==MT_CPAP) && if ((day->machine_type()==MT_CPAP) &&
((*s)->settings.find(CPAP_BrokenWaveform)!=(*s)->settings.end())) ((*s)->settings.find(CPAP_BrokenWaveform)!=(*s)->settings.end()))
@ -1088,16 +1091,22 @@ QString Daily::getSleepTime(Day * cpap, Day * oxi)
void Daily::Load(QDate date) void Daily::Load(QDate date)
{ {
if (sessbar) {
sessbar->clear();
sessbar->deleteLater();
sessbar=NULL;
}
dateDisplay->setText("<i>"+date.toString(Qt::SystemLocaleLongDate)+"</i>"); dateDisplay->setText("<i>"+date.toString(Qt::SystemLocaleLongDate)+"</i>");
static Day * lastcpapday=NULL;
previous_date=date; previous_date=date;
Day *cpap=PROFILE.GetDay(date,MT_CPAP); Day *cpap=PROFILE.GetDay(date,MT_CPAP);
Day *oxi=PROFILE.GetDay(date,MT_OXIMETER); Day *oxi=PROFILE.GetDay(date,MT_OXIMETER);
Day *stage=PROFILE.GetDay(date,MT_SLEEPSTAGE); Day *stage=PROFILE.GetDay(date,MT_SLEEPSTAGE);
if (!PROFILE.session->cacheSessions()) { if (!PROFILE.session->cacheSessions()) {
// Getting trashed on purge last day...
if (lastcpapday && (lastcpapday!=cpap)) { if (lastcpapday && (lastcpapday!=cpap)) {
for (QVector<Session *>::iterator s=lastcpapday->begin();s!=lastcpapday->end();s++) { for (QList<Session *>::iterator s=lastcpapday->begin();s!=lastcpapday->end();++s) {
(*s)->TrashEvents(); (*s)->TrashEvents();
} }
} }
@ -1307,7 +1316,7 @@ void Daily::Load(QDate date)
QColor("light blue"), QColor("light blue"),
}; };
const int maxcolors=sizeof(cols)/sizeof(QColor); const int maxcolors=sizeof(cols)/sizeof(QColor);
QVector<Session *>::iterator i; QList<Session *>::iterator i;
// WebView trashes it without asking.. :( // WebView trashes it without asking.. :(
if (cpap) { if (cpap) {
@ -1456,6 +1465,12 @@ void Daily::UnitsChanged()
} }
} }
void Daily::clearLastDay()
{
lastcpapday=NULL;
}
void Daily::Unload(QDate date) void Daily::Unload(QDate date)
{ {
Session *journal=GetJournalSession(date); Session *journal=GetJournalSession(date);
@ -1600,7 +1615,7 @@ Session * Daily::GetJournalSession(QDate date) // Get the first journal session
Day *journal=PROFILE.GetDay(date,MT_JOURNAL); Day *journal=PROFILE.GetDay(date,MT_JOURNAL);
if (!journal) if (!journal)
return NULL; //CreateJournalSession(date); return NULL; //CreateJournalSession(date);
QVector<Session *>::iterator s; QList<Session *>::iterator s;
s=journal->begin(); s=journal->begin();
if (s!=journal->end()) if (s!=journal->end())
return *s; return *s;

View File

@ -124,6 +124,8 @@ public:
*/ */
gGraph * eventBreakdownPie() { return GAHI; } gGraph * eventBreakdownPie() { return GAHI; }
QWidget * sessionBar() { return sessbar; } QWidget * sessionBar() { return sessbar; }
void clearLastDay();
private slots: private slots:
/*! \fn on_calendar_currentPageChanged(int year, int month); /*! \fn on_calendar_currentPageChanged(int year, int month);
@ -331,6 +333,8 @@ private:
QLabel * dateDisplay; QLabel * dateDisplay;
MyWebView * webView; MyWebView * webView;
Day * lastcpapday;
bool ZombieMeterMoved; bool ZombieMeterMoved;
bool BookmarksChanged; bool BookmarksChanged;

View File

@ -1113,11 +1113,12 @@ void MainWindow::on_actionPurge_Current_Day_triggered()
Machine *m; Machine *m;
if (day) { if (day) {
m=day->machine; m=day->machine;
QString path=PROFILE.Get("{"+STR_GEN_DataFolder+"}/")+m->GetClass()+"_"+m->hexid()+"/"; QString path=PROFILE.Get("{"+STR_GEN_DataFolder+"}/")+m->GetClass()+"_"+m->properties[STR_PROP_Serial]+"/";
QVector<Session *>::iterator s; QList<Session *>::iterator s;
for (s=day->begin();s!=day->end();s++) { QList<Session *> list;
for (s=day->begin();s!=day->end();++s) {
SessionID id=(*s)->session(); SessionID id=(*s)->session();
QString filename0=path+QString().sprintf("%08lx.000",id); QString filename0=path+QString().sprintf("%08lx.000",id);
QString filename1=path+QString().sprintf("%08lx.001",id); QString filename1=path+QString().sprintf("%08lx.001",id);
@ -1125,8 +1126,19 @@ void MainWindow::on_actionPurge_Current_Day_triggered()
qDebug() << "Removing" << filename1; qDebug() << "Removing" << filename1;
QFile::remove(filename0); QFile::remove(filename0);
QFile::remove(filename1); QFile::remove(filename1);
list.push_back(*s);
m->sessionlist.erase(m->sessionlist.find(id)); // remove from machines session list m->sessionlist.erase(m->sessionlist.find(id)); // remove from machines session list
} }
m->day.erase(m->day.find(date));
for (int i=0;i<list.size();i++) {
Session * sess=list.at(i);
day->removeSession(sess);
delete sess;
}
QList<Day *> & dl=PROFILE.daylist[date]; QList<Day *> & dl=PROFILE.daylist[date];
QList<Day *>::iterator it;//=dl.begin(); QList<Day *>::iterator it;//=dl.begin();
for (it=dl.begin();it!=dl.end();it++) { for (it=dl.begin();it!=dl.end();it++) {
@ -1138,7 +1150,8 @@ void MainWindow::on_actionPurge_Current_Day_triggered()
delete day; delete day;
} }
} }
getDaily()->ReloadGraphs(); getDaily()->clearLastDay();
getDaily()->LoadDate(date);
} }
void MainWindow::on_actionAll_Data_for_current_CPAP_machine_triggered() void MainWindow::on_actionAll_Data_for_current_CPAP_machine_triggered()

View File

@ -169,7 +169,8 @@ void SessionBar::paintEvent(QPaintEvent *)
SegType mn=min(); SegType mn=min();
SegType mx=max(); SegType mx=max();
Q_ASSERT(mx > mn); if (mx > mn)
return;
SegType total=mx-mn; SegType total=mx-mn;
double px=double(width()-5) / double(total); double px=double(width()-5) / double(total);