src/statsweekdayave.cpp \
src/statsweekdaycongestion.cpp \
src/statshourcongestion.cpp \
- src/statshourjourneys.cpp
+ src/statshourjourneys.cpp \
+ src/statsyearjourneys.cpp \
+ src/statsyearduration.cpp
DISTFILES += qml/harbour-pedalo.qml \
qml/cover/CoverPage.qml \
src/statsweekdayave.h \
src/statsweekdaycongestion.h \
src/statshourcongestion.h \
- src/statshourjourneys.h
+ src/statshourjourneys.h \
+ src/statsyearjourneys.h \
+ src/statsyearduration.h
height: (isPortrait ? (statsPage.height / 2.0) - Theme.paddingLarge : statsPage.height - Theme.paddingLarge - headerItem.height) - sectionHeaderItem.height
anchors.left: parent.left
bardata: barvalues
- //linedata: barvalues
+ linedata: linevalues
labelsx: labels
//labelsy: ["0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%"]
unitsy: units
painter->setBrush(Qt::NoBrush);
if (labelsxcount > 0) {
- for (count = 0; count < bars; count++) {
+ for (count = 0; count < labelsxcount; count++) {
QRectF rect(labelxgap + axiswidth + (labelfullwidth * count), size.height() - labelygap + 8.0, labelfullwidth, labelygap - 8.0);
painter->drawText(rect, Qt::AlignHCenter | Qt::NoClip | Qt::TextSingleLine, labelsx[count]);
//painter->drawRect(rect);
#include "statshourjourneys.h"
#include "statsweekdaycongestion.h"
#include "statshourcongestion.h"
+#include "statsyearjourneys.h"
+#include "statsyearduration.h"
#include "harbour-pedalo.h"
StatsModel statsmodel;
+ StatsYearDuration statsyearduration(&journeys);
+ statsmodel.addStats(statsyearduration);
+
+ StatsYearJourneys statsyearjourneys(&journeys);
+ statsmodel.addStats(statsyearjourneys);
+
StatsWeekdayAve statsweekdayave(&journeys);
statsmodel.addStats(statsweekdayave);
-#include <QDebug>
-
#include "statshourcongestion.h"
#define LOWESTHOUR (7)
unsigned int count[24];
int pos;
- qDebug() << "Calculating values";
barvalues.clear();
for (pos = 0; pos < 24; pos++) {
}
step = (maxval > 5.0) ? qRound(maxval / 5.0) : (maxval / 5.0);
-
- qDebug() << "Calculated values";
}
-#include <QDebug>
-
#include "statshourjourneys.h"
#define LOWESTHOUR (7)
StatsHourJourneys::StatsHourJourneys(JourneyModel * journeys) :
journeys(journeys)
{
- title = "Journey proportions per hour (%)";
+ title = "Journey proportion per hour (%)";
units = "%";
labels.clear();
quint64 totalmins;
int pos;
- qDebug() << "Calculating values";
barvalues.clear();
for (pos = 0; pos < 24; pos++) {
}
barvalues << result;
}
-
- qDebug() << "Calculated values";
}
-#include <QDebug>
-
#include "statsweekdayave.h"
StatsWeekdayAve::StatsWeekdayAve(JourneyModel * journeys) :
unsigned int count[7];
int pos;
- qDebug() << "Calculating values";
barvalues.clear();
for (pos = 0; pos < 7; pos++) {
}
step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
-
- qDebug() << "Calculated values";
}
-
-
-#include <QDebug>
-
#include "statsweekdaycongestion.h"
StatsWeekdayCongestion::StatsWeekdayCongestion(JourneyModel * journeys) :
unsigned int count[7];
int pos;
- qDebug() << "Calculating values";
barvalues.clear();
for (pos = 0; pos < 7; pos++) {
}
step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
-
- qDebug() << "Calculated values";
}
--- /dev/null
+#include "statsyearduration.h"
+
+#define WINDOW (3)
+
+StatsYearDuration::StatsYearDuration(JourneyModel * journeys) :
+ journeys(journeys)
+{
+ title = QString("Year view (hours/mon + moving ave)");
+ units = "";
+}
+
+void StatsYearDuration::update() {
+ double duration[12];
+ double average[11 + WINDOW];
+ int pos;
+ QDate now;
+ QDate start;
+ QDate startave;
+
+ now = QDate::currentDate();
+ start = now.addMonths(-12);
+ startave = start.addMonths(1 - WINDOW);
+
+ barvalues.clear();
+ linevalues.clear();
+
+ for (pos = 0; pos < 12; pos++) {
+ duration[pos] = 0.0;
+ average[pos] = 0.0;
+ }
+
+ foreach (Journey const &journey, journeys->getData()) {
+ QDate date = journey.getStartDate();
+ if (date > start) {
+ duration[(date.month() - now.month() + 11) % 12] += journey.getDuration() / (60.0 * 60.0);
+ }
+ if (date > startave) {
+ int month = (date.month() - now.month() + 11) % 12;
+ for (pos = 0; pos < WINDOW; pos++) {
+ average[month + pos] += journey.getDuration() / (60.0 * 60.0);
+ }
+ }
+ }
+
+ labels = QStringList{"J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"};
+ for (pos = 0; pos < now.month(); pos++) {
+ // Rotate values
+ labels.push_back(labels.takeFirst());
+ }
+
+ maxval = 0.0;
+ for (pos = 0; pos < 12; pos++) {
+ if (duration[pos] > maxval) {
+ maxval = duration[pos];
+ }
+ barvalues << duration[pos];
+ linevalues << average[pos] / (double)WINDOW;
+ }
+
+ step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
+}
--- /dev/null
+#ifndef STATSYEARDURATION_H
+#define STATSYEARDURATION_H
+
+#include "journeymodel.h"
+#include "stats.h"
+
+class StatsYearDuration : public Stats
+{
+public:
+ StatsYearDuration(JourneyModel * journeys);
+
+ void update();
+
+private:
+ JourneyModel * journeys;
+};
+
+#endif // STATSYEARDURATION_H
--- /dev/null
+#include "statsyearjourneys.h"
+
+#define WINDOW (3)
+
+StatsYearJourneys::StatsYearJourneys(JourneyModel * journeys) :
+ journeys(journeys)
+{
+ title = QString("Year view (journeys/mon + moving ave)");
+ units = "";
+}
+
+void StatsYearJourneys::update() {
+ unsigned int count[12];
+ unsigned int average[11 + WINDOW];
+ int pos;
+ QDate now;
+ QDate start;
+ QDate startave;
+
+ now = QDate::currentDate();
+ start = now.addMonths(-12);
+ startave = start.addMonths(1 - WINDOW);
+
+ barvalues.clear();
+ linevalues.clear();
+
+ for (pos = 0; pos < 12; pos++) {
+ count[pos] = 0u;
+ average[pos] = 0u;
+ }
+
+ foreach (Journey const &journey, journeys->getData()) {
+ QDate date = journey.getStartDate();
+ if (date > start) {
+ count[(date.month() - now.month() + 11) % 12]++;
+ }
+ if (date > startave) {
+ int month = (date.month() - now.month() + 11) % 12;
+ for (pos = 0; pos < WINDOW; pos++) {
+ average[month + pos]++;
+ }
+ }
+ }
+
+ labels = QStringList{"J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"};
+ for (pos = 0; pos < now.month(); pos++) {
+ // Rotate values
+ labels.push_back(labels.takeFirst());
+ }
+
+ maxval = 0.0;
+ for (pos = 0; pos < 12; pos++) {
+ if (count[pos] > maxval) {
+ maxval = count[pos];
+ }
+ barvalues << (float)count[pos];
+ linevalues << (float)average[pos] / (float)WINDOW;
+ }
+
+ step = maxval > 5.0 ? qRound(maxval / 5.0) : (maxval / 5.0);
+}
--- /dev/null
+#ifndef STATSYEARJOURNEYS_H
+#define STATSYEARJOURNEYS_H
+
+#include "journeymodel.h"
+#include "stats.h"
+
+class StatsYearJourneys : public Stats
+{
+public:
+ StatsYearJourneys(JourneyModel * journeys);
+
+ void update();
+
+private:
+ JourneyModel * journeys;
+};
+
+#endif // STATSYEARJOURNEYS_H