From 887273849f6e0fba7c779868aa6a2bdc080426cd Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Mon, 23 Apr 2018 06:04:39 +1000 Subject: [PATCH] Make ResMed imports progress bar move a bit more during stages --- .../SleepLib/loader_plugins/resmed_loader.cpp | 38 ++++++++++++++++++- sleepyhead/SleepLib/machine_loader.cpp | 6 +-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp index 70ee9191..40b644b2 100644 --- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp @@ -1683,6 +1683,28 @@ int ResmedLoader::scanFiles(Machine * mach, QString datalog_path) QHash > filesbytype; + QTime time; + time.start(); + + // Calculate number of files for progress bar for this stage + int dsiz = dirs.size(); + int numfiles = 0; + for (int d=0; d < dsiz; ++d) { + dir.setPath(dirs.at(d)); + dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); + dir.setSorting(QDir::Name); + + flist = dir.entryInfoList(); + + // get number of files in current directory being processed + int size = flist.size(); + numfiles += size; + } + + qprogress->setMaximum(numfiles); + + + int cnt = 0; // Scan through all folders looking for EDF files, skip any already imported and peek inside to get durations for (int d=0; d < dirs.size(); ++d) { dir.setPath(dirs.at(d)); @@ -1698,6 +1720,11 @@ int ResmedLoader::scanFiles(Machine * mach, QString datalog_path) for (int i = 0; i < size; i++) { QFileInfo fi = flist.at(i); filename = fi.fileName(); + cnt++; + if (cnt % 50) { + qprogress->setValue(cnt); + QApplication::processEvents(); + } // Forget about it if it can't be read. if (!fi.isReadable()) { @@ -1736,11 +1763,12 @@ int ResmedLoader::scanFiles(Machine * mach, QString datalog_path) dur.filename = filename; if (dur.start != dur.end) { // make sure empty EVE's are skipped - QMap::iterator it = newfiles.insert(filename, getEDFDuration(fullname)); + QMap::iterator it = newfiles.insert(filename, dur); //getEDFDuration(fullname)); filesbytype[dur.type].append(&it.value()); } } } + qDebug() << "ResmedLoader::scanFiles() took" << time.elapsed() << "ms"; QList EDForder; EDForder.push_back(EDF_PLD); @@ -1748,6 +1776,9 @@ int ResmedLoader::scanFiles(Machine * mach, QString datalog_path) EDForder.push_back(EDF_SAD); QHash::iterator gi; + qprogress->setMaximum(filesbytype[EDF_PLD].size() + filesbytype[EDF_BRP].size() + filesbytype[EDF_SAD].size()); + cnt = 0; + for (int i=0; i<3; i++) { EDFType basetype = EDForder.takeFirst(); @@ -1755,6 +1786,11 @@ int ResmedLoader::scanFiles(Machine * mach, QString datalog_path) QList & LIST = filesbytype[basetype]; int base_size = LIST.size(); for (int f=0; f < base_size; ++f) { + if ((cnt % 50) == 0) { + qprogress->setValue(cnt); + QApplication::processEvents(); + } + cnt++; const EDFduration * dur = LIST.at(f); quint32 start = dur->start; diff --git a/sleepyhead/SleepLib/machine_loader.cpp b/sleepyhead/SleepLib/machine_loader.cpp index 6de50398..d05b2748 100644 --- a/sleepyhead/SleepLib/machine_loader.cpp +++ b/sleepyhead/SleepLib/machine_loader.cpp @@ -187,12 +187,12 @@ void MachineLoader::runTasks(bool threaded) } } else { QThreadPool * threadpool = QThreadPool::globalInstance(); - + qprogress->setMaximum(m_totaltasks); while (!m_tasklist.isEmpty()) { if (threadpool->tryStart(m_tasklist.at(0))) { m_tasklist.pop_front(); - float f = float(m_currenttask) / float(m_totaltasks) * 100.0; - qprogress->setValue(f); + //float f = float(m_currenttask) / float(m_totaltasks) * 100.0; + qprogress->setValue(m_currenttask); m_currenttask++; } if ((m_currenttask % 50)==0) {