mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
When merging non-overlapping dives, add surface events in between
Most of the dive computers I have access to don't do the whole surface event thing at the beginning or the end of the dive, so when you merge two consecutive dives, you got this odd merged dive where the diver spent the time in between at a depth of 1.2m or so (whatever the dive computer "I'm now under water" depth limit happens to be). Don't do that. Add surface events at the end of the first dive to be merged, and the beginning of the second one, so that the time in between dives is properly marked as being at the surface. The logic for "time in between dives" is a bit iffy - it's "more than 60 seconds with no samples". If somebody has dive computers with samples more than 60 seconds apart, this will break and we may have to revisit the logic. But dang, that's some seriously broken sample rate. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
d166e34fed
commit
8a45a3ffb9
1 changed files with 26 additions and 3 deletions
29
dive.c
29
dive.c
|
@ -605,6 +605,29 @@ static struct dive *add_sample(struct sample *sample, int time, struct dive *div
|
|||
return dive;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is like add_sample(), but if the distance from the last sample
|
||||
* is excessive, we add two surface samples in between.
|
||||
*
|
||||
* This is so that if you merge two non-overlapping dives, we make sure
|
||||
* that the time in between the dives is at the surface, not some "last
|
||||
* sample that happened to be at a depth of 1.2m".
|
||||
*/
|
||||
static struct dive *merge_one_sample(struct sample *sample, int time, struct dive *dive)
|
||||
{
|
||||
int last = dive->samples-1;
|
||||
if (last >= 0) {
|
||||
static struct sample surface;
|
||||
int last_time = dive->sample[last].time.seconds;
|
||||
if (time > last_time + 60) {
|
||||
dive = add_sample(&surface, last_time+20, dive);
|
||||
dive = add_sample(&surface, time - 20, dive);
|
||||
}
|
||||
}
|
||||
return add_sample(sample, time, dive);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Merge samples. Dive 'a' is "offset" seconds before Dive 'b'
|
||||
*/
|
||||
|
@ -647,7 +670,7 @@ static struct dive *merge_samples(struct dive *res, struct dive *a, struct dive
|
|||
/* Only samples from a? */
|
||||
if (bt < 0) {
|
||||
add_sample_a:
|
||||
res = add_sample(as, at, res);
|
||||
res = merge_one_sample(as, at, res);
|
||||
as++;
|
||||
asamples--;
|
||||
continue;
|
||||
|
@ -656,7 +679,7 @@ add_sample_a:
|
|||
/* Only samples from b? */
|
||||
if (at < 0) {
|
||||
add_sample_b:
|
||||
res = add_sample(bs, bt, res);
|
||||
res = merge_one_sample(bs, bt, res);
|
||||
bs++;
|
||||
bsamples--;
|
||||
continue;
|
||||
|
@ -678,7 +701,7 @@ add_sample_b:
|
|||
if (as->cylinderindex)
|
||||
sample.cylinderindex = as->cylinderindex;
|
||||
|
||||
res = add_sample(&sample, at, res);
|
||||
res = merge_one_sample(&sample, at, res);
|
||||
|
||||
as++;
|
||||
bs++;
|
||||
|
|
Loading…
Add table
Reference in a new issue