Improve prisma smart loader

This commit is contained in:
axt 2022-09-18 12:12:28 +02:00
parent befa225434
commit b4914c0970
2 changed files with 28 additions and 24 deletions

View File

@ -563,6 +563,27 @@ MachineInfo PrismaLoader::PeekInfoFromConfig(const QString & selectedPath)
return MachineInfo();
}
void PrismaLoader::ImportDataDir(QDir& dataDir, QSet<SessionID>& sessions, QHash<SessionID, QString>& eventFiles, QHash<SessionID, QString>& signalFiles) {
dataDir.setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::NoSymLinks);
dataDir.setSorting(QDir::Name);
if (dataDir.exists()) {
for (auto & inputFile : dataDir.entryInfoList()) {
QString fileName = inputFile.fileName().toLower();
if (fileName.startsWith("event_") && fileName.endsWith(".xml")) {
SessionID sid = fileName.mid(6,fileName.size()-4-6).toLong();
sessions += sid;
eventFiles[sid] = inputFile.canonicalFilePath();
}
if (inputFile.fileName().toLower().startsWith("signal_") && inputFile.fileName().toLower().endsWith(".wmedf")) {
SessionID sid = fileName.mid(7,fileName.size()-6-7).toLong();
sessions += sid;
signalFiles[sid] = inputFile.canonicalFilePath();
}
}
}
}
// TODO AXT PrismaSmart specific, extract it into a parser class with the config files
void PrismaLoader::ScanFiles(const MachineInfo& info, const QString & machinePath)
{
@ -588,33 +609,13 @@ void PrismaLoader::ScanFiles(const MachineInfo& info, const QString & machinePat
dayDir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::NoSymLinks);
dayDir.setSorting(QDir::Name);
QFileInfoList subDirs = dayDir.entryInfoList();
QDir dataDir;
if (subDirs.size() == 0) {
dataDir = dayDir;
} else if (subDirs.size() == 1) {
dataDir = QDir(subDirs.at(0).canonicalFilePath());
ImportDataDir(dayDir, sessions, eventFiles, signalFiles);
} else {
qWarning() << "PrismaLoader: Directory structure not recognized!";
continue;
}
dataDir.setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::NoSymLinks);
dataDir.setSorting(QDir::Name);
if (dataDir.exists()) {
for (auto & inputFile : dataDir.entryInfoList()) {
QString fileName = inputFile.fileName().toLower();
if (fileName.startsWith("event_") && fileName.endsWith(".xml")) {
SessionID sid = fileName.mid(6,fileName.size()-4-6).toLong();
sessions += sid;
eventFiles[sid] = inputFile.canonicalFilePath();
}
if (inputFile.fileName().toLower().startsWith("signal_") && inputFile.fileName().toLower().endsWith(".wmedf")) {
SessionID sid = fileName.mid(7,fileName.size()-6-7).toLong();
sessions += sid;
signalFiles[sid] = inputFile.canonicalFilePath();
}
for (auto & dataDirInfo: subDirs) {
QDir dataDir(dataDirInfo.canonicalFilePath());
ImportDataDir(dataDir, sessions, eventFiles, signalFiles);
}
}
}

View File

@ -11,6 +11,7 @@
#define PRISMA_LOADER_H
#include "SleepLib/machine_loader.h"
#include "SleepLib/loader_plugins/edfparser.h"
#include <QDir>
#ifdef UNITTEST_MODE
#define private public
@ -188,6 +189,8 @@ class PrismaLoader : public CPAPLoader
MachineInfo PeekInfoFromConfig(const QString & selectedPath);
void ImportDataDir(QDir& dataDir, QSet<SessionID>& sessions, QHash<SessionID, QString>& eventFiles, QHash<SessionID, QString>& signalFiles);
//! \brief Scans the given directories for session data and create an import task for each logical session.
void ScanFiles(const MachineInfo& info, const QString & path);
};