Skip to content

Commit

Permalink
Added support for custom stress rmv
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Aug 8, 2024
1 parent b759a90 commit dd440ef
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion projects/planner/src/app/shared/PlanUrlSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ export class PlanUrlSerialization {
private static fromDiverParam(parseParam: string): DiverDto {
const context = new ParseContext(parseParam, ',');
const result: DiverDto = {
rmv: context.parseNumber(0)
rmv: context.parseNumber(0),
// TODO add test to verify default value is loaded if not present
stressRmv: context.parseNumber(1)
};

return result;
Expand Down
3 changes: 2 additions & 1 deletion projects/planner/src/app/shared/dtoSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ export class DtoSerialization {
public static fromDiver(diver: Diver): DiverDto {
return {
rmv: diver.rmv,
stressRmv: diver.stressRmv
};
}

public static toDiver(dto: DiverDto): Diver {
const diver = new Diver(dto.rmv);
const diver = new Diver(dto.rmv, dto.stressRmv);
return diver;
}

Expand Down
1 change: 1 addition & 0 deletions projects/planner/src/app/shared/serialization.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export interface GasDto {

export interface DiverDto {
rmv: number;
stressRmv: number;
}

export interface OptionsDto {
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/workers/planning.tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class PlanningTasks {
const segments = DtoSerialization.toSegments(task.plan, tanks);

// diver ppO2 is irrelevant for consumption calculation
const diver = new Diver(task.diver.rmv);
const diver = new Diver(task.diver.rmv, task.diver.stressRmv);

const options = DtoSerialization.toOptions(task.options);
const plan = PlanningTasks.selectConsumptionPlan(segments, task.isComplex);
Expand Down
19 changes: 14 additions & 5 deletions projects/scuba-physics/src/lib/Diver.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { Tank } from './Tanks';

export class Diver {
// liters/min
/** liters/min **/
public static readonly defaultSac = 20;
// TODO fix meaning of the value for one diver only
/** liter/min, usually 1.5x rmv for 2 divers (e.g. 3x) */

/** liter/min, usually 1.5x rmv for 1 diver only */
public stressRmv: number;

/**
* @param rmv liter/min
* @param rmvStress liter/min
*/
constructor(public rmv: number = Diver.defaultSac) {
this.stressRmv = rmv * 3;
constructor(public rmv: number = Diver.defaultSac, rmvStress?: number) {
this.stressRmv = rmvStress || rmv * 1.5;
}

/**
* Gets stress RMV for two divers.
* Value is derived from stressRmv in l/min.
**/
public get teamStressRmv() {
return this.stressRmv * 2;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion projects/scuba-physics/src/lib/consumption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class Consumption {
Tanks.resetConsumption(tanks);
const remainToConsume = this.consumeByTanks(segments, diver.rmv);
this.consumeByGases(segments, tanks, diver.rmv, remainToConsume);
this.updateReserve(emergencyAscent, tanks, diver.stressRmv);
this.updateReserve(emergencyAscent, tanks, diver.teamStressRmv);
}

/**
Expand Down

0 comments on commit dd440ef

Please sign in to comment.