From 6e3ff1b4391210aa3c2aa3d0623aa8df79c52d14 Mon Sep 17 00:00:00 2001 From: Jiri Pokorny Date: Wed, 6 Mar 2024 02:20:18 +0100 Subject: [PATCH] Adjusted gas blender precision --- .../gas-blender/gas-blender.component.spec.ts | 4 ---- .../app/gas-blender/gas-blender.component.ts | 1 - .../src/app/shared/gas-blender.service.spec.ts | 5 +++++ .../src/app/shared/gas-blender.service.ts | 3 +-- projects/scuba-physics/src/lib/gasBlender.ts | 18 +++++++++++------- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/projects/planner/src/app/gas-blender/gas-blender.component.spec.ts b/projects/planner/src/app/gas-blender/gas-blender.component.spec.ts index 393aedc3..08e0b150 100644 --- a/projects/planner/src/app/gas-blender/gas-blender.component.spec.ts +++ b/projects/planner/src/app/gas-blender/gas-blender.component.spec.ts @@ -27,8 +27,4 @@ describe('GasBlenderComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); - - // TODO test cases - // - imperial values: source pressure, target pressure, results, AddO2, AddHe, AddTop - // - imperial values: shows removeFrom source }); diff --git a/projects/planner/src/app/gas-blender/gas-blender.component.ts b/projects/planner/src/app/gas-blender/gas-blender.component.ts index a8f242db..a5633402 100644 --- a/projects/planner/src/app/gas-blender/gas-blender.component.ts +++ b/projects/planner/src/app/gas-blender/gas-blender.component.ts @@ -137,6 +137,5 @@ export class GasBlenderComponent implements OnInit { // TODO Gas blender component: // Do we need Reload? - // add service tests // save/load state } diff --git a/projects/planner/src/app/shared/gas-blender.service.spec.ts b/projects/planner/src/app/shared/gas-blender.service.spec.ts index f59f3d91..bb6a4a23 100644 --- a/projects/planner/src/app/shared/gas-blender.service.spec.ts +++ b/projects/planner/src/app/shared/gas-blender.service.spec.ts @@ -8,6 +8,11 @@ describe('Gas blender service', () => { sut = new GasBlenderService(new UnitConversion()); }); + // TODO test cases: + // - all result fields + // - add exception handling in case we are unable to create target mix. + // - imperial values: source pressure, target pressure, results, AddO2, AddHe, AddTop + // - imperial values: shows removeFrom source it('Creates', () => { expect(sut).toBeTruthy(); }); diff --git a/projects/planner/src/app/shared/gas-blender.service.ts b/projects/planner/src/app/shared/gas-blender.service.ts index 87e0dda1..ffee0098 100644 --- a/projects/planner/src/app/shared/gas-blender.service.ts +++ b/projects/planner/src/app/shared/gas-blender.service.ts @@ -46,7 +46,7 @@ export class GasBlenderService { } public get removeFromSource(): number { - return 0;// this.results.removeFromSource; + return this.results.removeFromSource; } public get needsRemove(): boolean { @@ -77,7 +77,6 @@ export class GasBlenderService { } }; - // TODO add exception handling in case we are unable to create target mix. this.results = GasBlender.mix(request); } } diff --git a/projects/scuba-physics/src/lib/gasBlender.ts b/projects/scuba-physics/src/lib/gasBlender.ts index c5689785..f2dfdef1 100644 --- a/projects/scuba-physics/src/lib/gasBlender.ts +++ b/projects/scuba-physics/src/lib/gasBlender.ts @@ -1,5 +1,5 @@ import { Tank, TankFill } from './Tanks'; -import { Precision } from "./precision"; +import { Precision } from './precision'; /** * Blending result showing amount of each component used @@ -75,10 +75,12 @@ export class GasBlender { const finalN2 = finalfN2 * request.target.pressure; const currentfN2 = GasBlender.n2(request.source); const currentN2 = currentfN2 * request.source.pressure; - const addN2 = finalN2 - currentN2; + let addN2 = finalN2 - currentN2; + addN2 = Precision.round(addN2, 8); + // Even the top mix contains more nitrogen than target, we are still able to mix // by adding less top mix and more He and O2 - if(Precision.round(addN2, 8) < 0) { + if(addN2 < 0) { const removeSource = -(addN2 / currentfN2); return GasBlender.mixByRemoving(request, removeSource); } @@ -88,16 +90,18 @@ export class GasBlender { const targetHe = request.target.pressure * request.target.he; const sourceHe = request.source.pressure * request.source.he; const topHe = addTop * request.topMix.he; - const addHe = targetHe - sourceHe - topHe; + let addHe = targetHe - sourceHe - topHe; + addHe = Precision.round(addHe, 8); - if(Precision.round(addHe, 8) < 0) { + if(addHe < 0) { const removeSource = -(addHe / request.source.he); return GasBlender.mixByRemoving(request, removeSource); } - const addO2 = request.target.pressure - request.source.pressure - addHe - addTop; + let addO2 = request.target.pressure - request.source.pressure - addHe - addTop; + addO2 = Precision.round(addO2, 8); - if(Precision.round(addO2, 8) < 0) { + if(addO2 < 0) { const removeSource = -(addO2 / request.source.o2); return GasBlender.mixByRemoving(request, removeSource); }