Skip to content

Commit

Permalink
Added tank reserve to model and serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Aug 16, 2024
1 parent ef13c78 commit 328b6de
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
9 changes: 5 additions & 4 deletions doc/missingTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

* Add tests for Diver.ts
* PersistenceService:
* Save and load AppSettings from store (density)
* Density not saved yet, default value is loaded
* Save and load AppSettings from store (density, warnings, tank reserve)
* AppSettings not saved yet, default value is loaded
* LoadFromUrl:
* Loads current density (no change)
* Loads app settings (density, warnings, tank reserve) with no change
* Loads and saves stressRmv and rmv
* Loads default stressRmv, if not present in URL
* ProfileEvents: Generates correct events based on maxDensity
Expand All @@ -14,11 +14,12 @@
* PlannerService:
* MaxGasDensity is used when calling task
* Events are filtered by AppSettings
* Scheduler: Change of maxDensity triggers schedule calculation
* Scheduler or AppSettingsComponent: Change of maxDensity triggers schedule calculation
* Diver.component.ts: Add tests for rmv and stressRmv save and load
* AppSettingsComponent:
* Precision and Step for imperial units
* Precision and Step for metric units
* Values are reloaded after switch to and from imperial units and click Use button
* Values are Saved to PreferencesStore after clicking Use button
* Values are loaded from PreferencesStore after component initialization
* Reset to default
27 changes: 24 additions & 3 deletions projects/planner/src/app/shared/ApplicationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { UnitConversion } from './UnitConversion';
import { AppSettings } from './models';
import { GasDensity } from 'scuba-physics';
import { AppOptionsDto } from './serialization.model';

@Injectable()
export class ApplicationSettingsService {
Expand All @@ -20,6 +21,14 @@ export class ApplicationSettingsService {
return this.units.fromGramPerLiter(this.appSettings.maxGasDensity);
}

public get primaryTankReserve(): number {
return this.units.fromBar(this.appSettings.primaryTankReserve);
}

public get stageTankReserve(): number {
return this.units.fromBar(this.appSettings.stageTankReserve);
}

/** in current units **/
public get defaultMaxGasDensity(): number {
return this.units.fromGramPerLiter(GasDensity.recommendedMaximum);
Expand All @@ -41,6 +50,14 @@ export class ApplicationSettingsService {
this.appSettings.maxGasDensity = this.units.toGramPerLiter(value);
}

public set primaryTankReserve(newValue: number) {
this.appSettings.primaryTankReserve = this.units.toBar(newValue);
}

public set stageTankReserve(newValue: number) {
this.appSettings.stageTankReserve = this.units.toBar(newValue);
}

public set icdIgnored(newValue: boolean) {
this.appSettings.icdIgnored = newValue;
}
Expand All @@ -53,8 +70,12 @@ export class ApplicationSettingsService {
this.appSettings.noDecoIgnored = newValue;
}

public loadFrom(maxDensity: number): void {
this.settings.maxGasDensity = maxDensity;
// TODO add ignored issues and tank reserve
public loadFrom(source: AppOptionsDto): void {
this.settings.maxGasDensity = source.maxDensity || GasDensity.recommendedMaximum;
this.settings.primaryTankReserve = source.primaryTankReserve || AppSettings.defaultPrimaryReserve;
this.settings.stageTankReserve = source.stageTankReserve || AppSettings.defaultStageReserve;
this.settings.icdIgnored = source.icdIgnored || false;
this.settings.densityIgnored = source.densityIgnored || false;
this.settings.noDecoIgnored = source.noDecoIgnored || false;
}
}
7 changes: 6 additions & 1 deletion projects/planner/src/app/shared/PlanUrlSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,12 @@ export class PlanUrlSerialization {
imperialUnits: context.parseBoolean(1),
language: 'en',
// Not part of the url:
maxDensity: this.appSettings.settings.maxGasDensity
maxDensity: this.appSettings.settings.maxGasDensity,
primaryTankReserve: this.appSettings.settings.primaryTankReserve,
stageTankReserve: this.appSettings.settings.stageTankReserve,
icdIgnored: this.appSettings.settings.icdIgnored,
densityIgnored: this.appSettings.settings.densityIgnored,
noDecoIgnored: this.appSettings.settings.noDecoIgnored
};
}
}
8 changes: 6 additions & 2 deletions projects/planner/src/app/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ export class Level {
* Not added to the Url, since it is not needed for sharing.
*/
export class AppSettings {
// TODO move default values to library GasConsumptions
public static readonly defaultPrimaryReserve = 30;
public static readonly defaultStageReserve = 20;

public maxGasDensity = GasDensity.recommendedMaximum;
public primaryTankReserve = 30;
public stageTankReserve = 20;
public primaryTankReserve = AppSettings.defaultPrimaryReserve;
public stageTankReserve = AppSettings.defaultStageReserve;
public icdIgnored = false;
public noDecoIgnored = false;
public densityIgnored = false;
Expand Down
11 changes: 8 additions & 3 deletions projects/planner/src/app/shared/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export class Preferences {
// first apply units to prevent loading of invalid values
this.units.imperialUnits = loaded.options.imperialUnits;
this.applyDives(loaded.dives);
const loadedDensity = loaded.options.maxDensity || GasDensity.recommendedMaximum;
this.appSettings.loadFrom(loadedDensity);
this.appSettings.loadFrom(loaded.options);

// now we are able to switch the view
this.viewSwitch.isComplex = loaded.options.isComplex;
Expand Down Expand Up @@ -110,11 +109,17 @@ export class Preferences {
}

private toAppSettings(): AppOptionsDto {
const settings = this.appSettings.settings;
return {
imperialUnits: this.units.imperialUnits,
isComplex: this.viewSwitch.isComplex,
language: 'en',
maxDensity: this.appSettings.settings.maxGasDensity
maxDensity: settings.maxGasDensity,
primaryTankReserve: settings.primaryTankReserve,
stageTankReserve: settings.stageTankReserve,
icdIgnored: settings.icdIgnored,
densityIgnored: settings.densityIgnored,
noDecoIgnored: settings.noDecoIgnored
};
}

Expand Down
5 changes: 5 additions & 0 deletions projects/planner/src/app/shared/serialization.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export interface AppOptionsDto {
isComplex: boolean;
language: string;
maxDensity: number;
primaryTankReserve: number;
stageTankReserve: number;
icdIgnored: boolean;
densityIgnored: boolean;
noDecoIgnored: boolean;
}

/**
Expand Down

0 comments on commit 328b6de

Please sign in to comment.