From cda41274d5c9d9161264c96afd66af80ec3e36c3 Mon Sep 17 00:00:00 2001 From: Guy Scharf Date: Fri, 10 Dec 2021 00:54:14 -0700 Subject: [PATCH] Add date range option to Statistics page. Implement existing (but hidden) UI for data range and modify reporting as needed. This is not the ideal solution to this feature. It would be better to have a pop-up dialog that asked for beginning and ending dates of range and size of interval for interval reporting. --- Htmldocs/release_notes.html | 1 + oscar/SleepLib/profiles.h | 8 ++++++++ oscar/mainwindow.cpp | 22 +++++++++++++++++++++- oscar/mainwindow.h | 4 ++++ oscar/statistics.cpp | 9 +++++++-- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Htmldocs/release_notes.html b/Htmldocs/release_notes.html index 1e25023c..e590c7f6 100644 --- a/Htmldocs/release_notes.html +++ b/Htmldocs/release_notes.html @@ -23,6 +23,7 @@
  • [new] Add support for new settings codes in recently manufactured 700X110 DreamStations.
  • [new] Add 95% flow limitation to Therapy Efficacy section on Statistics page.
  • +
  • [new] Add date range option to Statistics page.
  • [new] Improve appearance and operation of event types and graphs comboboxes on Daily and Overview pages.
  • [fix] Correct SleepStyle machines sometimes identified as Icon machines.
  • [fix] Improve event flag position in flow graph for DV6 machines.
  • diff --git a/oscar/SleepLib/profiles.h b/oscar/SleepLib/profiles.h index 5c5e3068..fd0fd0de 100644 --- a/oscar/SleepLib/profiles.h +++ b/oscar/SleepLib/profiles.h @@ -363,6 +363,8 @@ const QString STR_US_PrefCalcPercentile = "PrefCalcPercentile"; const QString STR_US_PrefCalcMax = "PrefCalcMax"; const QString STR_US_ShowUnknownFlags = "ShowUnknownFlags"; const QString STR_US_StatReportMode = "StatReportMode"; +const QString STR_US_StatReportRangeStart = "StatReportRangeStart"; +const QString STR_US_StatReportRangeEnd = "StatReportRangeEnd"; const QString STR_US_LastOverviewRange = "LastOverviewRange"; const QString STR_US_CustomOverviewRangeStart = "CustomOverviewRangeStart"; const QString STR_US_CustomOverviewRangeEnd = "CustomOverviewRangeEnd"; @@ -727,6 +729,8 @@ class UserSettings : public PrefSettings m_prefCalcPercentile = initPref(STR_US_PrefCalcPercentile, (double)95.0).toDouble(); m_prefCalcMax = initPref(STR_US_PrefCalcMax, (int)0).toInt(); initPref(STR_US_StatReportMode, 0); + initPref(STR_US_StatReportRangeStart, QDate(1,1,2000)); + initPref(STR_US_StatReportRangeEnd, QDate(1,1,2000)); m_showUnownFlags = initPref(STR_US_ShowUnknownFlags, false).toBool(); initPref(STR_US_LastOverviewRange, 4); } @@ -740,6 +744,8 @@ class UserSettings : public PrefSettings inline double prefCalcPercentile() const { return m_prefCalcPercentile; } inline int prefCalcMax() const { return m_prefCalcMax; } int statReportMode() const { return getPref(STR_US_StatReportMode).toInt(); } + QDate statReportRangeStart() const { return getPref(STR_US_StatReportRangeStart).toDate(); } + QDate statReportRangeEnd() const { return getPref(STR_US_StatReportRangeEnd).toDate(); } inline bool showUnknownFlags() const { return m_showUnownFlags; } int lastOverviewRange() const { return getPref(STR_US_LastOverviewRange).toInt(); } QDate customOverviewRangeStart () const { return getPref(STR_US_CustomOverviewRangeStart).toDate(); } @@ -754,6 +760,8 @@ class UserSettings : public PrefSettings void setPrefCalcPercentile(double p) { setPref(STR_US_PrefCalcPercentile, m_prefCalcPercentile=p); } void setPrefCalcMax(int i) { setPref(STR_US_PrefCalcMax, m_prefCalcMax=i); } void setStatReportMode(int i) { setPref(STR_US_StatReportMode, i); } + void setStatReportRangeStart(QDate i) { setPref (STR_US_StatReportRangeStart, i); } + void setStatReportRangeEnd(QDate i) { setPref (STR_US_StatReportRangeEnd, i); } void setShowUnknownFlags(bool b) { setPref(STR_US_ShowUnknownFlags, m_showUnownFlags=b); } void setLastOverviewRange(int i) { setPref(STR_US_LastOverviewRange, i); } void setCustomOverviewRangeStart(QDate i) { setPref(STR_US_CustomOverviewRangeStart, i); } diff --git a/oscar/mainwindow.cpp b/oscar/mainwindow.cpp index 7367683f..bec8259a 100644 --- a/oscar/mainwindow.cpp +++ b/oscar/mainwindow.cpp @@ -183,7 +183,7 @@ void MainWindow::SetupGUI() ui->statEndDate->setVisible(false); ui->statStartDate->setVisible(false); - ui->reportModeRange->setVisible(false); +// ui->reportModeRange->setVisible(false); int srm = 0; if (p_profile) { srm = p_profile->general->statReportMode(); @@ -582,9 +582,13 @@ bool MainWindow::OpenProfile(QString profileName, bool skippassword) switch (srm) { case 0: ui->reportModeStandard->setChecked(true); + ui->statEndDate->setVisible(false); + ui->statStartDate->setVisible(false); break; case 1: ui->reportModeMonthly->setChecked(true); + ui->statEndDate->setVisible(false); + ui->statStartDate->setVisible(false); break; case 2: ui->reportModeRange->setChecked(true); @@ -2382,6 +2386,10 @@ void MainWindow::GenerateStatistics() QString htmlStats = stats.GenerateHTML(); QString htmlRecords = stats.UpdateRecordsBox(); + bool brange = (p_profile->general->statReportMode() == 2); + ui->statEndDate->setVisible(brange); + ui->statStartDate->setVisible(brange); + updateFavourites(); setStatsHTML(htmlStats); @@ -2452,6 +2460,18 @@ void MainWindow::on_reportModeRange_clicked() } } +void MainWindow::on_statEndDate_dateChanged(const QDate &date) +{ + p_profile->general->setStatReportRangeEnd(date); + GenerateStatistics(); +} + +void MainWindow::on_statStartDate_dateChanged(const QDate &date) +{ + p_profile->general->setStatReportRangeStart(date); + GenerateStatistics(); +} + void MainWindow::on_actionPurgeCurrentDaysOximetry_triggered() { if (!daily) diff --git a/oscar/mainwindow.h b/oscar/mainwindow.h index fa0cbf01..14702fac 100644 --- a/oscar/mainwindow.h +++ b/oscar/mainwindow.h @@ -324,6 +324,10 @@ class MainWindow : public QMainWindow void on_reportModeRange_clicked(); + void on_statEndDate_dateChanged(const QDate &date); + + void on_statStartDate_dateChanged(const QDate &date); + void on_actionPurgeCurrentDaysOximetry_triggered(); void logMessage(QString msg); diff --git a/oscar/statistics.cpp b/oscar/statistics.cpp index 9effb1df..0b904e6b 100644 --- a/oscar/statistics.cpp +++ b/oscar/statistics.cpp @@ -28,7 +28,7 @@ extern MainWindow *mainwin; // HTML components that make up Statistics page and printed report QString htmlReportHeader = ""; // Page header -QString htmlReportHeaderPrint = ""; // Page header +QString htmlReportHeaderPrint = ""; // Page header QString htmlUsage = ""; // CPAP and Oximetry QString htmlMachineSettings = ""; // Machine (formerly Rx) changes QString htmlMachines = ""; // Machines used in this profile @@ -1141,6 +1141,7 @@ QString Statistics::GenerateCPAPUsage() if (number_periods > 12) { number_periods = 12; } +// } else if (p_profile->general->statReportMode() == STAT_MODE_RANGE) { } QDate last = lastcpap, first = lastcpap; @@ -1165,7 +1166,7 @@ QString Statistics::GenerateCPAPUsage() periods.push_back(Period(qMax(last.addDays(-29),first), last, tr("Last 30 Days"))); periods.push_back(Period(qMax(last.addMonths(-6), first), last, tr("Last 6 Months"))); periods.push_back(Period(qMax(last.addMonths(-12), first), last, tr("Last Year"))); - } else { // STAT_MODE_MONTHLY or STAT_MODE_RANGE + } else if (p_profile->general->statReportMode() == STAT_MODE_MONTHLY) { QDate l=last,s=last; periods.push_back(Period(last,last,tr("Last Session"))); @@ -1188,6 +1189,10 @@ QString Statistics::GenerateCPAPUsage() for (; j < number_periods; ++j) { periods.push_back(Period(last,last, "")); } + } else { // STAT_MODE_RANGE + first = p_profile->general->statReportRangeStart(); + last = p_profile->general->statReportRangeEnd(); + periods.push_back(Period(first,last,first.toString(MedDateFormat)+" -
    "+last.toString(MedDateFormat))); } int days = p_profile->countDays(row.type, first, last);