3 #include "statshourcongestion.h"
6 #define HIGHESTHOUR (21)
8 StatsHourCongestion::StatsHourCongestion(JourneyModel
* journeys
) :
11 title
= "Congestion by hour (cycles per hour)";
15 for (int hour
= LOWESTHOUR
; hour
<= HIGHESTHOUR
; hour
++) {
16 labels
<< QString::number(hour
);
20 void StatsHourCongestion::update() {
22 unsigned int count
[24];
25 qDebug() << "Calculating values";
28 for (pos
= 0; pos
< 24; pos
++) {
33 foreach (Journey
const &journey
, journeys
->getData()) {
34 QTime time
= journey
.getStartTime();
35 int hour
= time
.hour();
36 int startmin
= time
.minute();
37 int duration
= (journey
.getDuration() / 60);
38 int remaining
= duration
;
40 while (remaining
> 0) {
41 // toadd is always greater than 0, so the loop is guaranteed to exit
42 unsigned int toadd
= (startmin
+ remaining
) < 60 ? remaining
: 60 - startmin
;
43 passed
[hour
] += (double)toadd
* ((double)(journey
.getOvertook() + journey
.getOvertakenBy()) / duration
);
48 hour
= (hour
+ 1) % 24;
53 for (pos
= LOWESTHOUR
; pos
<= HIGHESTHOUR
; pos
++) {
56 result
= (float)(60.0 * passed
[pos
] / (double)count
[pos
]);
58 if (result
> maxval
) {
64 step
= (maxval
> 5.0) ? qRound(maxval
/ 5.0) : (maxval
/ 5.0);
66 qDebug() << "Calculated values";