Fix Suunto FIT file import dive duration mis-calculation

The Suunto FIT files end up creating a sample every second, but a lot of
those samples with no depth information, marked as "depth.mm" being negative.

That doesn't end up being a problem for subsurface, _except_ that it
really confuses our "dc_fixup_duration()" logic, and the dive duration
ends up being completely nonsensical (generally roughly by a factor of
five: every tenth sample has a depth, and we only count samples that
"begin or end under water" as being relevant for the dive duration, so
two out of the ten samples will count towards the dive time).

Saving the dive will then not save these invalid depths, so saving and
reloading the dive ends up fixing the dive duration calculation.

The fix is trivial - we just ignore samples with negative depth in
dc_fixup_duration().

The FIT file parser should probably be taught to not even bother sending
empty samples to subsurface, but that's a separate cleanup.  This fixes
the actual bad behavior.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2024-08-26 16:48:19 +12:00 committed by Dirk Hohndel
parent 069f8a5d18
commit 914cdb102b

View file

@ -272,6 +272,10 @@ void fixup_dc_duration(struct divecomputer &dc)
int time = sample.time.seconds;
int depth = sample.depth.mm;
/* Do we *have* a depth? */
if (depth < 0)
continue;
/* We ignore segments at the surface */
if (depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) {
duration += time - lasttime;