From db491f1e2c830631edc8b1e87898ccaf61cc18c2 Mon Sep 17 00:00:00 2001 From: Jiri Pokorny Date: Wed, 11 Dec 2024 21:01:20 +0100 Subject: [PATCH] Removed a,b coefficients from loadedTissues --- .../planner/src/app/shared/dtoSerialization.ts | 8 ++------ .../src/app/shared/serialization.model.ts | 2 -- projects/scuba-physics/src/lib/Tissues.spec.ts | 15 +++++++++++---- projects/scuba-physics/src/lib/Tissues.ts | 18 +----------------- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/projects/planner/src/app/shared/dtoSerialization.ts b/projects/planner/src/app/shared/dtoSerialization.ts index f4e64c1e..be30766f 100644 --- a/projects/planner/src/app/shared/dtoSerialization.ts +++ b/projects/planner/src/app/shared/dtoSerialization.ts @@ -121,18 +121,14 @@ export class DtoSerialization { public static toTissues(tissues: LoadedTissueDto[]): LoadedTissue[] { return _(tissues).map(t => ({ pN2: t.pN2, - pHe: t.pHe, - a: t.a, - b: t.b + pHe: t.pHe })).value(); } public static fromTissues(tissues: LoadedTissue[]): LoadedTissueDto[] { return _(tissues).map(t => ({ pN2: t.pN2, - pHe: t.pHe, - a: t.a, - b: t.b + pHe: t.pHe })).value(); } diff --git a/projects/planner/src/app/shared/serialization.model.ts b/projects/planner/src/app/shared/serialization.model.ts index 675e9d3c..d5c1fca5 100644 --- a/projects/planner/src/app/shared/serialization.model.ts +++ b/projects/planner/src/app/shared/serialization.model.ts @@ -110,8 +110,6 @@ export interface CalculatedProfileDto { export interface LoadedTissueDto { pHe: number; pN2: number; - a: number; - b: number; } export interface ConsumptionRequestDto { diff --git a/projects/scuba-physics/src/lib/Tissues.spec.ts b/projects/scuba-physics/src/lib/Tissues.spec.ts index b3924720..361a0967 100644 --- a/projects/scuba-physics/src/lib/Tissues.spec.ts +++ b/projects/scuba-physics/src/lib/Tissues.spec.ts @@ -1,3 +1,4 @@ +import _ from 'lodash'; import { LoadedTissue, LoadSegment, Tissue, Tissues, TissuesValidator } from './Tissues'; import { Compartments } from './Compartments'; import { Time } from './Time'; @@ -8,14 +9,20 @@ describe('Tissues', () => { describe('Creation', () => { it('Tissues Create generates valid tissues', () => { - const wrongCount: LoadedTissue[] = Tissues.create(1).finalState(); - const valid = TissuesValidator.valid(wrongCount); + const loadedTissues: LoadedTissue[] = Tissues.create(1).finalState(); + const valid = TissuesValidator.valid(loadedTissues); expect(valid).toBeTruthy(); }); + it('Tissues Create sets a,b coefficients', () => { + const created: Tissues = Tissues.create(1); + const allLoaded = _(created.compartments).every(t => t.a > 0 && t.b > 0); + expect(allLoaded).toBeTruthy(); + }); + it('Copy creates new valid deep copy', () => { const source = createTissue(); - const copy = source.copy(); + const copy = createTissue().copy(); expect(copy).toEqual(source); }); }); @@ -34,7 +41,7 @@ describe('Tissues', () => { it('One invalid item', () => { const tissues: LoadedTissue[] = Tissues.create(1).finalState(); - tissues[0] = { a: 0, b: 0, pHe: 0, pN2: -1 }; + tissues[0] = { pHe: 0, pN2: -1 }; const valid = TissuesValidator.valid(tissues); expect(valid).toBeFalsy(); }); diff --git a/projects/scuba-physics/src/lib/Tissues.ts b/projects/scuba-physics/src/lib/Tissues.ts index 0178fc0a..63edffe2 100644 --- a/projects/scuba-physics/src/lib/Tissues.ts +++ b/projects/scuba-physics/src/lib/Tissues.ts @@ -83,8 +83,6 @@ export class Tissue extends Compartment implements LoadedTissue { const copy = new Tissue(compartment, 1); // irrelevant pressure wouldn't be used copy._pN2 = loaded.pN2; copy._pHe = loaded.pHe; - copy._a = loaded.a; - copy._b = loaded.b; copy.updateTotal(); copy.updateCoefficients(); return copy; @@ -347,26 +345,12 @@ export interface LoadedTissue { * partial pressure of helium in bars */ pHe: number; - - // TODO remove a and b coefficients, since they are calculated from pN2 and pHe and compartment coefficients. - /** - * Buhlmann m-value constant a - */ - a: number; - - /** - * Buhlmann m-value constant b - */ - b: number; } export class TissuesValidator { public static validTissue(item: LoadedTissue): boolean { return item.pN2 > 0 && - item.pHe >= 0 && - // a and b may be 0 in case no loading of the tissues was performed yet. - item.a >= 0 && - item.b >= 0; + item.pHe >= 0; } public static validCount(current?: LoadedTissue[]): boolean {