From ab9d5e87c505759d59d1f4993ad59905f74e439e Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Thu, 30 Jan 2020 13:45:55 -0500 Subject: [PATCH] Flip the sleep stage data to negative so that the chart is drawn in the right orientation. Ideally graphs would be able to invert their Y axis without this hack, but it works for now. It would also be good to support non-numeric labels in the graph legend. --- oscar/Graphs/gGraph.cpp | 3 ++- oscar/SleepLib/loader_plugins/dreem_loader.cpp | 16 +++++++++------- oscar/SleepLib/loader_plugins/dreem_loader.h | 2 +- oscar/SleepLib/loader_plugins/zeo_loader.cpp | 7 +++++-- oscar/SleepLib/loader_plugins/zeo_loader.h | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/oscar/Graphs/gGraph.cpp b/oscar/Graphs/gGraph.cpp index 76635008..83c7f763 100644 --- a/oscar/Graphs/gGraph.cpp +++ b/oscar/Graphs/gGraph.cpp @@ -663,7 +663,8 @@ void gGraph::roundY(EventDataType &miny, EventDataType &maxy) } } - if (miny < 0) { + // Make the range symmetrical if there are both positive and negative values. + if (miny < 0 && maxy > 0) { EventDataType tmp = qMax(qAbs(miny), qAbs(maxy)); maxy = tmp; miny = -tmp; diff --git a/oscar/SleepLib/loader_plugins/dreem_loader.cpp b/oscar/SleepLib/loader_plugins/dreem_loader.cpp index 793b31ff..54421775 100644 --- a/oscar/SleepLib/loader_plugins/dreem_loader.cpp +++ b/oscar/SleepLib/loader_plugins/dreem_loader.cpp @@ -120,7 +120,7 @@ Session* DreemLoader::readNextSession() QDateTime start_time, stop_time; int sleep_onset, sleep_duration; int light_sleep_duration, deep_sleep_duration, rem_duration, awakened_duration; - int awakenings, position_changes, average_hr, average_rr; + int awakenings, position_changes; // average_hr, average_rr; float sleep_efficiency; QStringList hypnogram; @@ -147,12 +147,13 @@ Session* DreemLoader::readNextSession() awakened_duration = readDuration(row["Wake After Sleep Onset Duration"]); awakenings = readInt(row["Number of awakenings"]); position_changes = readInt(row["Position Changes"]); - average_hr = readInt(row["Mean Heart Rate"]); - average_rr = readInt(row["Mean Respiration CPM"]); + //average_hr = readInt(row["Mean Heart Rate"]); // TODO: sometimes "None" + //average_rr = readInt(row["Mean Respiration CPM"]); // "Number of Stimulations" is 0 for US models sleep_efficiency = readInt(row["Sleep efficiency"]) / 100.0; if (invalid_fields) { + qWarning() << "invalid Dreem row, skipping" << start_time; continue; } @@ -177,8 +178,8 @@ Session* DreemLoader::readNextSession() sess->settings[ZEO_TimeInREM] = rem_duration / 60; sess->settings[ZEO_TimeInLight] = light_sleep_duration / 60; sess->settings[ZEO_TimeInDeep] = deep_sleep_duration / 60; - sess->settings[OXI_Pulse] = average_hr; - sess->settings[CPAP_RespRate] = average_rr; + //sess->settings[OXI_Pulse] = average_hr; + //sess->settings[CPAP_RespRate] = average_rr; // Dreem also provides: // total sleep duration // # position changes @@ -194,7 +195,7 @@ Session* DreemLoader::readNextSession() qint64 tt = st; qint64 second_sample_tt = ((tt + step - 1L) / step) * step; - EventList *sleepstage = sess->AddEventList(ZEO_SleepStage, EVL_Event, 1, 0, 0, 4); + EventList *sleepstage = sess->AddEventList(ZEO_SleepStage, EVL_Event, 1, 0, -4, 0); for (int i = 0; i < hypnogram.size(); i++) { auto & label = hypnogram.at(i); @@ -209,7 +210,8 @@ Session* DreemLoader::readNextSession() tt = last; } - sleepstage->AddEvent(tt, stage); + if (stage == 0) qDebug() << start_time << "0 Dreem sleep stage?"; + sleepstage->AddEvent(tt, -stage); // use negative values so that the chart is oriented the right way } if (i == 0) { tt = second_sample_tt; diff --git a/oscar/SleepLib/loader_plugins/dreem_loader.h b/oscar/SleepLib/loader_plugins/dreem_loader.h index b6569d76..8c88619e 100644 --- a/oscar/SleepLib/loader_plugins/dreem_loader.h +++ b/oscar/SleepLib/loader_plugins/dreem_loader.h @@ -12,7 +12,7 @@ #include "SleepLib/machine_loader.h" const QString dreem_class_name = "Dreem"; -const int dreem_data_version = 1; +const int dreem_data_version = 2; /*! \class DreemLoader diff --git a/oscar/SleepLib/loader_plugins/zeo_loader.cpp b/oscar/SleepLib/loader_plugins/zeo_loader.cpp index 4a355a51..9817260d 100644 --- a/oscar/SleepLib/loader_plugins/zeo_loader.cpp +++ b/oscar/SleepLib/loader_plugins/zeo_loader.cpp @@ -227,12 +227,15 @@ Session* ZEOLoader::readNextSession() st = qint64(start_of_night.toTime_t()) * 1000L; sess->really_set_first(st); tt = st; - EventList *sleepstage = sess->AddEventList(ZEO_SleepStage, EVL_Event, 1, 0, 0, 4); + EventList *sleepstage = sess->AddEventList(ZEO_SleepStage, EVL_Event, 1, 0, -4, 0); for (int i = 0; i < DSG.size(); i++) { + bool ok; stage = DSG[i].toInt(&ok); if (ok) { - sleepstage->AddEvent(tt, stage); + // 1 = Awake, 2 = REM, 3 = Light Sleep, 4 = Deep Sleep + // TODO: What is 0? What is 6? + sleepstage->AddEvent(tt, -stage); // use negative values so that the chart is oriented the right way } tt += WindowSize; } diff --git a/oscar/SleepLib/loader_plugins/zeo_loader.h b/oscar/SleepLib/loader_plugins/zeo_loader.h index b5852e89..bf8abd3c 100644 --- a/oscar/SleepLib/loader_plugins/zeo_loader.h +++ b/oscar/SleepLib/loader_plugins/zeo_loader.h @@ -13,7 +13,7 @@ #include "SleepLib/machine_loader.h" const QString zeo_class_name = "ZEO"; -const int zeo_data_version = 1; +const int zeo_data_version = 2; /*! \class ZEOLoader