remora-kit

RemoraKit, shared dive computer engine (Buhlmann ZHL-16C + GF) and SwiftUI components for Open Remora and Open Merou
git clone https://git.schurger.org/remora-kit.git
Log | Files | Refs | README | LICENSE

commit 076704881a8ff22741a33446b629ff2e88e0592f
parent 405a33acbba98a36f22c12e90d51ab7976b490df
Author: Jean Schurger <jean@schurger.org>
Date:   Fri, 13 Nov 2026 23:56:57 -0500

Review 0.2: silent sensor underwater = depth held and flagged (never a false return to the surface), watchdog when the sensor goes quiet, stops always on the 3 m grid, above the stop = violation, safety stop can be redone, oscillating alarms logged once, Health samples bounded to the session; version 0.2

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYGcjJYQu2t1EUEKgbs

Diffstat:
MSources/RemoraDeco/AscentPlanner.swift | 12++++++++++++
MSources/RemoraDeco/DiveComputer.swift | 5++++-
MSources/RemoraDeco/DiveRecorder.swift | 9++++++++-
MTests/RemoraDecoTests/DecoTests.swift | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/Sources/RemoraDeco/AscentPlanner.swift b/Sources/RemoraDeco/AscentPlanner.swift @@ -117,6 +117,18 @@ public enum AscentPlanner { state.ceiling(gradientFactor: gfAt(d)) <= scale.pressure(atDepth: d) + 1e-9 } + // Plongeur entre deux paliers (ou au-dessus du sien) et qui ne peut pas monter au suivant : son palier + // est sur la grille, à sa profondeur ou plus bas, jamais à une profondeur quelconque. Révision 0.2 : + // avant, un plongeur remonté à 2,4 m se voyait proposer un « palier à 2 m ». + if depth > 0, !clear(t, at: nextStop(below: depth)) { + let step = settings.stopIncrement + var grid = max(settings.lastStopDepth, (depth / step - 1e-6).rounded(.up) * step) + if abs(grid - depth) > 1e-6 { + while !clear(t, at: grid) && grid < 60 { grid += step } + depth = grid + } + } + while depth > 0 { let next = nextStop(below: depth) let trial = ascend(t, from: depth, to: next) diff --git a/Sources/RemoraDeco/DiveComputer.swift b/Sources/RemoraDeco/DiveComputer.swift @@ -95,7 +95,8 @@ public struct DiveComputer: Sendable { let deco = configuration.deco guard maxDepth >= deco.safetyStopTriggerDepth else { return } if case .done = safetyStopState { return } - if case .missed = safetyStopState { return } + // Sauté, puis redescente : le palier redevient à faire. + if case .missed = safetyStopState, depth <= deco.safetyStopDepth + 2 { return } if plan?.inDecompression == true { safetyStopState = .pending; safetyStopTime = 0; return } let required = deco.safetyStopMinutes * 60 if depth >= 3, depth <= deco.safetyStopDepth + 1.5 { @@ -127,6 +128,8 @@ public struct DiveComputer: Sendable { case .normal: break } if ceiling > 0, depth < ceiling - 0.3 { warnings.insert(.ceilingViolated) } + // Au-dessus du palier demandé (les paliers sont par tranches de 3 m, plus profonds que le plafond continu). + if let stop = plan.stops.first, depth < stop.depth - 0.6 { warnings.insert(.ceilingViolated) } if ppO2 > configuration.ppO2Alarm { warnings.insert(.ppO2Critical) } else if ppO2 > configuration.ppO2Warning { warnings.insert(.ppO2High) } if depth >= configuration.depthLimit { warnings.insert(.depthLimit) } diff --git a/Sources/RemoraDeco/DiveRecorder.swift b/Sources/RemoraDeco/DiveRecorder.swift @@ -12,6 +12,9 @@ public struct DiveRecorder: Sendable { private var samples: [DiveSample] = [] private var events: [DiveEvent] = [] private var activeWarnings = Set<DiveComputer.Warning>() + private var lastLogged: [DiveComputer.Warning: Double] = [:] + /// Une même alarme qui oscille autour de son seuil n'est notée qu'une fois par période (s). + public var eventRepeatInterval: Double = 30 private var latest: DiveSample? /// Démarre une plongée. Les tissus viennent du carnet (plongée successive) s'il y en a une récente. @@ -32,7 +35,11 @@ public struct DiveRecorder: Sendable { if t0 == nil { t0 = time } let elapsed = time - (t0 ?? time) - for w in status.warnings.subtracting(activeWarnings) { events.append(DiveEvent(time: elapsed, warning: w)) } + for w in status.warnings.subtracting(activeWarnings) { + if let before = lastLogged[w], elapsed - before < eventRepeatInterval { continue } + lastLogged[w] = elapsed + events.append(DiveEvent(time: elapsed, warning: w)) + } activeWarnings = status.warnings let stop = status.plan.stops.first diff --git a/Tests/RemoraDecoTests/DecoTests.swift b/Tests/RemoraDecoTests/DecoTests.swift @@ -312,3 +312,57 @@ struct DiveScreenEngineTests { #expect(l.status.warnings.contains(.lowNoDecompression)) } } + +@Suite("Révision 0.2") +struct ReviewTests { + @Test func aboveRequiredStopIsAViolation() { + var config = DiveComputer.Configuration(); config.water = .salt + var c = DiveComputer(configuration: config, surfacePressure: scale.surfacePressure) + var t = 0.0, d = 0.0 + c.update(time: 0, pressure: scale.surfacePressure) + while d < 40 { d = min(40, d + 0.3); t += 1; c.update(time: t, pressure: scale.pressure(atDepth: d)) } + for _ in 0..<(25 * 60) { t += 1; c.update(time: t, pressure: scale.pressure(atDepth: d)) } + // Remontée continue à 9 m/min sans faire les paliers (les premiers s'effacent en route, pas le dernier). + var flagged = false + while d > 1 { + d -= 0.15; t += 1 + c.update(time: t, pressure: scale.pressure(atDepth: d)) + let status = c.status + if let stop = status.plan.stops.first, d < stop.depth - 0.6 { + #expect(status.warnings.contains(.ceilingViolated)) + flagged = true + } + } + #expect(flagged) + } + + @Test func missedSafetyStopCanBeRedone() { + var config = DiveComputer.Configuration(); config.water = .salt + var c = DiveComputer(configuration: config, surfacePressure: scale.surfacePressure) + var t = 0.0 + func at(_ depth: Double, _ seconds: Int) { for _ in 0..<seconds { t += 1; c.update(time: t, pressure: scale.pressure(atDepth: depth)) } } + c.update(time: 0, pressure: scale.surfacePressure) + at(15, 300); at(0.2, 5) + #expect(c.safetyStop == .missed) + at(12, 60) + #expect(c.safetyStop == .pending) + at(5, 181) + #expect(c.safetyStop == .done) + #expect(!c.status.warnings.contains(.missedSafetyStop)) + } + + @Test func oscillatingAlarmIsLoggedOncePerPeriod() { + var config = DiveComputer.Configuration(); config.water = .salt + var r = DiveRecorder(configuration: config, surfacePressure: scale.surfacePressure, + start: Date(timeIntervalSince1970: 1_800_000_000)) + var t = 0.0 + r.record(time: 0, pressure: scale.surfacePressure) + // Autour de 38 m : au-dessus puis au-dessous de la profondeur limite, toutes les 2 s pendant 40 s. + for i in 0..<20 { + t += 2 + r.record(time: t, pressure: scale.pressure(atDepth: i % 2 == 0 ? 38.2 : 37.8)) + } + let count = r.finish().events.filter { $0.warning == .depthLimit }.count + #expect(count == 2) // à t=2 s, puis une fois passé 30 s + } +}