f477c3b9313ad74679072ecad7ec3a84be749cce
1 #include "statsyearjourneys.h"
5 StatsYearJourneys::StatsYearJourneys(JourneyModel
* journeys
) :
8 title
= QString("Year view (journeys/mon + moving ave)");
12 void StatsYearJourneys::update() {
13 unsigned int count
[12];
14 unsigned int 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 count
[(date
.month() - now
.month() + 11) % 12]++;
37 if (date
> startave
) {
38 int month
= (date
.month() - now
.month() + 11) % 12;
39 for (pos
= 0; pos
< WINDOW
; pos
++) {
40 average
[month
+ pos
]++;
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 (count
[pos
] > maxval
) {
56 barvalues
<< (float)count
[pos
];
57 linevalues
<< (float)average
[pos
] / (float)WINDOW
;
60 step
= maxval
> 5.0 ? qRound(maxval
/ 5.0) : (maxval
/ 5.0);