From dc5619b5faff8e4e8737b2a0d3c83bd31a5ad6e1 Mon Sep 17 00:00:00 2001 From: Jiri Pokorny Date: Mon, 9 Oct 2023 17:54:46 +0200 Subject: [PATCH] moved no deco and ndlInvalid to dive --- .../depths-simple/depths-simple.component.ts | 2 +- .../planner/src/app/shared/depths.service.ts | 2 +- projects/planner/src/app/shared/models.ts | 20 ++++++++++++++----- .../planner/src/app/shared/plan.service.ts | 5 ----- .../src/app/shared/planner.service.spec.ts | 2 +- .../planner/src/app/shared/planner.service.ts | 9 ++------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/projects/planner/src/app/depths-simple/depths-simple.component.ts b/projects/planner/src/app/depths-simple/depths-simple.component.ts index 29b99235..96d756f1 100644 --- a/projects/planner/src/app/depths-simple/depths-simple.component.ts +++ b/projects/planner/src/app/depths-simple/depths-simple.component.ts @@ -47,7 +47,7 @@ export class DepthsSimpleComponent extends Streamed implements OnInit { } public get noDecoTime(): number { - return this.plan.noDecoTime; + return this.planner.dive.noDecoTime; } public get durationInvalid(): boolean { diff --git a/projects/planner/src/app/shared/depths.service.ts b/projects/planner/src/app/shared/depths.service.ts index f916d732..f5348237 100644 --- a/projects/planner/src/app/shared/depths.service.ts +++ b/projects/planner/src/app/shared/depths.service.ts @@ -93,7 +93,7 @@ export class DepthsService extends Streamed { } public applyNdlDuration(): void { - const newValue = this.plan.noDecoTime; + const newValue = this.planner.dive.noDecoTime; this.assignDuration(newValue); this.apply(); } diff --git a/projects/planner/src/app/shared/models.ts b/projects/planner/src/app/shared/models.ts index 992a92ce..48e76724 100644 --- a/projects/planner/src/app/shared/models.ts +++ b/projects/planner/src/app/shared/models.ts @@ -58,7 +58,7 @@ export class Level { } export class DiverOptions { - constructor(private options: Options = new Options(), private diver: Diver = new Diver()) {} + constructor(private options: Options = new Options(), private diver: Diver = new Diver()) { } public get maxPpO2(): number { return this.options.maxPpO2; @@ -101,7 +101,7 @@ export interface IGasContent { assignStandardGas(gasName: string): void; } -export class TankBound implements IGasContent{ +export class TankBound implements IGasContent { private _workingPressure: number; constructor(public tank: Tank, private units: UnitConversion) { @@ -163,7 +163,7 @@ export class TankBound implements IGasContent{ } public set workingPressure(newValue: number) { - if(isNaN(newValue)) { + if (isNaN(newValue)) { return; } @@ -174,7 +174,7 @@ export class TankBound implements IGasContent{ /** For serialization purpose only */ public set workingPressureBars(newValue: number) { - if(isNaN(newValue)) { + if (isNaN(newValue)) { return; } @@ -202,6 +202,8 @@ export class TankBound implements IGasContent{ } export class Dive { + private static readonly maxAcceptableNdl = 1000; + public noDecoTime = 0; public calculated = false; public diveInfoCalculated = false; public profileCalculated = false; @@ -213,7 +215,7 @@ export class Dive { public needsReturn = false; public notEnoughGas = false; public notEnoughTime = false; - public noDecoExceeded = false; + public planDuration = 0; public emergencyAscentStart = 0; public averageDepth = 0; public otu = 0; @@ -232,6 +234,14 @@ export class Dive { return this.wayPoints[this.wayPoints.length - 1].endTime; } + public get ndlValid(): boolean { + return this.diveInfoCalculated && this.noDecoTime < Dive.maxAcceptableNdl; + } + + public get noDecoExceeded(): boolean { + return this.planDuration > this.noDecoTime; + } + /** the only errors preventing draw chart */ public get hasErrors(): boolean { return this.calculated && (this.calculationFailed || this.notEnoughTime); diff --git a/projects/planner/src/app/shared/plan.service.ts b/projects/planner/src/app/shared/plan.service.ts index bde35b30..7f47cc08 100644 --- a/projects/planner/src/app/shared/plan.service.ts +++ b/projects/planner/src/app/shared/plan.service.ts @@ -7,7 +7,6 @@ import { Strategies } from './models'; @Injectable() export class Plan { private static readonly defaultDuration = Time.oneMinute * 10; - public noDecoTime = 0; // TODO move strategy to Consumption algorithm selection public strategy: Strategies = Strategies.ALL; /** Event fired only in case of segments rebuild. Not fired when adding or removing. */ @@ -61,10 +60,6 @@ export class Plan { return this.strategy !== Strategies.ALL; } - public get noDecoExceeded(): boolean { - return this.duration > this.noDecoTime; - } - public copySegments(): Segments { return this._segments.copy(); } diff --git a/projects/planner/src/app/shared/planner.service.spec.ts b/projects/planner/src/app/shared/planner.service.spec.ts index a70ff522..bb8a7dcd 100644 --- a/projects/planner/src/app/shared/planner.service.spec.ts +++ b/projects/planner/src/app/shared/planner.service.spec.ts @@ -60,7 +60,7 @@ describe('PlannerService', () => { describe('Dive info calculated', () => { it('No deco limit is calculated', () => { - const noDecoLimit = plan.noDecoTime; + const noDecoLimit = planner.dive.noDecoTime; expect(noDecoLimit).toBe(12); }); diff --git a/projects/planner/src/app/shared/planner.service.ts b/projects/planner/src/app/shared/planner.service.ts index e2a8e480..ae8879ca 100644 --- a/projects/planner/src/app/shared/planner.service.ts +++ b/projects/planner/src/app/shared/planner.service.ts @@ -21,7 +21,6 @@ import { OptionsService } from './options.service'; @Injectable() export class PlannerService extends Streamed { - public static readonly maxAcceptableNdl = 1000; // there always needs to be at least one public dive: Dive = new Dive(); public infoCalculated$: Observable; @@ -65,10 +64,6 @@ export class PlannerService extends Streamed { .subscribe(() => this.profileFailed()); } - public get ndlValid(): boolean { - return this.dive.diveInfoCalculated && this.plan.noDecoTime < PlannerService.maxAcceptableNdl; - } - private get serializableTanks(): ITankBound[] { return this.tanks.tanks as ITankBound[]; } @@ -173,10 +168,10 @@ export class PlannerService extends Streamed { } private finishDiveInfo(diveInfo: DiveInfoResultDto): void { - this.plan.noDecoTime = diveInfo.noDeco; + this.dive.noDecoTime = diveInfo.noDeco; this.dive.otu = diveInfo.otu; this.dive.cns = diveInfo.cns; - this.dive.noDecoExceeded = this.plan.noDecoExceeded; + this.dive.planDuration = this.plan.duration; this.dive.notEnoughTime = this.plan.notEnoughTime; this.dive.highestDensity = DtoSerialization.toDensity(diveInfo.density); this.dive.diveInfoCalculated = true;