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 635e7affbd67c846df1669ce4fb6bd0c0dd9d432
parent e5eace7d2f1e8b627410765f2c2da55682d1fa47
Author: Jean Schurger <jean@schurger.org>
Date:   Mon, 23 Nov 2026 11:10:19 -0500

Shearwater comparison on a second data set: dives sorted by what they can tell (open circuit GF, other model, gas switch, rebreather), tissue snapshots checked, rebreather dives replayed with the logged ppO2 (test-only Gas.loopPPO2); a diver exactly on a stop is given the grid depth, not 2.9999999999999996 m shown as "2 m"

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

Diffstat:
MSources/RemoraDeco/AscentPlanner.swift | 4+++-
MSources/RemoraDeco/Physics.swift | 9++++++++-
MSources/RemoraUI/DiveReadouts.swift | 2+-
MTests/RemoraDecoTests/DecoTests.swift | 14++++++++++++++
MTests/RemoraDecoTests/ShearwaterComparisonTests.swift | 285++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
5 files changed, 245 insertions(+), 69 deletions(-)

diff --git a/Sources/RemoraDeco/AscentPlanner.swift b/Sources/RemoraDeco/AscentPlanner.swift @@ -126,8 +126,10 @@ public enum AscentPlanner { 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 } + // Also for a diver right on the stop: a depth of 2.9999999999999996 m (pressure converted + // back to a depth) must not be reported, the display would truncate it to "2 m". + depth = grid } while depth > 0 { diff --git a/Sources/RemoraDeco/Physics.swift b/Sources/RemoraDeco/Physics.swift @@ -69,8 +69,15 @@ public struct Gas: Sendable, Hashable, Codable, CustomStringConvertible { scale.depth(atPressure: ppO2Limit / o2) } + /// Rebreather replays only (comparison with logged closed-circuit dives, see ShearwaterComparisonTests); + /// no app offers it. The loop holds this ppO2 (bar) and `o2` describes the diluent, whose inert part + /// is all nitrogen. + var loopPPO2: Double? + /// Inspired partial pressure of nitrogen (in the alveoli). func inspiredN2(atPressure pressure: Double) -> Double { - max(0, pressure - waterVapourPressure) * n2 + let dry = max(0, pressure - waterVapourPressure) + guard let loopPPO2 else { return dry * n2 } + return max(0, dry - loopPPO2) } } diff --git a/Sources/RemoraUI/DiveReadouts.swift b/Sources/RemoraUI/DiveReadouts.swift @@ -35,7 +35,7 @@ public struct DiveInstruction: View { } if let stop = s.plan.stops.first { HStack(alignment: .firstTextBaseline, spacing: 4 * scale) { - Text("STOP \(Int(stop.depth)) m", bundle: .module) + Text("STOP \(Int(stop.depth.rounded())) m", bundle: .module) .font(rounded(16, .bold)) Text(Format.clock(Double(stop.seconds ?? stop.minutes * 60))) .font(rounded(22, .bold)) diff --git a/Tests/RemoraDecoTests/DecoTests.swift b/Tests/RemoraDecoTests/DecoTests.swift @@ -156,6 +156,20 @@ struct DecoPlanTests { #expect(t.ceiling(gradientFactor: settings.gradientFactors.high) <= scale.surfacePressure + 1e-6) } + /// A diver right on a stop, whose depth comes back from the pressure as 2.9999999999999996 m (fresh + /// water, low surface pressure): the stop is the 3 m one, not a depth the display truncates to "2 m". + @Test func stopOfADiverOnTheGridIsOnTheGrid() throws { + let lake = DepthScale(surfacePressure: 0.976, water: .fresh) + var t = TissueState.saturated(surfacePressure: lake.surfacePressure) + t.stay(atPressure: lake.pressure(atDepth: 40), gas: .air, minutes: 25) + for depth in [3.0, 6.0, 9.0] { + let pressure = lake.pressure(atDepth: depth) + let p = AscentPlanner.plan(tissues: t, pressure: pressure, gas: .air, scale: lake, settings: DecoSettings()) + let first = try #require(p.stops.first) + #expect(first.depth.truncatingRemainder(dividingBy: 3) == 0 && first.depth >= depth) + } + } + @Test func moreConservativeMeansLongerDeco() { var pure = DecoSettings(); pure.gradientFactors = .pureBuhlmann let strict = plan(minutes: 25, depth: 40) diff --git a/Tests/RemoraDecoTests/ShearwaterComparisonTests.swift b/Tests/RemoraDecoTests/ShearwaterComparisonTests.swift @@ -3,17 +3,25 @@ import Foundation import Testing @testable import RemoraDeco -/// Compares the engine with a certified dive computer: replays Shearwater dives (same algorithm, same GF) -/// and checks the no-decompression time and the stops against what the computer displayed. -/// Personal data kept out of the repository: `tools/shearwater_decode.py` produces the JSON, path in SHEARWATER_JSON. +/// Compares the engine with a certified dive computer: replays Shearwater dives and checks the tissue +/// loading, the no-decompression time and the stops against what the computer logged and displayed. +/// Personal data kept out of the repository: `tools/shearwater_decode.py` (Open Rémora repository) +/// produces the JSON, path in SHEARWATER_JSON. struct ShearwaterDive: Decodable { struct Sample: Decodable { - let depth: Double - let stop_depth: Int + let depth: Double // m + let stop_depth: Int // m let tts: Int let o2: Int + let he: Int? + let ppo2: Double? // bar, as measured in the loop on a rebreather let ndl_or_stop: Int - let ceiling: Int + let status: Int? + } + /// The 16 nitrogen pressures the computer logs about every 5 minutes; `index` = samples logged before. + struct Tissues: Decodable { + let index: Int + let n2: [Double] } let number: String? let site: String? @@ -22,13 +30,56 @@ struct ShearwaterDive: Decodable { let gf_high: Int let surface_mbar: Int let sample_ms: Int + let model: String? // "GF", "VPM-B"… + let mode: String? // "oc-rec", "oc-tec", "cc"… + let density: Int? // kg/m³ let samples: [Sample] + let tissues: [Tissues]? + + enum Kind: String, CaseIterable { + /// Open circuit, one nitrox mix, gradient factors: the computer runs the algorithm of the engine, + /// its display is the reference. + case reference = "open circuit, GF" + /// Open circuit, another decompression model (VPM-B): same tissues, different limits. + case otherModel = "open circuit, other model" + /// Gas switch or helium: the engine knows one nitrox mix only. + case multiGas = "gas switch or helium" + /// Rebreather, as the watch would go through it: it knows open circuit only (air = the diluent). + case closedCircuit = "closed circuit, as the watch sees it" + /// Rebreather with the gradient factors of the computer and the ppO2 it logged in the loop, on the + /// planner alone (`Gas.loopPPO2`, replays only): what the algorithm gives on these dives. + case closedCircuitModelled = "closed circuit, logged ppO2" + } + + var hasHelium: Bool { samples.contains { ($0.he ?? 0) > 0 } } + + var kind: Kind { + let openCircuit = (mode ?? "oc").hasPrefix("oc") && samples.allSatisfy { ($0.status ?? 0x10) & 0x10 != 0 } + if !openCircuit { return .closedCircuit } + if Set(samples.map(\.o2)).count > 1 || hasHelium { return .multiGas } + return (model ?? "GF") == "GF" ? .reference : .otherModel + } } @Suite("Shearwater comparison") struct ShearwaterComparisonTests { static let path = ProcessInfo.processInfo.environment["SHEARWATER_JSON"] + struct Totals { + var dives = 0 + var ndl: [Double] = [] + var shortNDL: [Double] = [] // when the Shearwater shows 30 min or less: where it matters + var zeroEarly = 0, liberal = 0 + var tissueErrors: [Double] = [] + var decoBoth = 0, decoSameDepth = 0, decoOnlyTheirs = 0, decoOnlyOurs = 0 + var stopMinutes: [Double] = [] + var enterDiffs: [Double] = [] + var decoDivesTheirs = 0, decoDivesOurs = 0 + } + + static func mean(_ v: [Double]) -> Double { v.isEmpty ? 0 : v.reduce(0, +) / Double(v.count) } + static func rms(_ v: [Double]) -> Double { v.isEmpty ? 0 : (v.map { $0 * $0 }.reduce(0, +) / Double(v.count)).squareRoot() } + @Test(.enabled(if: path != nil)) func replayAgainstShearwater() throws { let dives = try JSONDecoder().decode([ShearwaterDive].self, @@ -39,102 +90,204 @@ struct ShearwaterComparisonTests { dates.dateFormat = "yyyy-MM-dd HH:mm:ss" var previous: (end: Date, tissues: TissueState)? - var allNDL: [Double] = [] - var zeroEarly = 0, liberal = 0 - var shortNDL: [Double] = [] // when the Shearwater shows 30 min or less: where it matters - for dive in dives { - let start = try #require(dates.date(from: dive.date)) + var totals: [ShearwaterDive.Kind: Totals] = [:] + for dive in dives where !dive.samples.isEmpty { + let start = try #require(dates.date(from: dive.date)) + // A rebreather dive is replayed twice: as the watch would see it, then with the logged ppO2. + var kinds = [dive.kind] + if dive.kind == .closedCircuit, !dive.hasHelium, (dive.model ?? "GF") == "GF", + dive.samples.allSatisfy({ $0.ppo2 != nil }) { kinds.append(.closedCircuitModelled) } + for kind in kinds { let surface = Double(dive.surface_mbar) / 1000 let step = Double(dive.sample_ms) / 1000 + // The computer derives its depth from the pressure with its own water density setting. + let density = Double(dive.density ?? 1020) + let barPerMetre = density * 9.80665 / 100_000 + // Reference dives: the settings of the computer. The others are replayed the way the watch + // would have gone through them: bottom gas (air on a rebreather, i.e. the diluent) and the + // conservative default gradient factors. var config = DiveComputer.Configuration() - config.gas = Gas(o2: Double(dive.samples[0].o2) / 100) - config.water = .en13319 - config.deco.gradientFactors = GradientFactors(low: Double(dive.gf_low) / 100, high: Double(dive.gf_high) / 100) + config.gas = kind == .closedCircuit ? .air : Gas(o2: Double(dive.samples[0].o2) / 100) + config.water = density < 1010 ? .fresh : density > 1022 ? .salt : .en13319 + config.deco.gradientFactors = kind == .reference || kind == .closedCircuitModelled + ? GradientFactors(low: Double(dive.gf_low) / 100, high: Double(dive.gf_high) / 100) + : .conservative config.deco.ascentRate = 10 + // A computer set for a last stop at 6 m (usual on a rebreather) never shows a shallower one. + if kind == .closedCircuitModelled, let last = dive.samples.map(\.stop_depth).filter({ $0 > 0 }).min(), last >= 6 { + config.deco.lastStopDepth = 6 + } + // Trial of another off-gassing credit for the no-stop time (see the result at the end). + if let rate = ProcessInfo.processInfo.environment["SHEARWATER_NOSTOP_RATE"].flatMap(Double.init) { + config.deco.noStopAscentRate = rate + } + // Initial tissues: the ones the computer logged at the start of the dive when it did (they + // carry every earlier dive, logged here or not), otherwise ours from the previous dive. var tissues: TissueState? - var interval: Double? - if let p = previous, start.timeIntervalSince(p.end) < 48 * 3600 { - interval = start.timeIntervalSince(p.end) / 60 - tissues = DiveComputer.surfaceInterval(p.tissues, minutes: interval!, surfacePressure: surface) + var origin = "saturated" + if let first = dive.tissues?.first, first.index == 0, first.n2.count == ZHL16C.nitrogen.count { + tissues = TissueState(nitrogen: first.n2, compartments: ZHL16C.nitrogen) + origin = "logged tissues" + } else if kind != .closedCircuitModelled, let p = previous, start.timeIntervalSince(p.end) < 48 * 3600, start > p.end { + let interval = start.timeIntervalSince(p.end) / 60 + tissues = DiveComputer.surfaceInterval(p.tissues, minutes: interval, surfacePressure: surface) + origin = "interval \(Int(interval)) min" } var computer = DiveComputer(configuration: config, surfacePressure: surface, tissues: tissues) computer.update(time: 0, pressure: surface) - var ndlDiffs: [Double] = [] + var t = Totals() + t.dives = 1 + var snapshots = (dive.tissues ?? []).filter { $0.index > 0 }[...] var stopRows: [String] = [] - var firstDeco: String? - var decoStats = (both: 0, sameDepth: 0, minuteDiffs: [Double](), ttsDiffs: [Double](), onlyTheirs: 0, onlyOurs: 0) + var decoTTS: [Double] = [] var enter: (theirs: Double?, ours: Double?) = (nil, nil) var leave: (theirs: Double?, ours: Double?) = (nil, nil) + var longest = (stop: 0, tts: 0.0) + // Logged ppO2: the planner alone, with the mix of each sample (open circuit when bailed out). + var loop = (tissues: computer.tissues, pressure: surface, anchor: Double?.none) for (i, s) in dive.samples.enumerated() { - computer.update(time: Double(i + 1) * step, pressure: computer.scale.pressure(atDepth: s.depth)) - let plan = computer.status.plan + let pressure = surface + s.depth * barPerMetre + let plan: AscentPlan + let nitrogen: [Double] + if kind == .closedCircuitModelled { + var gas = Gas(o2: Double(s.o2) / 100) + if (s.status ?? 0) & 0x10 == 0 { gas.loopPPO2 = s.ppo2 } + loop.tissues.change(from: loop.pressure, to: pressure, gas: gas, minutes: step / 60) + loop.pressure = pressure + plan = AscentPlanner.plan(tissues: loop.tissues, pressure: pressure, gas: gas, scale: computer.scale, + settings: config.deco, anchorDepth: loop.anchor) + if let anchor = plan.gradientAnchorDepth { loop.anchor = max(loop.anchor ?? 0, anchor) } + nitrogen = loop.tissues.nitrogen + } else { + computer.update(time: Double(i + 1) * step, pressure: pressure) + plan = computer.status.plan + nitrogen = computer.tissues.nitrogen + } + let minute = Double(i + 1) * step / 60 + + // Never an absurd answer, whatever the dive (deeper than the watch goes, hours long…). + #expect(plan.timeToSurface.isFinite && plan.timeToSurface >= 0) + #expect(plan.stops.allSatisfy { $0.minutes > 0 && $0.minutes < 999 && $0.depth >= 3 + && $0.depth.truncatingRemainder(dividingBy: 3) == 0 }) + #expect(nitrogen.allSatisfy { $0.isFinite && $0 > 0 }) + longest.stop = max(longest.stop, plan.stops.map(\.minutes).reduce(0, +)) + longest.tts = max(longest.tts, plan.timeToSurface) + + // Tissue loading against the tissues the computer logged (same gas only). + if let snapshot = snapshots.first, snapshot.index == i + 1 { + snapshots = snapshots.dropFirst() + if kind == .reference || kind == .otherModel || kind == .closedCircuitModelled { + t.tissueErrors += zip(nitrogen, snapshot.n2).map { $0 - $1 } + } + } + if s.stop_depth == 0, s.ndl_or_stop > 0, s.ndl_or_stop < 99, s.depth > 9, !plan.inDecompression { let diff = floor(plan.noDecompressionLimit ?? 99) - Double(s.ndl_or_stop) - ndlDiffs.append(diff) - if s.ndl_or_stop <= 30 { shortNDL.append(diff) } - if s.ndl_or_stop >= 5, (plan.noDecompressionLimit ?? 99) < 1 { zeroEarly += 1 } - if s.ndl_or_stop <= 30, diff >= 5 { liberal += 1 } - if s.ndl_or_stop <= 30, abs(diff) >= 5, i % 6 == 0 { - print(" diff t=\(Int(Double(i + 1) * step / 60))' \(s.depth) m: Shearwater \(s.ndl_or_stop) min, Rémora \(Int(plan.noDecompressionLimit ?? 99)) min") + t.ndl.append(diff) + if s.ndl_or_stop <= 30 { t.shortNDL.append(diff) } + if s.ndl_or_stop >= 5, (plan.noDecompressionLimit ?? 99) < 1 { t.zeroEarly += 1 } + if s.ndl_or_stop <= 30, diff >= 5 { t.liberal += 1 } + if kind == .reference, s.ndl_or_stop <= 30, abs(diff) >= 5, i % 6 == 0 { + print(" diff t=\(Int(minute))' \(s.depth) m: Shearwater \(s.ndl_or_stop) min, Rémora \(Int(plan.noDecompressionLimit ?? 99)) min") } } - let minute = Double(i + 1) * step / 60 if s.stop_depth > 0 { if enter.theirs == nil { enter.theirs = minute }; leave.theirs = minute } if plan.inDecompression { if enter.ours == nil { enter.ours = minute }; leave.ours = minute } if s.stop_depth > 0, let stop = plan.stops.first { - decoStats.both += 1 - if Int(stop.depth) == s.stop_depth { - decoStats.sameDepth += 1 - decoStats.minuteDiffs.append(Double(stop.minutes - s.ndl_or_stop)) + t.decoBoth += 1 + if Int(stop.depth.rounded()) == s.stop_depth { + t.decoSameDepth += 1 + t.stopMinutes.append(Double(stop.minutes - s.ndl_or_stop)) } - decoStats.ttsDiffs.append(plan.timeToSurface.rounded(.up) - Double(s.tts)) - } else if s.stop_depth > 0 { decoStats.onlyTheirs += 1 } else if plan.inDecompression { decoStats.onlyOurs += 1 } - if s.stop_depth > 0 || plan.inDecompression { + decoTTS.append(plan.timeToSurface.rounded(.up) - Double(s.tts)) + } else if s.stop_depth > 0 { t.decoOnlyTheirs += 1 } else if plan.inDecompression { t.decoOnlyOurs += 1 } + if s.stop_depth > 0 || plan.inDecompression, i % 12 == 0 { let ours = plan.stops.first.map { "\(Int($0.depth)) m \($0.minutes) min, surface \(Int(plan.timeToSurface.rounded(.up)))" } ?? "none" let theirs = s.stop_depth > 0 ? "\(s.stop_depth) m \(s.ndl_or_stop) min, surface \(s.tts)" : "none" - if firstDeco == nil { firstDeco = "t=\(Int(Double(i + 1) * step / 60)) min" } - if i % 12 == 0 { stopRows.append(" t=\(Int(Double(i + 1) * step / 60))' \(s.depth) m | Shearwater \(theirs) | Rémora \(ours)") } + stopRows.append(" t=\(Int(minute))' \(s.depth) m | Shearwater \(theirs) | Rémora \(ours)") } } - allNDL.append(contentsOf: ndlDiffs) - let mean = ndlDiffs.isEmpty ? 0 : ndlDiffs.reduce(0, +) / Double(ndlDiffs.count) - let worst = ndlDiffs.map { abs($0) }.max() ?? 0 - print("Dive \(dive.number ?? "?") \(dive.site ?? "") GF \(dive.gf_low)/\(dive.gf_high) O2 \(dive.samples[0].o2)%" - + (interval.map { " (interval \(Int($0)) min)" } ?? "") - + String(format: ": no-deco, %d samples, mean diff %+.1f min, worst %.0f min", ndlDiffs.count, mean, worst)) + + let deepest = dive.samples.map(\.depth).max() ?? 0 + print("Dive \(dive.number ?? "?") \(dive.date.prefix(10)) \(dive.site ?? "") [\(kind.rawValue)] " + + "\(dive.model ?? "GF") \(dive.gf_low)/\(dive.gf_high) -> \(config.deco.gradientFactors), \(config.gas), " + + String(format: "%.1f m, %.0f min, %@: no-deco %d samples, mean diff %+.1f min (%+.2f on the %d where the Shearwater shows 30 min or less), worst %+.0f min; tissues RMS %.4f bar", + deepest, Double(dive.samples.count) * step / 60, origin, t.ndl.count, Self.mean(t.ndl), + Self.mean(t.shortNDL), t.shortNDL.count, + t.ndl.max(by: { abs($0) < abs($1) }) ?? 0, Self.rms(t.tissueErrors))) if enter.theirs != nil || enter.ours != nil { func f(_ v: Double?) -> String { v.map { String(format: "%.1f", $0) } ?? "never" } - let m = decoStats.minuteDiffs - let t = decoStats.ttsDiffs - print(" DECO: entered Shearwater \(f(enter.theirs)) min, Rémora \(f(enter.ours)) min; left \(f(leave.theirs)) / \(f(leave.ours)) min") - print(String(format: " DECO: %d samples in common, same depth %d, stop time %+.2f min on average (worst %+.0f), surface %+.1f min; Shearwater only %d samples, Rémora only %d samples", - decoStats.both, decoStats.sameDepth, m.isEmpty ? 0 : m.reduce(0, +) / Double(m.count), - m.max(by: { abs($0) < abs($1) }) ?? 0, t.isEmpty ? 0 : t.reduce(0, +) / Double(t.count), - decoStats.onlyTheirs, decoStats.onlyOurs)) + print(" DECO: entered Shearwater \(f(enter.theirs)) min, Rémora \(f(enter.ours)) min; left \(f(leave.theirs)) / \(f(leave.ours)) min; " + + String(format: "%d samples in common, same depth %d, stop time %+.2f min on average (worst %+.0f), surface %+.1f min; Shearwater only %d samples, Rémora only %d; Rémora's longest: stops %d min, surface %.0f min", + t.decoBoth, t.decoSameDepth, Self.mean(t.stopMinutes), + t.stopMinutes.max(by: { abs($0) < abs($1) }) ?? 0, Self.mean(decoTTS), + t.decoOnlyTheirs, t.decoOnlyOurs, longest.stop, longest.tts)) + if ProcessInfo.processInfo.environment["SHEARWATER_ROWS"] != nil { stopRows.forEach { print($0) } } } + if enter.theirs != nil { t.decoDivesTheirs = 1 } + if enter.ours != nil { t.decoDivesOurs = 1 } + if let a = enter.theirs, let b = enter.ours { t.enterDiffs.append(b - a) } - let duration = Double(dive.samples.count) * step - previous = (start.addingTimeInterval(duration), computer.tissues) + var sum = totals[kind] ?? Totals() + sum.dives += 1 + sum.ndl += t.ndl; sum.shortNDL += t.shortNDL; sum.zeroEarly += t.zeroEarly; sum.liberal += t.liberal + sum.tissueErrors += t.tissueErrors + sum.decoBoth += t.decoBoth; sum.decoSameDepth += t.decoSameDepth + sum.decoOnlyTheirs += t.decoOnlyTheirs; sum.decoOnlyOurs += t.decoOnlyOurs + sum.stopMinutes += t.stopMinutes; sum.enterDiffs += t.enterDiffs + sum.decoDivesTheirs += t.decoDivesTheirs; sum.decoDivesOurs += t.decoDivesOurs + totals[kind] = sum + + if kind != .closedCircuitModelled { + previous = (start.addingTimeInterval(Double(dive.samples.count) * step), computer.tissues) + } + } + } + + for kind in ShearwaterDive.Kind.allCases { + guard let t = totals[kind] else { continue } + let short = t.shortNDL + let within2 = Double(short.filter { abs($0) <= 2 }.count) / Double(max(1, short.count)) * 100 + print("TOTAL [\(kind.rawValue)] \(t.dives) dives") + print(String(format: " no-deco: %d samples, mean diff %+.2f min, mean absolute %.2f min", t.ndl.count, Self.mean(t.ndl), Self.mean(t.ndl.map { abs($0) }))) + print(String(format: " no-deco, Shearwater ≤ 30 min: %d samples, mean diff %+.2f min, mean absolute %.2f min, worst %+.0f min, %.0f%% within 2 min, %d at +5 min or more, %d at zero while the Shearwater shows 5 min or more", + short.count, Self.mean(short), Self.mean(short.map { abs($0) }), + short.max(by: { abs($0) < abs($1) }) ?? 0, within2, t.liberal, t.zeroEarly)) + print(String(format: " deco: %d dives for the Shearwater, %d for Rémora; entered %+.1f min from the Shearwater on average; %d samples in common, same stop depth %d, stop time %+.2f min on average (worst %+.0f); Shearwater only %d samples, Rémora only %d", + t.decoDivesTheirs, t.decoDivesOurs, Self.mean(t.enterDiffs), t.decoBoth, t.decoSameDepth, + Self.mean(t.stopMinutes), t.stopMinutes.max(by: { abs($0) < abs($1) }) ?? 0, t.decoOnlyTheirs, t.decoOnlyOurs)) + print(String(format: " tissues: %d snapshots, mean %+.4f bar, RMS %.4f bar, worst %.3f bar", + t.tissueErrors.count / 16, Self.mean(t.tissueErrors), Self.rms(t.tissueErrors), + t.tissueErrors.map { abs($0) }.max() ?? 0)) } - let mean = allNDL.reduce(0, +) / Double(max(1, allNDL.count)) - let meanAbs = allNDL.map { abs($0) }.reduce(0, +) / Double(max(1, allNDL.count)) - print(String(format: "TOTAL no-deco: %d samples, mean diff %+.2f min, mean absolute diff %.2f min", allNDL.count, mean, meanAbs)) - let shortMean = shortNDL.reduce(0, +) / Double(max(1, shortNDL.count)) - let shortAbs = shortNDL.map { abs($0) }.reduce(0, +) / Double(max(1, shortNDL.count)) - let within2 = Double(shortNDL.filter { abs($0) <= 2 }.count) / Double(max(1, shortNDL.count)) * 100 - print(String(format: "SHORT (Shearwater ≤ 30 min): %d samples, mean diff %+.2f min, mean absolute %.2f min, worst %.0f min, %.0f%% within 2 min", - shortNDL.count, shortMean, shortAbs, shortNDL.map { abs($0) }.max() ?? 0, within2)) + + // Tissue loading does not depend on the decompression model of the computer. + let tissueErrors = (totals[.reference]?.tissueErrors ?? []) + (totals[.otherModel]?.tissueErrors ?? []) + #expect(Self.rms(tissueErrors) < 0.02) + // Result of 2026-11-13 (10 dives from a Petrel 3): stops identical to within one minute. // No-decompression time, when the Shearwater shows 30 min or less, depending on the ascent off-gassing credit: // no credit : -1.8 min on average, 77% within 2 min, 44 samples at zero too early; // credit at 30 m/min : -0.3 min, 88% within 2 min, 7 samples at zero too early ← chosen (noStopAscentRate); // credit at 18 m/min : +0.6 min (less conservative than the Shearwater): rejected. - #expect(meanAbs < 3) - #expect(shortAbs < 2) - #expect(shortMean < 0, "the engine must stay on the conservative side of the Shearwater") - #expect(zeroEarly < 15) + // + // Result of 2026-11-23 (second diver, 127 dives, 2018 to 2026, Perdix AI then Petrel 2 on a rebreather): + // tissues, open circuit (49 dives, 567 snapshots) : RMS 0.0065 bar; + // tissues, closed circuit with the logged ppO2 (697) : RMS 0.0126 bar (ppO2 logged to 0.01 bar); + // stops, closed circuit, GF 30/70 and 40/65, last stop 6 m : same depth on 627 samples of 649, stop time + // -0.15 min on average, never more than 1 min apart (6 dives); no-stop time -1.1 min; + // stops, open circuit GF 30/70 (1 dive of 2018) : same depth on 184 of 186, -0.35 min; + // no-stop time, open circuit GF (4 dives of 2018, feet, tissues at the start unknown): +0.14 min on + // average, 93% within 2 min. The expectation below fails on that set by this much; with the credit + // at 60 m/min it gives -0.54 min there and -1.15 min on the 2026-11-13 set. + if let t = totals[.reference], !t.ndl.isEmpty { + #expect(Self.mean(t.ndl.map { abs($0) }) < 3) + #expect(Self.mean(t.shortNDL.map { abs($0) }) < 2) + #expect(Self.mean(t.shortNDL) < 0, "the engine must stay on the conservative side of the Shearwater") + #expect(t.zeroEarly < 15) + } } }