summaryrefslogtreecommitdiffstats
path: root/core/statistics.c
diff options
context:
space:
mode:
authorGravatar Robert Helling <helling@atdotde.de>2017-02-03 11:14:51 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-02-03 07:45:24 -0800
commit5aa9c6fa1ba1d2f2a38732fd3f87b24b0d15eb98 (patch)
tree1c2c5d07f5a7d43a4dcc677e05accb1f5aaef321 /core/statistics.c
parent67de8f3a4960941f7de7b49bac4a93e4448fdd63 (diff)
downloadsubsurface-5aa9c6fa1ba1d2f2a38732fd3f87b24b0d15eb98.tar.gz
Do not count gas used in planned dives for statistics
This is important if in one dive we have the real dive and a planned version of the dive as different computers using different sets of cylinders. [Dirk Hohndel: an early version of this was mistakenly pushed out by me; I reverted that and added this commit since fixing things up as I had done for the other two patches made things nearly unreadable] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/statistics.c')
-rw-r--r--core/statistics.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/core/statistics.c b/core/statistics.c
index 62a4d737f..d10854c01 100644
--- a/core/statistics.c
+++ b/core/statistics.c
@@ -326,41 +326,56 @@ void get_selected_dives_text(char *buffer, size_t size)
#define SOME_GAS 5000 // 5bar drop in cylinder pressure makes cylinder used
+bool has_gaschange_event(struct dive *dive, struct divecomputer *dc, int idx) {
+ bool first_gas_explicit = false;
+ struct event *event = get_next_event(dc->events, "gaschange");
+ while (event) {
+ if (dc->sample && (event->time.seconds == 0 ||
+ (dc->samples && dc->sample[0].time.seconds == event->time.seconds)))
+ first_gas_explicit = true;
+ if (get_cylinder_index(dive, event) == idx)
+ return true;
+ event = get_next_event(event->next, "gaschange");
+ }
+ if (dc->divemode == CCR && (idx == dive->diluent_cylinder_index || idx == dive->oxygen_cylinder_index))
+ return true;
+ return !first_gas_explicit && idx == 0;
+}
+
bool is_cylinder_used(struct dive *dive, int idx)
{
struct divecomputer *dc;
- bool firstGasExplicit = false;
if (cylinder_none(&dive->cylinder[idx]))
return false;
if ((dive->cylinder[idx].start.mbar - dive->cylinder[idx].end.mbar) > SOME_GAS)
return true;
for_each_dc(dive, dc) {
- struct event *event = get_next_event(dc->events, "gaschange");
- while (event) {
- if (dc->sample && (event->time.seconds == 0 ||
- (dc->samples && dc->sample[0].time.seconds == event->time.seconds)))
- firstGasExplicit = true;
- if (get_cylinder_index(dive, event) == idx)
- return true;
- event = get_next_event(event->next, "gaschange");
- }
- if (dc->divemode == CCR && (idx == dive->diluent_cylinder_index || idx == dive->oxygen_cylinder_index))
+ if (has_gaschange_event(dive, dc, idx))
return true;
}
- if (idx == 0 && !firstGasExplicit)
- return true;
return false;
}
void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])
{
int idx;
+ struct divecomputer *dc;
+ bool used;
+
for (idx = 0; idx < MAX_CYLINDERS; idx++) {
+ used = false;
cylinder_t *cyl = &dive->cylinder[idx];
pressure_t start, end;
- if (!is_cylinder_used(dive, idx))
+ for_each_dc(dive, dc) {
+ if (!strcmp(dc->model, "planned dive"))
+ continue;
+ if (has_gaschange_event(dive, dc, idx))
+ used = true;
+ }
+
+ if (!used)
continue;
start = cyl->start.mbar ? cyl->start : cyl->sample_start;