Skip to content

Commit

Permalink
Fixed normalization of options
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed May 7, 2024
1 parent d02ac91 commit 0d3d863
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ describe('App settings component', () => {
expect(options.diverOptions.rmv).toBeCloseTo(29.998867, 6);
});

it('Applies recreational options', () => {
expect(options.maxEND).toBeCloseTo(100, 4);
it('Rounds END', () => {
expect(options.maxEND).toBeCloseTo(98, 4);
});

it('Applies units change', inject([UnitConversion],
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/PlanUrlSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class PlanUrlSerialization {
if (!foundByUrl) {
// the loaded dive was valid in its original units, so normalization fixes the range.
const added = this.preferences.addLoaded(parsed.dives[0]);
// this.normalization.applyDive(added);
this.normalization.applyDive(added);

if (parsed.options.isComplex) {
this.viewSwitch.isComplex = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('SettingsNormalizationService', () => {
it('Updates depth level options to 10 feet', () => {
expect(options.decoStopDistance).toBeCloseTo(3.048, 4);
expect(options.minimumAutoStopDepth).toBeCloseTo(10.0584, 4);
expect(options.lastStopDepth).toBeCloseTo(4.572, 4);
expect(options.lastStopDepth).toBeCloseTo(3.048, 4);
});

it('Updates diver rounded rmv', () => {
Expand All @@ -79,12 +79,12 @@ describe('SettingsNormalizationService', () => {
});

it('Rounds options feet', () => {
expect(options.maxEND).toBeCloseTo(30.48, 4);
expect(options.maxEND).toBeCloseTo(29.8704, 4);
expect(options.altitude).toBeCloseTo(99.9744, 4);
expect(options.ascentSpeed50perc).toBeCloseTo(9.144, 4);
expect(options.ascentSpeed50percTo6m).toBeCloseTo(9.144, 4);
expect(options.ascentSpeed6m).toBeCloseTo(9.144, 4);
expect(options.descentSpeed).toBeCloseTo(18.288, 4);
expect(options.ascentSpeed50percTo6m).toBeCloseTo(6.096, 4);
expect(options.ascentSpeed6m).toBeCloseTo(3.048, 4);
expect(options.descentSpeed).toBeCloseTo(17.9832, 4);
});

it('Rounds segments to feet', () => {
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('SettingsNormalizationService', () => {
it('Updates depth level options to 3 m', () => {
expect(options.decoStopDistance).toBe(3);
expect(options.minimumAutoStopDepth).toBe(10);
expect(options.lastStopDepth).toBe(5);
expect(options.lastStopDepth).toBe(3);
});

it('Updates diver rounded rmv liters', () => {
Expand All @@ -145,8 +145,8 @@ describe('SettingsNormalizationService', () => {
expect(options.maxEND).toBe(30);
expect(options.altitude).toBe(100);
expect(options.ascentSpeed50perc).toBe(9);
expect(options.ascentSpeed50percTo6m).toBe(9);
expect(options.ascentSpeed6m).toBe(9);
expect(options.ascentSpeed50percTo6m).toBe(6);
expect(options.ascentSpeed6m).toBe(3);
expect(options.descentSpeed).toBe(18);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ export class SettingsNormalizationService {

private normalizeOptions(options: OptionsService): void {
const altitudeRange = this.ranges.altitude;
const speedRange = this.ranges.speed;
options.altitude = this.fitUnit(u => u, v => v, options.altitude, altitudeRange);
options.useRecreational(); // to round usage of options to nice values
options.ascentSpeed50perc = this.fitUnit(u => u, v => v, options.ascentSpeed50perc, speedRange);
options.ascentSpeed50percTo6m = this.fitUnit(u => u, v => v, options.ascentSpeed50percTo6m, speedRange);
options.ascentSpeed6m = this.fitUnit(u => u, v => v, options.ascentSpeed6m, speedRange);
options.descentSpeed = this.fitUnit(u => u, v => v, options.descentSpeed, speedRange);
options.lastStopDepth = this.fitUnit(u => u, v => v, options.lastStopDepth, this.ranges.lastStopDepth);
options.maxEND = this.fitUnit(u => u, v => v, options.maxEND, this.ranges.narcoticDepth);
}

private normalizeTanks(tanksService: TanksService): void {
Expand Down

0 comments on commit 0d3d863

Please sign in to comment.