Bump version to 0.2.2
[harbour-pedalo.git] / src / statsweekdayave.cpp
1 #include "statsweekdayave.h"
2
3 StatsWeekdayAve::StatsWeekdayAve(JourneyModel * journeys) :
4 journeys(journeys)
5 {
6 title = "Average journey time (mins)";
7 units = "";
8 labels = QStringList{"M", "T", "W", "Th", "F", "S", "Su"};
9 }
10
11 void StatsWeekdayAve::update() {
12 double duration[7];
13 unsigned int count[7];
14 int pos;
15
16 barvalues.clear();
17
18 for (pos = 0; pos < 7; pos++) {
19 duration[pos] = 0.0;
20 count[pos] = 0u;
21 }
22
23 foreach (Journey const &journey, journeys->getData()) {
24 QDate date = journey.getStartDate();
25 int dayofweek = date.dayOfWeek() - 1;
26 if (dayofweek >= 0) {
27 duration[dayofweek] += journey.getDuration();
28 count[dayofweek]++;
29 }
30 }
31
32 maxval = 0.0;
33 for (pos = 0; pos < 7; pos++) {
34 float result = 0.0f;
35 if (count[pos] > 0) {
36 result = ((duration[pos] / 60.0) / (double)count[pos]);
37 }
38 if (result > maxval) {
39 maxval = result;
40 }
41 barvalues << result;
42 }
43
44 step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
45 }