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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-06-09 22:45:44 -07:00
parent 0102604645
commit 8a0d852a7c
4 changed files with 81 additions and 14 deletions

View file

@ -1,11 +1,12 @@
#include "qthelper.h"
#include "qt-gui.h"
#include "dive.h"
#include "statistics.h"
#include <exif.h>
#include "file.h"
#include <QRegExp>
#include <QDir>
#include <QMap>
#include <QDebug>
#include <QSettings>
#include <libxslt/documents.h>
@ -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<QString, int> &a, const QPair<QString, int> &b)
{
return a.second < b.second;
}
void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsedOrdered)
{
int i, j;
struct dive *d;
QString gas;
QMap<QString, int> 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<QString, int>(gas, gasUsed[gas]));
}
qSort(gasUsedOrdered.begin(), gasUsedOrdered.end(), lessThan);
}