Commit 49c341bb authored by Volker Krause's avatar Volker Krause
Browse files

Only include transport modes in the statistics that at least have one entry

This hides those modes that have never been used, and thus are likely
irrelevant for the user.
parent d2cf3707
Pipeline #207725 passed with stage
in 4 minutes and 41 seconds
......@@ -64,39 +64,50 @@ private Q_SLOTS:
auto item = stats.totalCount();
QCOMPARE(item.m_value, QLatin1String("2"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.totalNights();
QCOMPARE(item.m_value, QLatin1String("13"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.totalDistance();
QCOMPARE(item.m_value, QLatin1String("6,182 km"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.totalCO2();
QCOMPARE(item.m_value, QLatin1String("1,673 kg"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.flightCount();
QCOMPARE(item.m_value, QLatin1String("6"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.flightDistance();
QCOMPARE(item.m_value, QLatin1String("5,859 km"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.flightCO2();
QCOMPARE(item.m_value, QLatin1String("1,668 kg"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.trainCount();
QCOMPARE(item.m_value, QLatin1String("4"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.trainDistance();
QCOMPARE(item.m_value, QLatin1String("323 km"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.trainCO2();
QCOMPARE(item.m_value, QLatin1String("4.5 kg"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, true);
item = stats.carCount();
QCOMPARE(item.m_value, QLatin1String("0"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnknown);
QCOMPARE(item.m_hasData, false);
changeSpy.clear();
stats.setTimeRange({2017, 9, 1}, {2018, 1, 1});
......@@ -104,35 +115,50 @@ private Q_SLOTS:
item = stats.totalCount();
QCOMPARE(item.m_value, QLatin1String("1"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUnchanged);
QCOMPARE(item.m_hasData, true);
item = stats.totalNights();
QCOMPARE(item.m_value, QLatin1String("5"));
QCOMPARE(item.m_trend, StatisticsItem::TrendDown);
QCOMPARE(item.m_hasData, true);
item = stats.totalDistance();
QCOMPARE(item.m_value, QLatin1String("1,642 km"));
QCOMPARE(item.m_trend, StatisticsItem::TrendDown);
QCOMPARE(item.m_hasData, true);
item = stats.totalCO2();
QCOMPARE(item.m_value, QLatin1String("380 kg"));
QCOMPARE(item.m_trend, StatisticsItem::TrendDown);
QCOMPARE(item.m_hasData, true);
item = stats.flightCount();
QCOMPARE(item.m_value, QLatin1String("2"));
QCOMPARE(item.m_trend, StatisticsItem::TrendDown);
QCOMPARE(item.m_hasData, true);
item = stats.flightDistance();
QCOMPARE(item.m_value, QLatin1String("1,319 km"));
QCOMPARE(item.m_trend, StatisticsItem::TrendDown);
QCOMPARE(item.m_hasData, true);
item = stats.flightCO2();
QCOMPARE(item.m_value, QLatin1String("375 kg"));
QCOMPARE(item.m_trend, StatisticsItem::TrendDown);
QCOMPARE(item.m_hasData, true);
item = stats.trainCount();
QCOMPARE(item.m_value, QLatin1String("4"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUp);
QCOMPARE(item.m_hasData, true);
item = stats.trainDistance();
QCOMPARE(item.m_value, QLatin1String("323 km"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUp);
QCOMPARE(item.m_hasData, true);
item = stats.trainCO2();
QCOMPARE(item.m_value, QLatin1String("4.5 kg"));
QCOMPARE(item.m_trend, StatisticsItem::TrendUp);
QCOMPARE(item.m_hasData, true);
QCOMPARE(stats.boatCount().m_value, QLatin1String("0"));
QCOMPARE(stats.boatCount().m_hasData, false);
QCOMPARE(stats.boatDistance().m_hasData, false);
QCOMPARE(stats.boatCO2().m_hasData, false);
}
void testTimeRangeModel()
......
......@@ -16,6 +16,7 @@ RowLayout {
property var statItem
property alias label: labelItem
visible: statItem.hasData
Kirigami.FormData.label: root.statItem.label
Layout.fillWidth: true
......
......@@ -84,6 +84,7 @@ Kirigami.ScrollablePage {
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Flights")
visible: model.flightCount.hasData
}
StatisticsDelegate { statItem: model.flightCount }
StatisticsDelegate { statItem: model.flightDistance }
......@@ -92,6 +93,7 @@ Kirigami.ScrollablePage {
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Trains")
visible: model.trainCount.hasData
}
StatisticsDelegate { statItem: model.trainCount }
StatisticsDelegate { statItem: model.trainDistance }
......@@ -100,6 +102,7 @@ Kirigami.ScrollablePage {
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Bus")
visible: model.busCoutn.hasData
}
StatisticsDelegate { statItem: model.busCount }
StatisticsDelegate { statItem: model.busDistance }
......@@ -108,6 +111,7 @@ Kirigami.ScrollablePage {
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Boat")
visible: model.boatCount.hasData
}
StatisticsDelegate { statItem: model.boatCount }
StatisticsDelegate { statItem: model.boatDistance }
......@@ -116,6 +120,7 @@ Kirigami.ScrollablePage {
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Car")
visible: model.carCount.hasData
}
StatisticsDelegate { statItem: model.carCount }
StatisticsDelegate { statItem: model.carDistance }
......
......@@ -23,10 +23,11 @@ using namespace KItinerary;
StatisticsItem::StatisticsItem() = default;
StatisticsItem::StatisticsItem(const QString &label, const QString &value, StatisticsItem::Trend trend)
StatisticsItem::StatisticsItem(const QString &label, const QString &value, StatisticsItem::Trend trend, bool hasData)
: m_label(label)
, m_value(value)
, m_trend(trend)
, m_hasData(hasData)
{
}
......@@ -123,77 +124,77 @@ StatisticsItem StatisticsModel::visitedCountries() const
StatisticsItem StatisticsModel::flightCount() const
{
return StatisticsItem(i18n("Flights"), QLocale().toString(m_statData[Flight][TripCount]), trend(Flight, TripCount));
return StatisticsItem(i18n("Flights"), QLocale().toString(m_statData[Flight][TripCount]), trend(Flight, TripCount), m_hasData[Flight]);
}
StatisticsItem StatisticsModel::flightDistance() const
{
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Flight][Distance] / 1000), trend(Flight, Distance));
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Flight][Distance] / 1000), trend(Flight, Distance), m_hasData[Flight]);
}
StatisticsItem StatisticsModel::flightCO2() const
{
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Flight][CO2]), trend(Flight, CO2));
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Flight][CO2]), trend(Flight, CO2), m_hasData[Flight]);
}
StatisticsItem StatisticsModel::trainCount() const
{
return StatisticsItem(i18n("Train rides"), QLocale().toString(m_statData[Train][TripCount]), trend(Train, TripCount));
return StatisticsItem(i18n("Train rides"), QLocale().toString(m_statData[Train][TripCount]), trend(Train, TripCount), m_hasData[Train]);
}
StatisticsItem StatisticsModel::trainDistance() const
{
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Train][Distance] / 1000), trend(Train, Distance));
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Train][Distance] / 1000), trend(Train, Distance), m_hasData[Train]);
}
StatisticsItem StatisticsModel::trainCO2() const
{
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Train][CO2]), trend(Train, CO2));
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Train][CO2]), trend(Train, CO2), m_hasData[Train]);
}
StatisticsItem StatisticsModel::busCount() const
{
return StatisticsItem(i18n("Bus rides"), QLocale().toString(m_statData[Bus][TripCount]), trend(Bus, TripCount));
return StatisticsItem(i18n("Bus rides"), QLocale().toString(m_statData[Bus][TripCount]), trend(Bus, TripCount), m_hasData[Bus]);
}
StatisticsItem StatisticsModel::busDistance() const
{
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Bus][Distance] / 1000), trend(Bus, Distance));
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Bus][Distance] / 1000), trend(Bus, Distance), m_hasData[Bus]);
}
StatisticsItem StatisticsModel::busCO2() const
{
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Bus][CO2]), trend(Bus, CO2));
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Bus][CO2]), trend(Bus, CO2), m_hasData[Bus]);
}
StatisticsItem StatisticsModel::carCount() const
{
return StatisticsItem(i18n("Car rides"), QLocale().toString(m_statData[Car][TripCount]), trend(Car, TripCount));
return StatisticsItem(i18n("Car rides"), QLocale().toString(m_statData[Car][TripCount]), trend(Car, TripCount), m_hasData[Car]);
}
StatisticsItem StatisticsModel::carDistance() const
{
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Car][Distance] / 1000), trend(Car, Distance));
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Car][Distance] / 1000), trend(Car, Distance), m_hasData[Car]);
}
StatisticsItem StatisticsModel::carCO2() const
{
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Car][CO2]), trend(Car, CO2));
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Car][CO2]), trend(Car, CO2), m_hasData[Car]);
}
StatisticsItem StatisticsModel::boatCount() const
{
return StatisticsItem(i18n("Boat trips"), QLocale().toString(m_statData[Boat][TripCount]), trend(Boat, TripCount));
return StatisticsItem(i18n("Boat trips"), QLocale().toString(m_statData[Boat][TripCount]), trend(Boat, TripCount), m_hasData[Boat]);
}
StatisticsItem StatisticsModel::boatDistance() const
{
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Boat][Distance] / 1000), trend(Boat, Distance));
return StatisticsItem(i18n("Distance"), i18n("%1 km", m_statData[Boat][Distance] / 1000), trend(Boat, Distance), m_hasData[Boat]);
}
StatisticsItem StatisticsModel::boatCO2() const
{
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Boat][CO2]), trend(Boat, CO2));
return StatisticsItem(i18n("CO₂"), formatCo2(m_statData[Boat][CO2]), trend(Boat, CO2), m_hasData[Boat]);
}
StatisticsModel::AggregateType StatisticsModel::typeForReservation(const QVariant &res) const
......@@ -259,6 +260,8 @@ void StatisticsModel::recompute()
{
memset(m_statData, 0, AGGREGATE_TYPE_COUNT * STAT_TYPE_COUNT * sizeof(int));
memset(m_prevStatData, 0, AGGREGATE_TYPE_COUNT * STAT_TYPE_COUNT * sizeof(int));
memset(m_hasData, 0, AGGREGATE_TYPE_COUNT * sizeof(bool));
m_hasData[Total] = true;
m_hotelCount = 0;
m_prevHotelCount = 0;
m_countries.clear();
......@@ -277,6 +280,9 @@ void StatisticsModel::recompute()
const auto &batches = m_resMgr->batches();
for (const auto &batchId : batches) {
const auto res = m_resMgr->reservation(batchId);
if (LocationUtil::isLocationChange(res)) {
m_hasData[typeForReservation(res)] = true;
}
const auto dt = SortUtil::startDateTime(res);
bool isPrev = false;
......
......@@ -19,6 +19,7 @@ class TripGroupManager;
class StatisticsItem
{
Q_GADGET
Q_PROPERTY(bool hasData MEMBER m_hasData CONSTANT)
Q_PROPERTY(QString label MEMBER m_label CONSTANT)
Q_PROPERTY(QString value MEMBER m_value CONSTANT)
Q_PROPERTY(Trend trend MEMBER m_trend CONSTANT)
......@@ -33,12 +34,13 @@ public:
Q_ENUM(Trend)
StatisticsItem();
explicit StatisticsItem(const QString &label, const QString &value, StatisticsItem::Trend trend = TrendUnknown);
explicit StatisticsItem(const QString &label, const QString &value, StatisticsItem::Trend trend = TrendUnknown, bool hasData = true);
~StatisticsItem();
QString m_label;
QString m_value;
Trend m_trend = TrendUnknown;
bool m_hasData = true;
};
Q_DECLARE_METATYPE(StatisticsItem)
......@@ -139,6 +141,7 @@ private:
int m_statData[AGGREGATE_TYPE_COUNT][STAT_TYPE_COUNT];
int m_prevStatData[AGGREGATE_TYPE_COUNT][STAT_TYPE_COUNT];
bool m_hasData[AGGREGATE_TYPE_COUNT];
int m_hotelCount = 0;
int m_prevHotelCount = 0;
int m_tripGroupCount = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment