Journey proportions per hour.
Congestion by hour.
src/statsmodel.cpp \
src/stats.cpp \
src/statsweekdayave.cpp \
- src/statsweekdaycongestion.cpp
+ src/statsweekdaycongestion.cpp \
+ src/statshourcongestion.cpp \
+ src/statshourjourneys.cpp
DISTFILES += qml/harbour-pedalo.qml \
qml/cover/CoverPage.qml \
src/statsmodel.h \
src/stats.h \
src/statsweekdayave.h \
- src/statsweekdaycongestion.h
+ src/statsweekdaycongestion.h \
+ src/statshourcongestion.h \
+ src/statshourjourneys.h
#include "imageprovider.h"
#include "graph.h"
#include "statsweekdayave.h"
+#include "statshourjourneys.h"
#include "statsweekdaycongestion.h"
+#include "statshourcongestion.h"
#include "harbour-pedalo.h"
StatsWeekdayAve statsweekdayave(&journeys);
statsmodel.addStats(statsweekdayave);
+ StatsHourJourneys statshourjourneys(&journeys);
+ statsmodel.addStats(statshourjourneys);
+
StatsWeekdayCongestion statsweekdaycongestion(&journeys);
statsmodel.addStats(statsweekdaycongestion);
+ StatsHourCongestion statshourcongestion(&journeys);
+ statsmodel.addStats(statshourcongestion);
+
QFile file;
file.setFileName(Settings::getConfigDir() + "/journeys.csv");
journeys.importFromFile(file);
--- /dev/null
+#include <QDebug>
+
+#include "statshourcongestion.h"
+
+#define LOWESTHOUR (7)
+#define HIGHESTHOUR (21)
+
+StatsHourCongestion::StatsHourCongestion(JourneyModel * journeys) :
+ journeys(journeys)
+{
+ title = "Congestion by hour (cycles per hour)";
+ units = "";
+
+ labels.clear();
+ for (int hour = LOWESTHOUR; hour <= HIGHESTHOUR; hour++) {
+ labels << QString::number(hour);
+ }
+}
+
+void StatsHourCongestion::update() {
+ double passed[24];
+ unsigned int count[24];
+ int pos;
+
+ qDebug() << "Calculating values";
+ values.clear();
+
+ for (pos = 0; pos < 24; pos++) {
+ passed[pos] = 0.0;
+ count[pos] = 0;
+ }
+
+ foreach (Journey const &journey, journeys->getData()) {
+ QTime time = journey.getStartTime();
+ int hour = time.hour();
+ int startmin = time.minute();
+ int duration = (journey.getDuration() / 60);
+ int remaining = duration;
+
+ while (remaining > 0) {
+ // toadd is always greater than 0, so the loop is guaranteed to exit
+ unsigned int toadd = (startmin + remaining) < 60 ? remaining : 60 - startmin;
+ passed[hour] += (double)toadd * ((double)(journey.getOvertook() + journey.getOvertakenBy()) / duration);
+ count[hour] += toadd;
+ remaining -= toadd;
+ startmin = 0;
+
+ hour = (hour + 1) % 24;
+ }
+ }
+
+ maxval = 0.0;
+ for (pos = LOWESTHOUR; pos <= HIGHESTHOUR; pos++) {
+ float result = 0.0f;
+ if (count[pos] > 0) {
+ result = (float)(60.0 * passed[pos] / (double)count[pos]);
+ }
+ if (result > maxval) {
+ maxval = result;
+ }
+ values << result;
+ }
+
+ step = (maxval > 5.0) ? qRound(maxval / 5.0) : (maxval / 5.0);
+
+ qDebug() << "Calculated values";
+}
--- /dev/null
+#ifndef STATSHOURCONGESTION_H
+#define STATSHOURCONGESTION_H
+
+#include "journeymodel.h"
+#include "stats.h"
+
+class StatsHourCongestion : public Stats
+{
+public:
+ StatsHourCongestion(JourneyModel * journeys);
+
+ void update();
+
+private:
+ JourneyModel * journeys;
+};
+
+#endif // STATSHOURCONGESTION_H
--- /dev/null
+#include <QDebug>
+
+#include "statshourjourneys.h"
+
+#define LOWESTHOUR (7)
+#define HIGHESTHOUR (21)
+
+StatsHourJourneys::StatsHourJourneys(JourneyModel * journeys) :
+ journeys(journeys)
+{
+ title = "Journey proportions per hour (%)";
+ units = "%";
+
+ labels.clear();
+ for (int hour = LOWESTHOUR; hour <= HIGHESTHOUR; hour++) {
+ labels << QString::number(hour);
+ }
+}
+
+void StatsHourJourneys::update() {
+ unsigned int minsperhour[24];
+ quint64 totalmins;
+ int pos;
+
+ qDebug() << "Calculating values";
+ values.clear();
+
+ for (pos = 0; pos < 24; pos++) {
+ minsperhour[pos] = 0u;
+ }
+
+ totalmins = 0u;
+ foreach (Journey const &journey, journeys->getData()) {
+ QTime time = journey.getStartTime();
+ int hour = time.hour();
+ int startmin = time.minute();
+ int remaining = (journey.getDuration() / 60);
+ totalmins += remaining;
+
+ while (remaining > 0) {
+ // toadd is always greater than 0, so the loop is guaranteed to exit
+ unsigned int toadd = (startmin + remaining) < 60 ? remaining : 60 - startmin;
+ minsperhour[hour] += toadd;
+ remaining -= toadd;
+ startmin = 0;
+
+ hour = (hour + 1) % 24;
+ }
+ }
+
+ for (pos = LOWESTHOUR; pos <= HIGHESTHOUR; pos++) {
+ float result = 0.0f;
+ if (totalmins > 0) {
+ result = ((double)minsperhour[pos] / (double)totalmins);
+ }
+ values << result;
+ }
+
+ qDebug() << "Calculated values";
+}
--- /dev/null
+#ifndef STATSHOURJOURNEYS_H
+#define STATSHOURJOURNEYS_H
+
+#include "journeymodel.h"
+#include "stats.h"
+
+class StatsHourJourneys : public Stats
+{
+public:
+ StatsHourJourneys(JourneyModel * journeys);
+
+ void update();
+
+private:
+ JourneyModel * journeys;
+};
+
+#endif // STATSHOURJOURNEYS_H
values << result;
}
- step = qRound(maxval / 5.0);
+ step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
qDebug() << "Calculated values";
}
#define STATSWEEKDAYAVE_H
#include "journeymodel.h"
-
#include "stats.h"
class StatsWeekdayAve : public Stats
StatsWeekdayCongestion::StatsWeekdayCongestion(JourneyModel * journeys) :
journeys(journeys)
{
- title = "Congested days (cycles passed)";
+ title = "Congestion by day (cycles per hour)";
units = "";
labels = QStringList{"M", "T", "W", "Th", "F", "S", "Su"};
}
void StatsWeekdayCongestion::update() {
- quint32 passed[7];
+ double passed[7];
unsigned int count[7];
int pos;
foreach (Journey const &journey, journeys->getData()) {
QDate date = journey.getStartDate();
int dayofweek = date.dayOfWeek() - 1;
+ double duration = journey.getDuration() / (60.0 * 60.0);
if (dayofweek >= 0) {
- passed[dayofweek] += journey.getOvertook() + journey.getOvertakenBy();
+ passed[dayofweek] += (journey.getOvertook() + journey.getOvertakenBy()) / duration;
count[dayofweek]++;
}
}
values << result;
}
- step = qRound(maxval / 5.0);
+ step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
qDebug() << "Calculated values";
}
#define STATSWEEKDAYCONGESTION_H
#include "journeymodel.h"
-
#include "stats.h"
class StatsWeekdayCongestion : public Stats