Calculate approx gas bill on dives

This uses a bit of naive gas computations to figure out how much of
different base gases you used up on the dives the statistics is done for.

It's quite useful to get a minimum line about how big your gas bill is
going to be after a dive trip.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Anton Lundin 2014-06-29 20:01:56 +02:00 committed by Dirk Hohndel
parent c020cda41b
commit b2288e1e3d
3 changed files with 40 additions and 0 deletions

View file

@ -552,6 +552,9 @@ void MainTab::updateDiveInfo(int dive)
}
if (!gasUsed.isEmpty())
gasUsedString.append("...");
volume_t o2_tot = {}, he_tot = {};
selected_dives_gas_parts(&o2_tot, &he_tot);
gasUsedString.append(QString("These gases could be\nmixed from Air and using:\nHe: %1 and O2: %2\n").arg(get_volume_string(he_tot, true)).arg(get_volume_string(o2_tot, true)));
ui.gasConsumption->setText(gasUsedString);
} else {
/* clear the fields */

View file

@ -357,3 +357,39 @@ char *get_gaslist(struct dive *dive)
buf[MAXBUF - 1] = '\0';
return buf;
}
/* Quite crude reverse-blender-function, but it produces a approx result */
static void get_gas_parts(struct gasmix mix, volume_t vol, int o2_in_topup, volume_t *o2, volume_t *he)
{
volume_t air = {};
if (gasmix_is_air(&mix)) {
o2->mliter = 0;
he->mliter = 0;
return;
}
air.mliter = (vol.mliter * (1000 - get_he(&mix) - get_o2(&mix))) / (1000 - o2_in_topup);
he->mliter = (vol.mliter * get_he(&mix)) / 1000;
o2->mliter += vol.mliter - he->mliter - air.mliter;
}
void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot)
{
int i, j;
struct dive *d;
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) {
volume_t o2 = {}, he = {};
get_gas_parts(d->cylinder[j].gasmix, diveGases[j], O2_IN_AIR, &o2, &he);
o2_tot->mliter += o2.mliter;
he_tot->mliter += he.mliter;
}
}
}
}

View file

@ -47,6 +47,7 @@ extern void get_selected_dives_text(char *buffer, int size);
extern void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]);
extern char *get_gaslist(struct dive *dive);
extern void process_selected_dives(void);
void selected_dives_gas_parts(volume_t *o2_tot, volume_t *he_tot);
#ifdef __cplusplus
}