diff --git a/projects/planner/src/app/shared/gas.properties.spec.ts b/projects/planner/src/app/shared/gas.properties.spec.ts index 1e5a3b49..4f8a3aff 100644 --- a/projects/planner/src/app/shared/gas.properties.spec.ts +++ b/projects/planner/src/app/shared/gas.properties.spec.ts @@ -1,5 +1,5 @@ import { UnitConversion } from './UnitConversion'; -import { BoundGasProperties, GasProperties } from './gas.properties'; +import { BoundGasProperties } from './gas.properties'; describe('Gas properties bound', () => { const units: UnitConversion = new UnitConversion(); @@ -35,93 +35,3 @@ describe('Gas properties bound', () => { }); }); }); - -describe('Gas properties calculator', () => { - let sut: GasProperties; - - beforeEach(() => { - sut = new GasProperties(); - sut.depth = 30; - }); - - describe('Air at 30 m', () => { - beforeEach(() => { - sut.tank.o2 = 21; - }); - - it('MND is 30 m', () => { - expect(sut.mnd).toBeCloseTo(30, 3); - }); - - it('END is 30 m', () => { - expect(sut.end).toBeCloseTo(30, 3); - }); - - it('Minimum depth is 0 m', () => { - expect(sut.minDepth).toBeCloseTo(0, 3); - }); - - it('Maximum depth (MOD) is 57 m', () => { - expect(sut.maxDepth).toBeCloseTo(56.986, 3); - }); - - it('Total partial pressure is depth (4 b)', () => { - expect(sut.totalPp).toBeCloseTo(4, 3); - }); - - it('ppO2 is 0.836', () => { - expect(sut.ppO2).toBeCloseTo(0.836, 3); - }); - - it('ppHe is 0', () => { - expect(sut.ppHe).toBeCloseTo(0, 3); - }); - - it('ppN2 is 3.164', () => { - expect(sut.ppN2).toBeCloseTo(3.164, 3); - }); - - it('Density is 5.15 g/l', () => { - expect(sut.density).toBeCloseTo(5.151972, 6); - }); - }); - - describe('Trimix 10/70 at 30 m', () => { - beforeEach(() => { - sut.tank.o2 = 10; - sut.tank.he = 70; - }); - - it('MND is 123.3 m', () => { - expect(sut.mnd).toBeCloseTo(123.333, 3); - }); - - it('END is 2 m', () => { - expect(sut.end).toBeCloseTo(2, 3); - }); - - it('Minimum depth is 8 m', () => { - expect(sut.minDepth).toBeCloseTo(8, 3); - }); - - it('Maximum depth (MOD) is 130 m', () => { - expect(sut.maxDepth).toBeCloseTo(130, 3); - }); - - it('ppO2 is 0.4', () => { - expect(sut.ppO2).toBeCloseTo(0.4, 3); - }); - - it('ppHe is 2.8', () => { - expect(sut.ppHe).toBeCloseTo(2.8, 3); - }); - - it('ppN2 is 0.8', () => { - expect(sut.ppN2).toBeCloseTo(0.8, 3); - }); - - it('Density is 2 g/l', () => { - expect(sut.density).toBeCloseTo(2.0732, 6); - }); - }); -}); diff --git a/projects/planner/src/app/shared/gas.properties.ts b/projects/planner/src/app/shared/gas.properties.ts index ac836c73..a59c0f03 100644 --- a/projects/planner/src/app/shared/gas.properties.ts +++ b/projects/planner/src/app/shared/gas.properties.ts @@ -1,9 +1,5 @@ import { - DensityAtDepth, - DepthConverter, - Gas, - GasMixtures, - Tank + GasProperties } from 'scuba-physics'; import { TankBound } from './models'; import { UnitConversion } from './UnitConversion'; @@ -69,71 +65,3 @@ export class BoundGasProperties { this.calc.depth = newValue; } } - - -export class GasProperties { - /** in meters */ - public depth = 0; - private readonly _tank = Tank.createDefault(); - private readonly depthConverter = DepthConverter.simple(); - private readonly densityCalc = new DensityAtDepth(this.depthConverter); - - public get tank(): Tank { - return this._tank; - } - - public get ppO2(): number { - const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fO2); - return result; - } - - public get ppHe(): number { - const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fHe); - return result; - } - - public get ppN2(): number { - const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fN2); - return result; - } - - public get totalPp(): number { - return this.depthPressure; - } - - public get minDepth(): number { - const surface = this.depthConverter.surfacePressure; - const minDepthPressure = GasMixtures.ceiling(this.gas.fO2, surface); - return this.depthConverter.fromBar(minDepthPressure); - } - - public get maxDepth(): number { - const maxppO2 = 1.4; // TODO add to UI - const maxDepthPressure = GasMixtures.mod(1.4, this.gas.fO2); - return this.depthConverter.fromBar(maxDepthPressure); - } - - public get end(): number { - const endDepthPressure = GasMixtures.end(this.depthPressure, this.gas.fN2, this.gas.fO2); - return this.depthConverter.fromBar(endDepthPressure); - } - - public get mnd(): number { - const narcDepthBars = 4; // TODO add to UI - const endDepthPressure = GasMixtures.mnd(narcDepthBars, this.gas.fN2, this.gas.fO2); - return this.depthConverter.fromBar(endDepthPressure); - } - - public get density(): number { - const density = this.densityCalc.atDepth(this.gas, this.depth); - return density; - } - - private get gas(): Gas { - return this.tank.gas; - } - - private get depthPressure(): number { - return this.depthConverter.toBar(this.depth); - } -} diff --git a/projects/scuba-physics/src/lib/gas.properties.spec.ts b/projects/scuba-physics/src/lib/gas.properties.spec.ts new file mode 100644 index 00000000..7a67425c --- /dev/null +++ b/projects/scuba-physics/src/lib/gas.properties.spec.ts @@ -0,0 +1,91 @@ +import { GasProperties } from './gas.properties'; + +describe('Gas properties calculator', () => { + let sut: GasProperties; + + beforeEach(() => { + sut = new GasProperties(); + sut.depth = 30; + }); + + describe('Air at 30 m', () => { + beforeEach(() => { + sut.tank.o2 = 21; + }); + + it('MND is 30 m', () => { + expect(sut.mnd).toBeCloseTo(30, 3); + }); + + it('END is 30 m', () => { + expect(sut.end).toBeCloseTo(30, 3); + }); + + it('Minimum depth is 0 m', () => { + expect(sut.minDepth).toBeCloseTo(0, 3); + }); + + it('Maximum depth (MOD) is 57 m', () => { + expect(sut.maxDepth).toBeCloseTo(56.986, 3); + }); + + it('Total partial pressure is depth (4 b)', () => { + expect(sut.totalPp).toBeCloseTo(4, 3); + }); + + it('ppO2 is 0.836', () => { + expect(sut.ppO2).toBeCloseTo(0.836, 3); + }); + + it('ppHe is 0', () => { + expect(sut.ppHe).toBeCloseTo(0, 3); + }); + + it('ppN2 is 3.164', () => { + expect(sut.ppN2).toBeCloseTo(3.164, 3); + }); + + it('Density is 5.15 g/l', () => { + expect(sut.density).toBeCloseTo(5.151972, 6); + }); + }); + + describe('Trimix 10/70 at 30 m', () => { + beforeEach(() => { + sut.tank.o2 = 10; + sut.tank.he = 70; + }); + + it('MND is 123.3 m', () => { + expect(sut.mnd).toBeCloseTo(123.333, 3); + }); + + it('END is 2 m', () => { + expect(sut.end).toBeCloseTo(2, 3); + }); + + it('Minimum depth is 8 m', () => { + expect(sut.minDepth).toBeCloseTo(8, 3); + }); + + it('Maximum depth (MOD) is 130 m', () => { + expect(sut.maxDepth).toBeCloseTo(130, 3); + }); + + it('ppO2 is 0.4', () => { + expect(sut.ppO2).toBeCloseTo(0.4, 3); + }); + + it('ppHe is 2.8', () => { + expect(sut.ppHe).toBeCloseTo(2.8, 3); + }); + + it('ppN2 is 0.8', () => { + expect(sut.ppN2).toBeCloseTo(0.8, 3); + }); + + it('Density is 2 g/l', () => { + expect(sut.density).toBeCloseTo(2.0732, 6); + }); + }); +}); diff --git a/projects/scuba-physics/src/lib/gas.properties.ts b/projects/scuba-physics/src/lib/gas.properties.ts new file mode 100644 index 00000000..692a516e --- /dev/null +++ b/projects/scuba-physics/src/lib/gas.properties.ts @@ -0,0 +1,71 @@ +import { DensityAtDepth } from './GasDensity'; +import { Gas, GasMixtures } from './Gases'; +import { Tank } from './Tanks'; +import { DepthConverter } from './depth-converter'; + +export class GasProperties { + /** in meters */ + public depth = 0; + private readonly _tank = Tank.createDefault(); + private readonly depthConverter = DepthConverter.simple(); + private readonly densityCalc = new DensityAtDepth(this.depthConverter); + + public get tank(): Tank { + return this._tank; + } + + public get ppO2(): number { + const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fO2); + return result; + } + + public get ppHe(): number { + const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fHe); + return result; + } + + public get ppN2(): number { + const result = GasMixtures.partialPressure(this.depthPressure, this.gas.fN2); + return result; + } + + public get totalPp(): number { + return this.depthPressure; + } + + public get minDepth(): number { + const surface = this.depthConverter.surfacePressure; + const minDepthPressure = GasMixtures.ceiling(this.gas.fO2, surface); + return this.depthConverter.fromBar(minDepthPressure); + } + + public get maxDepth(): number { + const maxppO2 = 1.4; // TODO add to UI + const maxDepthPressure = GasMixtures.mod(1.4, this.gas.fO2); + return this.depthConverter.fromBar(maxDepthPressure); + } + + public get end(): number { + const endDepthPressure = GasMixtures.end(this.depthPressure, this.gas.fN2, this.gas.fO2); + return this.depthConverter.fromBar(endDepthPressure); + } + + public get mnd(): number { + const narcDepthBars = 4; // TODO add to UI + const endDepthPressure = GasMixtures.mnd(narcDepthBars, this.gas.fN2, this.gas.fO2); + return this.depthConverter.fromBar(endDepthPressure); + } + + public get density(): number { + const density = this.densityCalc.atDepth(this.gas, this.depth); + return density; + } + + private get gas(): Gas { + return this.tank.gas; + } + + private get depthPressure(): number { + return this.depthConverter.toBar(this.depth); + } +} diff --git a/projects/scuba-physics/src/public-api.ts b/projects/scuba-physics/src/public-api.ts index f5618583..a5146e14 100644 --- a/projects/scuba-physics/src/public-api.ts +++ b/projects/scuba-physics/src/public-api.ts @@ -13,6 +13,7 @@ export * from './lib/DepthLevels'; export * from './lib/Diver'; export * from './lib/Gases'; export * from './lib/GasDensity'; +export * from './lib/gas.properties'; export * from './lib/NitroxCalculator'; export * from './lib/Options'; export * from './lib/OtuCalculator';