From 8a0d852a7c17643bd6d45751c8b7489c23699829 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 9 Jun 2014 22:45:44 -0700 Subject: Add gas consumption statistic for selected dives We already did a list of gases and volume consumed for the selected dive on the Dive Info tab, but did not provide that same data on the Stats tab for all the selected dives. I arbitrary limited this to eight gases (as the list can get quite long when you select a lot of dives). The gases are sorted by volume consumed. Fixes #535 Signed-off-by: Dirk Hohndel --- helpers.h | 1 + qt-ui/maintab.cpp | 17 +++++++++++++++++ qt-ui/maintab.ui | 46 +++++++++++++++++++++++++++++++++------------- qthelper.cpp | 31 ++++++++++++++++++++++++++++++- 4 files changed, 81 insertions(+), 14 deletions(-) diff --git a/helpers.h b/helpers.h index 445e9135c..392dcb5ac 100644 --- a/helpers.h +++ b/helpers.h @@ -33,6 +33,7 @@ QString get_dive_date_string(timestamp_t when); QString get_short_dive_date_string(timestamp_t when); QString get_trip_date_string(timestamp_t when, int nr); QString uiLanguage(QLocale *callerLoc); +void selectedDivesGasUsed(QVector > &gasUsed); #define M_OR_FT(_m, _f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : (feet_to_mm(_f))) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 19b47c872..5b8985b3e 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -530,6 +530,23 @@ void MainTab::updateDiveInfo(int dive) ui.timeLimits->setAverage(get_time_string(seconds, 0)); ui.timeLimits->setMaximum(get_time_string(stats_selection.longest_time.seconds, 0)); ui.timeLimits->setMinimum(get_time_string(stats_selection.shortest_time.seconds, 0)); + // now let's get some gas use statistics + QVector > gasUsed; + QString gasUsedString; + QPair topGases[8] = { }; + volume_t vol; + selectedDivesGasUsed(gasUsed); + for (int j = 0; j < 8; j++) { + if (gasUsed.isEmpty()) + break; + QPair gasPair = gasUsed.last(); + gasUsed.pop_back(); + vol.mliter = gasPair.second; + gasUsedString.append(gasPair.first).append(": ").append(get_volume_string(vol, true)).append("\n"); + } + if (!gasUsed.isEmpty()) + gasUsedString.append("..."); + ui.gasConsumption->setText(gasUsedString); } else { /* clear the fields */ clearInfo(); diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 904a49304..2a0d3353e 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -37,8 +37,8 @@ 0 0 - 662 - 649 + 668 + 658 @@ -289,8 +289,8 @@ 0 0 - 662 - 649 + 100 + 30 @@ -369,8 +369,8 @@ 0 0 - 662 - 649 + 387 + 285 @@ -679,8 +679,8 @@ 0 0 - 662 - 649 + 337 + 157 @@ -766,7 +766,7 @@ - + Dives @@ -785,8 +785,27 @@ - - + + + + Gas Consumption + + + + + + + + + Qt::AlignCenter + + + + + + + + Qt::Vertical @@ -795,8 +814,8 @@ - 20 - 20 + 0 + 0 @@ -808,6 +827,7 @@ groupBox_14 groupBoxb groupBox_7b + groupBox_13 diff --git a/qthelper.cpp b/qthelper.cpp index 7eba936a6..8b7b3960f 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1,11 +1,12 @@ #include "qthelper.h" #include "qt-gui.h" #include "dive.h" +#include "statistics.h" #include #include "file.h" #include #include - +#include #include #include #include @@ -280,3 +281,31 @@ extern "C" void picture_load_exif_data(struct picture *p, timestamp_t *timestamp free(mem.buffer); return; } + +static bool lessThan(const QPair &a, const QPair &b) +{ + return a.second < b.second; +} + +void selectedDivesGasUsed(QVector > &gasUsedOrdered) +{ + int i, j; + struct dive *d; + QString gas; + QMap gasUsed; + for_each_dive (i, d) { + if (!d->selected) + continue; + volume_t diveGases[MAX_CYLINDERS] = {}; + get_gas_used(d, diveGases); + for (j = 0; j < MAX_CYLINDERS; j++) + if (diveGases[j].mliter) { + QString gasName = gasname(&d->cylinder[j].gasmix); + gasUsed[gasName] += diveGases[j].mliter; + } + } + Q_FOREACH(gas, gasUsed.keys()) { + gasUsedOrdered.append(QPair(gas, gasUsed[gas])); + } + qSort(gasUsedOrdered.begin(), gasUsedOrdered.end(), lessThan); +} -- cgit v1.2.3-70-g09d2