mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-17 19:20:46 +00:00
Split single CSV in to multiple sessions
This commit is contained in:
parent
112c4ce9eb
commit
db2047b6d5
@ -94,7 +94,7 @@ int SomnoposeLoader::OpenFile(const QString & filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QDateTime epoch(QDate(2001, 1, 1));
|
QDateTime epoch(QDate(2001, 1, 1));
|
||||||
qint64 ep = qint64(epoch.toTime_t()+epoch.offsetFromUtc()) * 1000, time;
|
qint64 ep = qint64(epoch.toTime_t()+epoch.offsetFromUtc()) * 1000, time=0;
|
||||||
qDebug() << "Epoch starts at" << epoch.toString();
|
qDebug() << "Epoch starts at" << epoch.toString();
|
||||||
|
|
||||||
double timestamp, orientation=0, inclination=0, movement=0;
|
double timestamp, orientation=0, inclination=0, movement=0;
|
||||||
@ -102,7 +102,8 @@ int SomnoposeLoader::OpenFile(const QString & filename)
|
|||||||
QStringList fields;
|
QStringList fields;
|
||||||
bool ok, orientation_ok, inclination_ok, movement_ok;
|
bool ok, orientation_ok, inclination_ok, movement_ok;
|
||||||
|
|
||||||
bool first = true;
|
bool first = true, skip_session = false;
|
||||||
|
int session_count = 0;
|
||||||
MachineInfo info = newInfo();
|
MachineInfo info = newInfo();
|
||||||
info.model = model;
|
info.model = model;
|
||||||
info.serial = serial;
|
info.serial = serial;
|
||||||
@ -115,6 +116,39 @@ int SomnoposeLoader::OpenFile(const QString & filename)
|
|||||||
while (!(data = ts.readLine()).isEmpty()) {
|
while (!(data = ts.readLine()).isEmpty()) {
|
||||||
fields = data.split(",");
|
fields = data.split(",");
|
||||||
|
|
||||||
|
if (fields.size() >= col_timestamp && fields[col_timestamp] == "-") {
|
||||||
|
// Flag end of session...
|
||||||
|
if (sess) {
|
||||||
|
if (ev_orientation) {
|
||||||
|
sess->setMin(POS_Orientation, ev_orientation->Min());
|
||||||
|
sess->setMax(POS_Orientation, ev_orientation->Max());
|
||||||
|
}
|
||||||
|
if (ev_inclination) {
|
||||||
|
sess->setMin(POS_Inclination, ev_inclination->Min());
|
||||||
|
sess->setMax(POS_Inclination, ev_inclination->Max());
|
||||||
|
}
|
||||||
|
if (ev_movement) {
|
||||||
|
sess->setMin(POS_Movement, ev_movement->Min());
|
||||||
|
sess->setMax(POS_Movement, ev_movement->Max());
|
||||||
|
}
|
||||||
|
sess->really_set_last(time);
|
||||||
|
sess->SetChanged(true);
|
||||||
|
|
||||||
|
mach->AddSession(sess);
|
||||||
|
session_count++;
|
||||||
|
}
|
||||||
|
// Prepare for potential next session...
|
||||||
|
sess = nullptr;
|
||||||
|
ev_orientation = ev_inclination = ev_movement = nullptr;
|
||||||
|
first = true;
|
||||||
|
skip_session = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skip_session) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (fields.size() < hdr_size) { // missing fields.. skip this record
|
if (fields.size() < hdr_size) { // missing fields.. skip this record
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -122,6 +156,7 @@ int SomnoposeLoader::OpenFile(const QString & filename)
|
|||||||
timestamp = fields[col_timestamp].toDouble(&ok);
|
timestamp = fields[col_timestamp].toDouble(&ok);
|
||||||
|
|
||||||
if (!ok) { continue; }
|
if (!ok) { continue; }
|
||||||
|
orientation_ok = inclination_ok = movement_ok = false;
|
||||||
|
|
||||||
if (col_orientation >= 0) {
|
if (col_orientation >= 0) {
|
||||||
orientation = fields[col_orientation].toDouble(&orientation_ok);
|
orientation = fields[col_orientation].toDouble(&orientation_ok);
|
||||||
@ -142,12 +177,15 @@ int SomnoposeLoader::OpenFile(const QString & filename)
|
|||||||
time = (timestamp * 1000.0) + ep;
|
time = (timestamp * 1000.0) + ep;
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
|
first = false;
|
||||||
sid = time / 1000;
|
sid = time / 1000;
|
||||||
qDebug() << "First timestamp is" << QDateTime::fromMSecsSinceEpoch(time).toString();
|
qDebug() << "First timestamp is" << QDateTime::fromMSecsSinceEpoch(time).toString();
|
||||||
|
|
||||||
if (mach->SessionExists(sid)) {
|
if (mach->SessionExists(sid)) {
|
||||||
qDebug() << "File " << filename << " already loaded... skipping";
|
qDebug() << "File " << filename << " session " << sid << " already loaded... skipping";
|
||||||
return 0; // Already imported
|
// Continue processing file to allow for case where new sessions are added to a file
|
||||||
|
skip_session = true;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sess = new Session(mach, sid);
|
sess = new Session(mach, sid);
|
||||||
@ -161,7 +199,6 @@ int SomnoposeLoader::OpenFile(const QString & filename)
|
|||||||
if (col_movement >= 0) {
|
if (col_movement >= 0) {
|
||||||
ev_movement = sess->AddEventList(POS_Movement, EVL_Event, 1, 0, 0, 0);
|
ev_movement = sess->AddEventList(POS_Movement, EVL_Event, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
first = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sess->set_last(time);
|
sess->set_last(time);
|
||||||
@ -193,14 +230,17 @@ int SomnoposeLoader::OpenFile(const QString & filename)
|
|||||||
sess->SetChanged(true);
|
sess->SetChanged(true);
|
||||||
|
|
||||||
mach->AddSession(sess);
|
mach->AddSession(sess);
|
||||||
|
session_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session_count) {
|
||||||
mach->Save();
|
mach->Save();
|
||||||
// Adding these to hopefully make data persistent...
|
// Adding these to hopefully make data persistent...
|
||||||
mach->SaveSummaryCache();
|
mach->SaveSummaryCache();
|
||||||
p_profile->StoreMachines();
|
p_profile->StoreMachines();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return session_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user