[PATCH] Calculate approx gas bill on dives

Anton Lundin glance at acc.umu.se
Sun Jun 29 11:01:56 PDT 2014


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

Its 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 at acc.umu.se>
---
 qt-ui/maintab.cpp |  3 +++
 statistics.c      | 36 ++++++++++++++++++++++++++++++++++++
 statistics.h      |  1 +
 3 files changed, 40 insertions(+)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index b3514e4..90a527e 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -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 */
diff --git a/statistics.c b/statistics.c
index 5da48f2..2f14911 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;
+			}
+		}
+	}
+}
diff --git a/statistics.h b/statistics.h
index 94a4961..e28fb8f 100644
--- a/statistics.h
+++ b/statistics.h
@@ -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
 }
-- 
1.9.1



More information about the subsurface mailing list