[PATCH 2/2] Tune the dive joining surface event insert code

Linus Torvalds torvalds at linux-foundation.org
Fri Dec 7 09:42:47 PST 2012


>From 178a3f0d6d5112f76943fec5f8c1c1f3b173a7f4 Mon Sep 17 00:00:00 2001
From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Fri, 7 Dec 2012 09:34:18 -0800
Subject: [PATCH 2/2] Tune the dive joining surface event insert code

So this makes us do surface events only if the samples are more than one
minute apart, and are shallow enough (randomly selected at 5m).

We can add more heuristics.  Maybe we should compare the 1-minute sample
time limit of the previous sample to the time to the sample before that:
if some computer (or manually entered dive) has a long time between
*all* samples, we'd make the cut-off time longer.

Baby steps.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

I'll think about the other heuristics. This fixes the particular test-case 
Dirk added, but you could just change the test-case to have the few events 
they have at a much shallower depth, and it will show the same issue.

At some point it will have to be just a judgement call, but looking at how 
dense the events are may well be at least *one* more input to the 
heuristics. Currently this only looks at time between events and now the 
depths of the samples.

 dive.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/dive.c b/dive.c
index 5edb6087f887..d4e0217d7d4d 100644
--- a/dive.c
+++ b/dive.c
@@ -614,8 +614,15 @@ static void merge_one_sample(struct sample *sample, int time, struct divecompute
 	int last = dc->samples-1;
 	if (last >= 0) {
 		static struct sample surface;
-		int last_time = dc->sample[last].time.seconds;
-		if (time > last_time + 60) {
+		struct sample *prev = dc->sample + last;
+		int last_time = prev->time.seconds;
+		int last_depth = prev->depth.mm;
+
+		/*
+		 * Only do surface events if the samples are more than
+		 * a minute apart, and shallower than 5m
+		 */
+		if (time > last_time + 60 && last_depth < 5000) {
 			add_sample(&surface, last_time+20, dc);
 			add_sample(&surface, time - 20, dc);
 		}
-- 
1.8.0



More information about the subsurface mailing list