1 #include "statsyearduration.h"
5 StatsYearDuration::StatsYearDuration(JourneyModel
* journeys
) :
8 title
= QString("Year view (hours/mon + moving ave)");
12 void StatsYearDuration::update() {
14 double average
[11 + WINDOW
];
20 now
= QDate::currentDate();
21 start
= now
.addMonths(-12);
22 startave
= start
.addMonths(1 - WINDOW
);
27 for (pos
= 0; pos
< 12; pos
++) {
32 foreach (Journey
const &journey
, journeys
->getData()) {
33 QDate date
= journey
.getStartDate();
35 duration
[(date
.month() - now
.month() + 11) % 12] += journey
.getDuration() / (60.0 * 60.0);
37 if (date
> startave
) {
38 int month
= (date
.month() - now
.month() + 11) % 12;
39 for (pos
= 0; pos
< WINDOW
; pos
++) {
40 average
[month
+ pos
] += journey
.getDuration() / (60.0 * 60.0);
45 labels
= QStringList
{"J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"};
46 for (pos
= 0; pos
< now
.month(); pos
++) {
48 labels
.push_back(labels
.takeFirst());
52 for (pos
= 0; pos
< 12; pos
++) {
53 if (duration
[pos
] > maxval
) {
54 maxval
= duration
[pos
];
56 barvalues
<< duration
[pos
];
57 linevalues
<< average
[pos
] / (double)WINDOW
;
60 step
= maxval
> 5.0 ? qRound(maxval
/ 5.0) : (maxval
/ 5.0);