Skip to content

Commit

Permalink
Implemented tissues saturation alignment in diff
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Jan 7, 2025
1 parent 3e392d8 commit 48f4f6d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
34 changes: 30 additions & 4 deletions projects/planner/src/app/shared/diff/profileComparatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { Injectable } from '@angular/core';
import { DiveSchedule, DiveSchedules } from '../dive.schedules';
import { DiveResults } from '../diveresults';
import { Observable, Subject, takeUntil } from 'rxjs';
import { ConsumptionByMix, IConsumedMix } from 'scuba-physics';
import {
ConsumptionByMix, IConsumedMix,
SurfaceIntervalParameters, BuhlmannAlgorithm,
TissueOverPressures, Time
} from 'scuba-physics';
import { ComparedWaypoint } from './ComparedWaypoint';
import { ReloadDispatcher } from '../reloadDispatcher';
import { Streamed } from '../streamed';
Expand Down Expand Up @@ -114,10 +118,23 @@ export class ProfileComparatorService extends Streamed {
}

public get overPressures(): SaturationComparison {
// TODO rescale different profile duration to the same max. duration (add surface tissues offgasing to shorter dive)
const aLonger = this.profileAResults.planDuration > this.profileBResults.planDuration;
const durationDiff = this.profileAResults.totalDuration - this.profileBResults.totalDuration;
const surfaceInterval = Math.abs(durationDiff);

// add to the shorter one and don't store it in the result, since it is used only for the diff
if(durationDiff > 0) {
const surfaceIntervalOverPressures = this.applySurfaceInterval(this.profileB, surfaceInterval);
const profileBOverPressures = [...this.profileBResults.tissueOverPressures, ...surfaceIntervalOverPressures];
return {
profileAOverPressures: this.profileAResults.tissueOverPressures,
profileBOverPressures: profileBOverPressures
};
}

const surfaceIntervalOverPressures = this.applySurfaceInterval(this.profileA, surfaceInterval);
const profileAOverPressures = [...this.profileAResults.tissueOverPressures, ...surfaceIntervalOverPressures];
return {
profileAOverPressures: this.profileAResults.tissueOverPressures,
profileAOverPressures: profileAOverPressures,
profileBOverPressures: this.profileBResults.tissueOverPressures
};
}
Expand Down Expand Up @@ -171,6 +188,15 @@ export class ProfileComparatorService extends Streamed {
context.next();
}
}

private applySurfaceInterval(profile: DiveSchedule, surfaceInterval: number): TissueOverPressures {
const altitude = profile.optionsService.altitude;
const tissues = profile.diveResult.finalTissues;
const parameters = new SurfaceIntervalParameters(tissues, altitude, surfaceInterval);
const algorithm = new BuhlmannAlgorithm();
const changes = algorithm.applySurfaceInterval(parameters);
return changes.tissueOverPressures;
}
}

class WaypointsDiffContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { DiveSchedules } from '../dive.schedules';
import { ProfileComparatorService } from './profileComparatorService';
import { ReloadDispatcher } from '../reloadDispatcher';
import { UnitConversion } from '../UnitConversion';
import { ConsumptionByMix, IConsumedMix, Segment, StandardGases, Tank } from 'scuba-physics';
import {
ConsumptionByMix, FeatureFlags, IConsumedMix, Segment, StandardGases, Tank
} from 'scuba-physics';
import { WayPoint } from '../wayPoint';
import { PlannerService } from '../planner.service';
import { ViewSwitchService } from "../viewSwitchService";
Expand Down Expand Up @@ -168,18 +170,20 @@ describe('ProfileComparison service', () => {
});
});

xit('Tissue saturation Both have the same amount of samples', () => {
it('Tissue saturation Both have the same amount of samples', () => {
FeatureFlags.Instance.collectSaturation = true;
schedules.add();
schedules.dives[1].depths.planDuration = 14;
sut.selectProfile(1);
const planner = TestBed.inject(PlannerService);
// needed to get the finale over pressures
// needed to get the final over pressures
planner.calculate(1);
planner.calculate(2);

const overPressures = sut.overPressures;
const lengthB = overPressures.profileAOverPressures.length;
const lengthA = overPressures.profileBOverPressures.length;
expect(lengthA).toEqual(lengthB);
FeatureFlags.Instance.collectSaturation = false;
});
});
7 changes: 3 additions & 4 deletions projects/planner/src/app/shared/diveresults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Ceiling, EventType, Event, HighestDensity, OtuCalculator, LoadedTissue
Ceiling, EventType, Event, HighestDensity,
OtuCalculator, LoadedTissue, TissueOverPressures
} from 'scuba-physics';
import { Injectable } from '@angular/core';
import { WayPoint } from './wayPoint';
Expand All @@ -26,9 +27,7 @@ export class DiveResults {
/** In meaning of at end of the dive */
public finalTissues: LoadedTissue[] = [];
// 16 tissues overpressure history
public tissueOverPressures: number[][] = [
[0],[0],[0],[0], [0],[0],[0],[0], [0],[0],[0],[0], [0],[0],[0],[0],
];
public tissueOverPressures: TissueOverPressures = [];
public events: Event[] = [];


Expand Down

0 comments on commit 48f4f6d

Please sign in to comment.