From e5bcb16b30b21488c93878f7e545d91bf0c79d7a Mon Sep 17 00:00:00 2001
From: Phil Olynyk <phil@pholynyk.ca>
Date: Thu, 21 Sep 2017 10:50:18 -0400
Subject: [PATCH] add debug code - trying to fix 'normal average' problem

---
 sleepyhead/Graphs/gSessionTimesChart.cpp | 10 ++++++----
 sleepyhead/Graphs/gSessionTimesChart.h   |  4 ++--
 sleepyhead/SleepLib/day.cpp              |  4 ++--
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/sleepyhead/Graphs/gSessionTimesChart.cpp b/sleepyhead/Graphs/gSessionTimesChart.cpp
index a44a7302..dd94574c 100644
--- a/sleepyhead/Graphs/gSessionTimesChart.cpp
+++ b/sleepyhead/Graphs/gSessionTimesChart.cpp
@@ -1138,7 +1138,7 @@ void gAHIChart::preCalc()
 
     ahi_wavg = 0;
     ahi_avg = 0;
-    calc_cnt = 0;
+    total_days = 0;
     total_hours = 0;
     min_ahi = 99999;
     max_ahi = -99999;
@@ -1187,13 +1187,15 @@ void gAHIChart::customCalc(Day *day, QVector<SummaryChartSlice> &list)
     ahi_wavg += ahi_cnt;
     ahi_avg += ahi_cnt;
     total_hours += hours;
-    calc_cnt++;
+    total_days++;
+    qDebug() << "Leaving gAHIChart::customCalc - ahi_avg: " << ahi_avg << " total_days: " << total_days ;
 }
 void gAHIChart::afterDraw(QPainter & /*painter */, gGraph &graph, QRect rect)
 {
     if (totaldays == nousedays) return;
 
     //int size = idx_end - idx_start;
+    qDebug() << "Entering gAHIChart::afterDraw - ahi_avg: " << ahi_avg << " total_days: " << total_days ;
 
     bool skip = true;
     float med = 0;
@@ -1211,8 +1213,8 @@ void gAHIChart::afterDraw(QPainter & /*painter */, gGraph &graph, QRect rect)
         }
         break;
     case 2: // avg
-        if (calc_cnt > 0) {
-            med = ahi_avg / calc_cnt;
+        if (total_days > 0) {
+            med = ahi_avg / total_days;
             skip = false;
         }
         break;
diff --git a/sleepyhead/Graphs/gSessionTimesChart.h b/sleepyhead/Graphs/gSessionTimesChart.h
index 148db904..6f3c905e 100644
--- a/sleepyhead/Graphs/gSessionTimesChart.h
+++ b/sleepyhead/Graphs/gSessionTimesChart.h
@@ -412,7 +412,7 @@ public:
 //        layer->total_hours = total_hours;
 //        layer->max_ahi = max_ahi;
 //        layer->min_ahi = min_ahi;
-//        layer->calc_cnt = calc_cnt;
+//        layer->total_days = total_days;
 //        layer->ahi_data = ahi_data;
     }
 
@@ -424,7 +424,7 @@ public:
     float max_ahi;
     float min_ahi;
 
-    int calc_cnt;
+    int total_days;
     QList<float> ahi_data;
 };
 
diff --git a/sleepyhead/SleepLib/day.cpp b/sleepyhead/SleepLib/day.cpp
index 3a3b4361..47b6e7f0 100644
--- a/sleepyhead/SleepLib/day.cpp
+++ b/sleepyhead/SleepLib/day.cpp
@@ -150,9 +150,9 @@ QString Day::calcMiddleLabel(ChannelID code)
     if (c == 0) {
         return QObject::tr("%1 %2").arg(STR_TR_Median).arg(schema::channel[code].label());
     } else if (c == 1) {
-        return QObject::tr("%1 %2").arg(STR_TR_Average).arg(schema::channel[code].label());
+        return QObject::tr("%1 %2").arg(STR_TR_WAvg).arg(schema::channel[code].label());
     } else {
-        return QObject::tr("%1 %2").arg(STR_TR_Average).arg(schema::channel[code].label());
+        return QObject::tr("%1 %2").arg(STR_TR_Avg).arg(schema::channel[code].label());
     }
 }
 QString Day::calcMaxLabel(ChannelID code)