1 #include "statshourcongestion.h"
4 #define HIGHESTHOUR (21)
6 StatsHourCongestion::StatsHourCongestion(JourneyModel
* journeys
) :
9 title
= "Congestion by hour (cycles per hour)";
13 for (int hour
= LOWESTHOUR
; hour
<= HIGHESTHOUR
; hour
++) {
14 labels
<< QString::number(hour
);
18 void StatsHourCongestion::update() {
20 unsigned int count
[24];
25 for (pos
= 0; pos
< 24; pos
++) {
30 foreach (Journey
const &journey
, journeys
->getData()) {
31 QTime time
= journey
.getStartTime();
32 int hour
= time
.hour();
33 int startmin
= time
.minute();
34 int duration
= (journey
.getDuration() / 60);
35 int remaining
= duration
;
37 while (remaining
> 0) {
38 // toadd is always greater than 0, so the loop is guaranteed to exit
39 unsigned int toadd
= (startmin
+ remaining
) < 60 ? remaining
: 60 - startmin
;
40 passed
[hour
] += (double)toadd
* ((double)(journey
.getOvertook() + journey
.getOvertakenBy()) / duration
);
45 hour
= (hour
+ 1) % 24;
50 for (pos
= LOWESTHOUR
; pos
<= HIGHESTHOUR
; pos
++) {
53 result
= (float)(60.0 * passed
[pos
] / (double)count
[pos
]);
55 if (result
> maxval
) {
61 step
= (maxval
> 5.0) ? qRound(maxval
/ 5.0) : (maxval
/ 5.0);