ResMed Session grouping rework

This commit is contained in:
Mark Watkins 2014-05-14 15:15:06 +10:00
parent 96429dee7a
commit c369f0ef00
2 changed files with 101 additions and 139 deletions

View File

@ -292,9 +292,6 @@ bool EDFParser::Parse()
sig.pos = 0; sig.pos = 0;
} }
if (num_signals == 2) {
int i=5;
}
for (int x = 0; x < num_data_records; x++) { for (int x = 0; x < num_data_records; x++) {
for (int i = 0; i < num_signals; i++) { for (int i = 0; i < num_signals; i++) {
EDFSignal &sig = edfsignals[i]; EDFSignal &sig = edfsignals[i];
@ -304,7 +301,7 @@ bool EDFParser::Parse()
sig.pos += sig.nr; sig.pos += sig.nr;
pos += sig.nr * 2; pos += sig.nr * 2;
#else #else
// ARM, PPC, etc.. // Big endian safe
for (int j=0;j<sig.nr;j++) { for (int j=0;j<sig.nr;j++) {
qint16 t=Read16(); qint16 t=Read16();
sig.data[sig.pos++]=t; sig.data[sig.pos++]=t;
@ -759,12 +756,25 @@ int ResmedLoader::Open(QString &path, Profile *profile)
SessionID sessionid; SessionID sessionid;
QDateTime date; QDateTime date;
QString fullname; QString fullname;
QString edftypestr;
bool gz; bool gz;
int size; int size;
QMap<SessionID, QStringList>::iterator si; QMap<SessionID, QStringList>::iterator si;
sessfiles.clear(); sessfiles.clear();
QMap<SessionID, EDFGroup> filegroups;
QMap<SessionID, EDFGroup>::iterator fgit;
QStringList files;
enum EDF_Type {
ET_ERR=0, BRP, EVE, PLD, SAD
} edftype;
SessionID lastsession = 0;
for (int dc = 0; dc < dirs.size(); dc++) { for (int dc = 0; dc < dirs.size(); dc++) {
dir.setPath(dirs.at(dc)); dir.setPath(dirs.at(dc));
@ -809,68 +819,70 @@ int ResmedLoader::Open(QString &path, Profile *profile)
continue; continue;
} }
edftypestr = filename.section("_", 2).section(".", 0, 0);
// Could always just compare first letter, seeing date is already checked..
if (edftypestr.compare("BRP", Qt::CaseInsensitive) == 0) edftype = BRP;
else if (edftypestr.compare("EVE", Qt::CaseInsensitive) == 0) edftype = EVE;
else if (edftypestr.compare("PLD", Qt::CaseInsensitive) == 0) edftype = PLD;
else if (edftypestr.compare("SAD", Qt::CaseInsensitive) == 0) edftype = SAD;
else edftype = ET_ERR;
// convert this date to UNIX epoch to form the sessionID // convert this date to UNIX epoch to form the sessionID
sessionid = date.toTime_t(); sessionid = date.toTime_t();
//////////////////////////////////////////////////////////////////////////////////////////// fgit = filegroups.find(sessionid);
// Resmed bugs up on the session filenames.. More than these 3 seconds if (fgit == filegroups.end()) {
if ((edftype == EVE) || (edftype == BRP)) {
fgit = filegroups.insert(sessionid,EDFGroup());
lastsession = sessionid;
} else {
////////////////////////////////////////////////////////////////////////////////////////////
// Resmed bugs up on the session filenames.. Biggest observed delay so far of 14 seconds
// Moral of the story, when writing firmware and saving in batches, use the same datetimes,
// and provide firmware updates for free to your customers.
////////////////////////////////////////////////////////////////////////////////////////////
// Moral of the story, when writing firmware and saving in batches, use the same datetimes, // Check how long since last EVE/BRP session
// and provide firmware updates for free to your customers. if ((sessionid - lastsession) < 30) {
//////////////////////////////////////////////////////////////////////////////////////////// fgit = filegroups.find(lastsession);
si = sessfiles.find(sessionid); } else {
// It appears we have a lonely PLD or SAD file...
if (si == sessfiles.end()) { fgit = filegroups.insert(sessionid,EDFGroup());
// Scan 3 seconds either way for sessions..
for (int j = 1; j < 3; j++) {
if ((si = sessfiles.find(sessionid + j)) != sessfiles.end()) {
sessionid += j;
break;
} else if ((si = sessfiles.find(sessionid - j)) != sessfiles.end()) {
sessionid -= j;
break;
} }
} }
} }
fullname = backup(fullname, backup_path); fullname = backup(fullname, backup_path);
// Push current filename to ordered-by-sessionid list switch (edftype) {
if (si != sessfiles.end()) { case BRP:
// Ignore if already compressed version of the same file exists.. (just in case) fgit.value().BRP = fullname;
break;
bool skip = false; case EVE:
fgit.value().EVE = fullname;
// check for any other versions of the same file. break;
for (int i = 0; i < si.value().size(); i++) { case PLD:
QString st = si.value().at(i).section("/", -1); fgit.value().PLD = fullname;
break;
if (st.endsWith(STR_ext_gz)) { case SAD:
st.chop(3); fgit.value().SAD = fullname;
} break;
default:
if (st == filename) { break;
skip = true; // No such thing..
}
}
if (!skip) {
si.value().push_back(fullname);
}
} else {
sessfiles[sessionid].push_back(fullname);
} }
// if ((i % 10)==0) { if (qprogress) {
// Update the progress bar if ((i % 5) == 0) {
if (qprogress) { qprogress->setValue((float(i + 1) / float(size) * 10.0)); } qprogress->setValue((float(i + 1) / float(size) * 10.0));
QApplication::processEvents();
QApplication::processEvents(); }
// } }
} }
} }
QString fn; QString fn;
Session *sess; Session *sess;
int cnt = 0; int cnt = 0;
@ -1305,8 +1317,8 @@ int ResmedLoader::Open(QString &path, Profile *profile)
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Scan through new file list and import sessions // Scan through new file list and import sessions
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
for (QMap<SessionID, QStringList>::iterator si = sessfiles.begin(); si != sessfiles.end(); si++) { for (fgit = filegroups.begin(); fgit != filegroups.end(); ++fgit) {
sessionid = si.key(); sessionid = fgit.key();
// Skip file if already imported // Skip file if already imported
if (m->SessionExists(sessionid)) { if (m->SessionExists(sessionid)) {
@ -1316,92 +1328,21 @@ 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; if (!fgit.value().EVE.isEmpty()) {
EDFParser edf(fgit.value().EVE);
// Process EDF File List if (edf.Parse()) LoadEVE(sess,edf);
for (int i = 0; i < si.value().size(); ++i) { }
fullname = si.value()[i]; if (!fgit.value().BRP.isEmpty()) {
filename = fullname.section("/", -1); EDFParser edf(fgit.value().BRP);
gz = (filename.right(3).toLower() == STR_ext_gz); if (edf.Parse()) LoadBRP(sess,edf);
}
if (!fgit.value().PLD.isEmpty()) {
// yearstr=filename.left(4); EDFParser edf(fgit.value().PLD);
// bkuppath=backup_path; if (edf.Parse()) LoadPLD(sess,edf);
// int year=yearstr.toInt(&ok,10); }
// if (ok) { if (!fgit.value().SAD.isEmpty()) {
// bkuppath+=yearstr+"/"; EDFParser edf(fgit.value().SAD);
// dir.mkpath(bkuppath); if (edf.Parse()) LoadSAD(sess,edf);
// }
// // Copy the EDF file to the backup folder
// if (create_backups) {
// oldbkfile=backup_path+filename;
// backupfile=bkuppath+filename;
// bool dobackup=true;
// if (QFile::exists(oldbkfile+STR_ext_gz))
// QFile::remove(oldbkfile+STR_ext_gz);
// 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);
// Parse the actual file
if (!edf.Parse()) {
continue;
}
// Give a warning if doesn't match the machine serial number in Identification.tgt
if (edf.serialnumber != serial) {
qDebug() << "edf Serial number doesn't match Identification.tgt";
}
fn = filename.section("_", -1).section(".", 0, 0).toLower();
if (fn == "eve") { LoadEVE(sess, edf); }
else if (fn == "pld") { LoadPLD(sess, edf); }
else if (fn == "brp") { LoadBRP(sess, edf); }
else if (fn == "sad") { LoadSAD(sess, edf); }
} }
if ((++cnt % 10) == 0) { if ((++cnt % 10) == 0) {

View File

@ -229,4 +229,25 @@ class ResmedLoader : public MachineLoader
#endif #endif
}; };
struct EDFGroup {
EDFGroup() { }
EDFGroup(QString brp, QString eve, QString pld, QString sad) {
BRP = brp;
EVE = eve;
PLD = pld;
SAD = sad;
}
EDFGroup(const EDFGroup & copy) {
BRP=copy.BRP;
EVE=copy.EVE;
PLD=copy.PLD;
SAD=copy.SAD;
}
QString BRP;
QString EVE;
QString PLD;
QString SAD;
};
#endif // RESMED_LOADER_H #endif // RESMED_LOADER_H