Skip to content

Commit

Permalink
Fix Suunto FIT file import dive duration mis-calculation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
torvalds authored and dirkhh committed Aug 27, 2024
1 parent 069f8a5 commit 914cdb1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/divecomputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 914cdb1

Please sign in to comment.