Bump version to 0.2.2
[harbour-pedalo.git] / src / statsweekdaycongestion.cpp
index 685e175..9b6eb81 100644 (file)
@@ -1,22 +1,19 @@
-#include <QDebug>
-
 #include "statsweekdaycongestion.h"
 
 StatsWeekdayCongestion::StatsWeekdayCongestion(JourneyModel * journeys) :
     journeys(journeys)
 {
-    title = "Congested days (cycles passed)";
+    title = "Congestion by day (cycles per hour)";
     units = "";
     labels = QStringList{"M", "T", "W", "Th", "F", "S", "Su"};
 }
 
 void StatsWeekdayCongestion::update() {
-    quint32 passed[7];
+    double passed[7];
     unsigned int count[7];
     int pos;
 
-    qDebug() << "Calculating values";
-    values.clear();
+    barvalues.clear();
 
     for (pos = 0; pos < 7; pos++) {
         passed[pos] = 0u;
@@ -26,8 +23,9 @@ void StatsWeekdayCongestion::update() {
     foreach (Journey const &journey, journeys->getData()) {
         QDate date = journey.getStartDate();
         int dayofweek = date.dayOfWeek() - 1;
+        double duration = journey.getDuration() / (60.0 * 60.0);
         if (dayofweek >= 0) {
-            passed[dayofweek] += journey.getOvertook() + journey.getOvertakenBy();
+            passed[dayofweek] += (journey.getOvertook() + journey.getOvertakenBy()) / duration;
             count[dayofweek]++;
         }
     }
@@ -41,10 +39,8 @@ void StatsWeekdayCongestion::update() {
         if (result > maxval) {
             maxval = result;
         }
-        values << result;
+        barvalues << result;
     }
 
-    step = qRound(maxval / 5.0);
-
-    qDebug() << "Calculated values";
+    step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
 }