685e17540876eea8322df79d8247452dfabb11b0
[harbour-pedalo.git] / src / statsweekdaycongestion.cpp
1 #include <QDebug>
2
3 #include "statsweekdaycongestion.h"
4
5 StatsWeekdayCongestion::StatsWeekdayCongestion(JourneyModel * journeys) :
6 journeys(journeys)
7 {
8 title = "Congested days (cycles passed)";
9 units = "";
10 labels = QStringList{"M", "T", "W", "Th", "F", "S", "Su"};
11 }
12
13 void StatsWeekdayCongestion::update() {
14 quint32 passed[7];
15 unsigned int count[7];
16 int pos;
17
18 qDebug() << "Calculating values";
19 values.clear();
20
21 for (pos = 0; pos < 7; pos++) {
22 passed[pos] = 0u;
23 count[pos] = 0u;
24 }
25
26 foreach (Journey const &journey, journeys->getData()) {
27 QDate date = journey.getStartDate();
28 int dayofweek = date.dayOfWeek() - 1;
29 if (dayofweek >= 0) {
30 passed[dayofweek] += journey.getOvertook() + journey.getOvertakenBy();
31 count[dayofweek]++;
32 }
33 }
34
35 maxval = 0.0;
36 for (pos = 0; pos < 7; pos++) {
37 float result = 0.0f;
38 if (count[pos] > 0) {
39 result = ((double)passed[pos] / (double)count[pos]);
40 }
41 if (result > maxval) {
42 maxval = result;
43 }
44 values << result;
45 }
46
47 step = qRound(maxval / 5.0);
48
49 qDebug() << "Calculated values";
50 }