summaryrefslogtreecommitdiffstats
path: root/statistics.c
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2014-06-29 20:01:56 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-29 17:15:09 -0700
commitb2288e1e3d231ed9d5629942730d49cb7ffec96b (patch)
treee0fa650bfb8c21c2713f0f172a78aa92d95e9011 /statistics.c
parentc020cda41b7319b7d419607f3f52d830cee4dc98 (diff)
downloadsubsurface-b2288e1e3d231ed9d5629942730d49cb7ffec96b.tar.gz
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>
Diffstat (limited to 'statistics.c')
-rw-r--r--statistics.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/statistics.c b/statistics.c
index 5da48f225..2f149113d 100644
--- a/statistics.c
+++ b/statistics.c
@@ -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;
+ }
+ }
+ }
+}