X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=blobdiff_plain;f=src%2Fstatsweekdaycongestion.cpp;h=9b6eb8129ef3e1e01d1d805af94fb7c32cc9bee7;hp=685e17540876eea8322df79d8247452dfabb11b0;hb=336d2255eb501f5c228a80a0fa469844bbc1ee2f;hpb=dc14479d561196e19417c4ecf78e847ec4b43b7c diff --git a/src/statsweekdaycongestion.cpp b/src/statsweekdaycongestion.cpp index 685e175..9b6eb81 100644 --- a/src/statsweekdaycongestion.cpp +++ b/src/statsweekdaycongestion.cpp @@ -1,22 +1,19 @@ -#include - #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); }