From 7c09991876ef8b34bda6f5615a37f99e1b476b18 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 11 Nov 2012 10:36:46 +0100 Subject: [PATCH] Trim the dive to exclude surface time at beginning and end We don't change any of the samples, we just don't plot (or consider for dive time / mean calculations) the samples at the beginning or end of the dive that are less than a certain threshold under water. Right now that's an arbitrary 75cm which seems to Do The Right Thing(tm) for the dives I tried this with - but I'm happy to look at other values if this causes problems for people with dive computers I do not have access to. Signed-off-by: Dirk Hohndel --- dive.c | 6 ++++-- dive.h | 3 +++ profile.c | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dive.c b/dive.c index 65cfc4d53..384b8dcad 100644 --- a/dive.c +++ b/dive.c @@ -449,10 +449,10 @@ struct dive *fixup_dive(struct dive *dive) lastindex = index; lastpressure = pressure; - if (lastdepth) + if (lastdepth > SURFACE_THRESHOLD) end = time; - if (depth) { + if (depth > SURFACE_THRESHOLD) { if (start < 0) start = lasttime; if (depth > maxdepth) @@ -479,6 +479,8 @@ struct dive *fixup_dive(struct dive *dive) lastdepth = depth; lasttime = time; } + dive->start = start; + dive->end = end; /* if all the samples for a cylinder have pressure data that * is basically equidistant throw out the sample cylinder pressure * information but make sure we still have a valid start and end diff --git a/dive.h b/dive.h index ff5b37a18..8a79de0b2 100644 --- a/dive.h +++ b/dive.h @@ -261,6 +261,7 @@ struct dive { tripflag_t tripflag; dive_trip_t *divetrip; int selected; + int start, end; timestamp_t when; char *location; char *notes; @@ -296,6 +297,8 @@ static inline int depth_to_mbar(int depth, struct dive *dive) return depth / 10.0 * specific_weight + surface_pressure + 0.5; } +#define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */ + /* this is a global spot for a temporary dive structure that we use to * be able to edit a dive without unintended side effects */ extern struct dive edit_dive; diff --git a/profile.c b/profile.c index 6eab3b240..065934746 100644 --- a/profile.c +++ b/profile.c @@ -1704,6 +1704,10 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str int delay = 0; struct sample *sample = dive_sample+i; + if (sample->time.seconds < dive->start || sample->time.seconds > dive->end) { + pi_idx--; + continue; + } entry = pi->entry + i + pi_idx; while (ceil_ev && ceil_ev->time.seconds <= sample->time.seconds) { struct event *next_ceil_ev = get_next_event(ceil_ev->next, "ceiling");