X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=blobdiff_plain;f=src%2Fstatsweekdaycongestion.cpp;h=3e19192883ac5770e31b5ab7f24d9293dfea5f3b;hp=685e17540876eea8322df79d8247452dfabb11b0;hb=54ab3ebfadf8cb258561a4641249da8c6469dc0f;hpb=dc14479d561196e19417c4ecf78e847ec4b43b7c diff --git a/src/statsweekdaycongestion.cpp b/src/statsweekdaycongestion.cpp index 685e175..3e19192 100644 --- a/src/statsweekdaycongestion.cpp +++ b/src/statsweekdaycongestion.cpp @@ -5,18 +5,18 @@ 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 +26,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 +42,10 @@ void StatsWeekdayCongestion::update() { if (result > maxval) { maxval = result; } - values << result; + barvalues << result; } - step = qRound(maxval / 5.0); + step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0); qDebug() << "Calculated values"; }