X-Git-Url: https://www.flypig.org.uk/git/?p=harbour-pedalo.git;a=blobdiff_plain;f=src%2Fstatus.cpp;h=aeff901f69d5f67ea29d7ffd3f42a62049cbb8c4;hp=b4bb630abf99c36d9944c5fe495e0b2a916bd683;hb=41ee443df2b12e7a4373be580006f57cc5fd768a;hpb=5fc520bad80dccf9bf2e0f16552c9f2605417067 diff --git a/src/status.cpp b/src/status.cpp index b4bb630..aeff901 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; } @@ -96,7 +109,6 @@ QString Status::getFormattedTime(quint64 seconds, int min, int max) { portion = (unit == max - 1) ? remaining : remaining % base[unit]; portions << portion; remaining /= base[unit]; - qDebug() << plural[unit] << ": " << portion; } formatted = ""; @@ -111,6 +123,15 @@ QString Status::getFormattedTime(quint64 seconds, int min, int max) { } } + if (formatted == "") { + formatted = "None"; + } + return formatted; } +QList Status::getGraphData() { + static QList data({0.1, 0.2, 0.3, 0.4, 1.0, 0.8, 0.7, 0.9, 0.5, 1.0}); + + return data; +}