From 851af6c4deb0aabedf01ddc9e23511dca8ccbf7a Mon Sep 17 00:00:00 2001 From: David Llewellyn-Jones Date: Tue, 17 Jul 2018 18:42:49 +0100 Subject: [PATCH] Generate sensible stats when no journeys are logged Previouosly it was producing empty or "%NaN" results due to zero or division-by-zero calculations. Now it should show sensible text. There are also some changes made to allow the cover to work better on Jolla One and Jolla C devices. --- qml/cover/CoverPage.qml | 72 +++++++++++++++++-------------- qml/pages/About.qml | 2 +- src/status.cpp | 21 ++++++++- translations/harbour-pedalo-de.ts | 8 ++-- translations/harbour-pedalo.ts | 8 ++-- 5 files changed, 68 insertions(+), 43 deletions(-) diff --git a/qml/cover/CoverPage.qml b/qml/cover/CoverPage.qml index a4a911b..67d6a83 100644 --- a/qml/cover/CoverPage.qml +++ b/qml/cover/CoverPage.qml @@ -11,6 +11,13 @@ CoverBackground { stopwatchtrigger.restart() } + allowResize: true + + property int _maximumItems: height >= Theme.coverSizeLarge.height + ? 2 + : height >= Theme.coverSizeSmall.height ? 1 : 0 + + Item { id: stopwatch property int seconds: 0 @@ -45,46 +52,47 @@ CoverBackground { yScale: root.height / contents.height } - ClockView { - id: clockView - - anchors { - top: parent.top - left: parent.left - right: parent.right - margins: Theme.paddingLarge - } - height: width - } + ClockView { + id: clockView - LargeItem { - id: stopwatchView - - anchors { - top: clockView.bottom - topMargin: Theme.paddingMedium - leftMargin: Theme.paddingLarge - rightMargin: Theme.paddingLarge + anchors { + top: parent.top + left: parent.left + right: parent.right + margins: Theme.paddingLarge + } + height: width } - textVisible: root.update + LargeItem { + id: stopwatchView - title: qsTr("Pedalo") + anchors { + top: clockView.bottom + topMargin: Theme.paddingMedium + leftMargin: Theme.paddingLarge + rightMargin: Theme.paddingLarge + } - text: { - if (stopwatch.seconds < 60) { - return qsTr("%n seconds", "", stopwatch.seconds) - } else if (stopwatch.seconds < 60*60) { - return qsTr("%1 minutes").arg(Math.floor(stopwatch.seconds/60)) - } else { - var minutes = Math.floor(stopwatch.seconds/60) - var hours = Math.floor(minutes/60) - minutes = minutes % 60 - return qsTrId("%1h %2min").arg(hours).arg(minutes) + titleVisible: ((!root.update) && _maximumItems > 0) || (_maximumItems > 1) + textVisible: (root.update && (_maximumItems > 0)) + + title: qsTr("Pedalo") + + text: { + if (stopwatch.seconds < 60) { + return qsTr("%n seconds", "", stopwatch.seconds) + } else if (stopwatch.seconds < 60*60) { + return qsTr("%1 minutes").arg(Math.floor(stopwatch.seconds/60)) + } else { + var minutes = Math.floor(stopwatch.seconds/60) + var hours = Math.floor(minutes/60) + minutes = minutes % 60 + return qsTrId("%1h %2min").arg(hours).arg(minutes) + } } } } - } CoverActionList { id: coverAction diff --git a/qml/pages/About.qml b/qml/pages/About.qml index f732dd2..e526861 100644 --- a/qml/pages/About.qml +++ b/qml/pages/About.qml @@ -34,7 +34,7 @@ Page { } Label { - text: qsTr("Compare your pedalo performance with others") + text: qsTr("Compare your relative pedalo performance with others in a privacy-preserving way") wrapMode: Text.WordWrap font.pixelSize: Theme.fontSizeSmall anchors { diff --git a/src/status.cpp b/src/status.cpp index b4bb630..4a46cdf 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -57,8 +57,16 @@ quint64 Status::getTimeSpentCycling() const { double Status::getAverageDuration() const { quint64 time = getTimeSpentCycling(); quint64 count = Status::getJourneyCount(); + double average = 0.0; - return ((double)time / (double)count); + if (count > 0) { + average = ((double)time / (double)count); + } + else { + average = 0.0; + } + + return average; } double Status::getSpeedPercentile() const { @@ -74,7 +82,12 @@ double Status::getSpeedPercentile() const { overtakenby += journey.getOvertakenBy(); } - percentile = (double)overtook / (double)(overtook + overtakenby); + if (overtook + overtakenby > 0.0) { + percentile = (double)overtook / (double)(overtook + overtakenby); + } + else { + percentile = 0.0; + } return percentile; } @@ -111,6 +124,10 @@ QString Status::getFormattedTime(quint64 seconds, int min, int max) { } } + if (formatted == "") { + formatted = "None"; + } + return formatted; } diff --git a/translations/harbour-pedalo-de.ts b/translations/harbour-pedalo-de.ts index 801b26d..c974b69 100644 --- a/translations/harbour-pedalo-de.ts +++ b/translations/harbour-pedalo-de.ts @@ -14,10 +14,6 @@ About Pedalo - - Compare your pedalo performance with others - - Version: @@ -42,6 +38,10 @@ Email + + Compare your relative pedalo performance with others in a privacy-preserving way + + CoverPage diff --git a/translations/harbour-pedalo.ts b/translations/harbour-pedalo.ts index 801b26d..c974b69 100644 --- a/translations/harbour-pedalo.ts +++ b/translations/harbour-pedalo.ts @@ -14,10 +14,6 @@ About Pedalo - - Compare your pedalo performance with others - - Version: @@ -42,6 +38,10 @@ Email + + Compare your relative pedalo performance with others in a privacy-preserving way + + CoverPage -- 2.25.1