Skip to content

Commit

Permalink
Removed a,b coefficients from loadedTissues
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Dec 11, 2024
1 parent 5ef84c7 commit db491f1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
8 changes: 2 additions & 6 deletions projects/planner/src/app/shared/dtoSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 0 additions & 2 deletions projects/planner/src/app/shared/serialization.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ export interface CalculatedProfileDto {
export interface LoadedTissueDto {
pHe: number;
pN2: number;
a: number;
b: number;
}

export interface ConsumptionRequestDto {
Expand Down
15 changes: 11 additions & 4 deletions projects/scuba-physics/src/lib/Tissues.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import { LoadedTissue, LoadSegment, Tissue, Tissues, TissuesValidator } from './Tissues';
import { Compartments } from './Compartments';
import { Time } from './Time';
Expand All @@ -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);
});
});
Expand All @@ -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();
});
Expand Down
18 changes: 1 addition & 17 deletions projects/scuba-physics/src/lib/Tissues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit db491f1

Please sign in to comment.