Skip to content

Commit

Permalink
Added gas density to normalization service
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Aug 15, 2024
1 parent b7c128d commit 0265b06
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ describe('App settings component', () => {
// TODO AppSettings:
// * After changing units, also the range values need to be reloaded
// * Add save and load last form state. Do we want this? Or together with reset to default?
// * Apply to algorithm
// * add to normalization service


// TODO missing test cases:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,12 @@ export class AppSettingsComponent implements OnInit {
return this.inputs.controlInValid(densityControl);
}

public get densityRounding(): number {
return this.units.imperialUnits ? 3 : 1;
}

public get densityStep(): number {
return Math.pow(0.1, this.densityRounding);
return Math.pow(0.1, this.ranges.densityRounding);
}

private get maxDensity(): number {
return Precision.round(this.appSettings.maxGasDensity, this.densityRounding);
return Precision.round(this.appSettings.maxGasDensity, this.ranges.densityRounding);
}

public ngOnInit(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Url Serialization', () => {
const appSettings = new ApplicationSettingsService(units);
const planner = new PlannerService(schedules, dispatcher, viewSwitch, appSettings, irrelevantFactory, units);
const preferences = new Preferences(viewSwitch, units, schedules, appSettings, new ViewStates());
const normalization = new SettingsNormalizationService(units, schedules);
const normalization = new SettingsNormalizationService(units, appSettings, schedules);
const urlSerialization = new PlanUrlSerialization(viewSwitch, units, normalization,
schedules, appSettings, preferences);
const firstDive = schedules.dives[0];
Expand Down
3 changes: 3 additions & 0 deletions projects/planner/src/app/shared/UnitConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export interface RangeConstants {
depthLabel: string;
maxDensity: [number, number];
maxDensityLabel: string;
densityRounding: number;
narcoticDepth: [number, number];
narcoticDepthLabel: string;
lastStopDepth: [number, number];
Expand Down Expand Up @@ -205,6 +206,7 @@ class MetricRanges implements RangeConstants {
public readonly durationLabel: string = toLabel(this.duration, 'min');
public readonly maxDensity: [number, number] = [1, 10];
public readonly maxDensityLabel: string = toLabel(this.maxDensity, this.units.densityShortcut);
public readonly densityRounding: number = 1;
public readonly narcoticDepth: [number, number] = [1, 100];
public readonly narcoticDepthLabel: string = toLabel(this.narcoticDepth, this.units.lengthShortcut);
public readonly nitroxOxygen: [number, number] = [21, 100];
Expand Down Expand Up @@ -243,6 +245,7 @@ class ImperialRanges implements RangeConstants {
public readonly durationLabel: string = toLabel(this.duration, 'min');
public readonly maxDensity: [number, number] = [0.0624, 0.624];
public readonly maxDensityLabel: string = toLabel(this.maxDensity, this.units.densityShortcut);
public readonly densityRounding: number = 4;
public readonly narcoticDepth: [number, number] = [1, 300];
public readonly narcoticDepthLabel: string = toLabel(this.narcoticDepth, this.units.lengthShortcut);
public readonly nitroxOxygen: [number, number] = [21, 100];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DiverOptions } from './models';
import { DiveSchedules } from './dive.schedules';
import { ViewStates } from './viewStates';
import { ReloadDispatcher } from './reloadDispatcher';
import { ApplicationSettingsService } from './ApplicationSettings';

describe('SettingsNormalizationService', () => {
let service: SettingsNormalizationService;
Expand All @@ -30,7 +31,8 @@ describe('SettingsNormalizationService', () => {
providers: [
RouterTestingModule, UnitConversion,
SettingsNormalizationService, ReloadDispatcher,
ViewStates, DiveSchedules
ViewStates, DiveSchedules,
ApplicationSettingsService
],
imports: [RouterTestingModule.withRoutes([])]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { Precision } from 'scuba-physics';
import { OptionsService } from './options.service';
import { TanksService } from './tanks.service';
import { RangeConstants, UnitConversion } from './UnitConversion';
import { ViewStates } from './viewStates';
import { DepthsService } from './depths.service';
import { DiveSchedule, DiveSchedules } from './dive.schedules';
import { ApplicationSettingsService } from './ApplicationSettings';

@Injectable()
export class SettingsNormalizationService {
constructor(
private units: UnitConversion,
private appSettings: ApplicationSettingsService,
private schedules: DiveSchedules
) { }

Expand All @@ -28,6 +29,16 @@ export class SettingsNormalizationService {
this.normalizeSegments(dive.depths);
}

private applyToAppSettings(): void {
const settings = this.appSettings.settings;
const densityRounding = this.units.ranges.densityRounding;

settings.maxGasDensity = this.fitUnit(
v => this.units.fromGramPerLiter(v),
v => this.units.toGramPerLiter(v),
settings.maxGasDensity, this.units.ranges.maxDensity, densityRounding);
}

private applyToOptions(options: OptionsService): void {
const oDiver = options.diverOptions;
const rmvRounding = this.units.ranges.rmvRounding;
Expand Down

0 comments on commit 0265b06

Please sign in to comment.