Skip to content

Commit

Permalink
moved no deco and ndlInvalid to dive
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Pokorny committed Oct 9, 2023
1 parent 305269a commit dc5619b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/depths.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
20 changes: 15 additions & 5 deletions projects/planner/src/app/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -163,7 +163,7 @@ export class TankBound implements IGasContent{
}

public set workingPressure(newValue: number) {
if(isNaN(newValue)) {
if (isNaN(newValue)) {
return;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions projects/planner/src/app/shared/plan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/planner.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
9 changes: 2 additions & 7 deletions projects/planner/src/app/shared/planner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
Expand Down Expand Up @@ -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[];
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit dc5619b

Please sign in to comment.