From 8368fd50c131051377383c41a58e98f7818b6e7d Mon Sep 17 00:00:00 2001 From: Jiri Pokorny Date: Wed, 1 Jan 2025 23:29:04 +0100 Subject: [PATCH] Added over pressures comparison test. --- .../diff-profilechart.component.ts | 21 +++++-------------- .../shared/diff/profileComparatorService.ts | 14 +++++++++++++ .../diff/profileCompoarator.service.spec.ts | 21 +++++++++++++++++++ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/projects/planner/src/app/diff/profilechart/diff-profilechart.component.ts b/projects/planner/src/app/diff/profilechart/diff-profilechart.component.ts index e2910744..f8c5170c 100644 --- a/projects/planner/src/app/diff/profilechart/diff-profilechart.component.ts +++ b/projects/planner/src/app/diff/profilechart/diff-profilechart.component.ts @@ -36,7 +36,7 @@ export class ProfileDifferenceChartComponent extends Streamed implements OnInit const chartPlotterFactory = new ChartPlotterFactory(resampling, units); const profileATraces = chartPlotterFactory.withNamePrefix('Profile A ') - .create(() => this.profileA); + .create(() => this.profileComparatorService.profileAResults); const profileBTraces = chartPlotterFactory .withNamePrefix('Profile B ') .wthAverageDepthColor('rgb(188,191,192)') @@ -44,7 +44,7 @@ export class ProfileDifferenceChartComponent extends Streamed implements OnInit .wthCeilingColor(ChartPlotterFactory.depthLineColorB) .wthEventFillColor(ChartPlotterFactory.depthLineColorB) .wthEventLineColor('rgb(118,119,120)') - .create(() => this.profileB); + .create(() => this.profileComparatorService.profileBResults); this.plotter = new ChartPlotter('diveplotdiff', chartPlotterFactory, profileBTraces, profileATraces); this.heatMapPlotterA = new HeatMapPlotter('heatmapPlotA'); @@ -75,14 +75,6 @@ export class ProfileDifferenceChartComponent extends Streamed implements OnInit return this.profileComparatorService.profilesCalculated; } - private get profileA(): DiveResults { - return this.profileComparatorService.profileAResults; - } - - private get profileB(): DiveResults { - return this.profileComparatorService.profileBResults; - } - public ngOnInit(): void { if (this.profilesCalculated) { this.plotCharts(); @@ -115,12 +107,9 @@ export class ProfileDifferenceChartComponent extends Streamed implements OnInit this.plotter.plotCharts(this.profileComparatorService.totalDuration); if(this.heatMapEnabled) { - // TODO rescale different profile duration to the same max. duration (add surface tissues offgasing to shorter dive) - const overPressuresA = this.profileA.tissueOverPressures; - this.heatMapPlotterA.plotHeatMap(overPressuresA); - - const overPressuresB = this.profileB.tissueOverPressures; - this.heatMapPlotterB.plotHeatMap(overPressuresB); + var overPressures = this.profileComparatorService.overPressures; + this.heatMapPlotterA.plotHeatMap(overPressures.profileAOverPressures); + this.heatMapPlotterB.plotHeatMap(overPressures.profileBOverPressures); } } diff --git a/projects/planner/src/app/shared/diff/profileComparatorService.ts b/projects/planner/src/app/shared/diff/profileComparatorService.ts index cb7f68d1..080a6638 100644 --- a/projects/planner/src/app/shared/diff/profileComparatorService.ts +++ b/projects/planner/src/app/shared/diff/profileComparatorService.ts @@ -8,6 +8,11 @@ import { ReloadDispatcher } from '../reloadDispatcher'; import { Streamed } from '../streamed'; import { WayPoint } from '../wayPoint'; +export interface SaturationComparison { + profileAOverPressures: number[][]; + profileBOverPressures: number[][]; +} + @Injectable() export class ProfileComparatorService extends Streamed { private _profileAIndex = 0; @@ -108,6 +113,15 @@ export class ProfileComparatorService extends Streamed { return this.profileAResults.showResults && this.profileBResults.showResults; } + 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; + return { + profileAOverPressures: this.profileAResults.tissueOverPressures, + profileBOverPressures: this.profileBResults.tissueOverPressures + }; + } + private get wayPointsA(): WayPoint[]{ return this.profileAResults.wayPoints; } diff --git a/projects/planner/src/app/shared/diff/profileCompoarator.service.spec.ts b/projects/planner/src/app/shared/diff/profileCompoarator.service.spec.ts index 463717ce..dc4ab604 100644 --- a/projects/planner/src/app/shared/diff/profileCompoarator.service.spec.ts +++ b/projects/planner/src/app/shared/diff/profileCompoarator.service.spec.ts @@ -5,6 +5,10 @@ import { ReloadDispatcher } from '../reloadDispatcher'; import { UnitConversion } from '../UnitConversion'; import { ConsumptionByMix, IConsumedMix, Segment, StandardGases, Tank } from 'scuba-physics'; import { WayPoint } from '../wayPoint'; +import { PlannerService } from '../planner.service'; +import { ViewSwitchService } from "../viewSwitchService"; +import { ApplicationSettingsService } from "../ApplicationSettings"; +import { WorkersFactoryCommon } from "../serial.workers.factory"; describe('ProfileComparison service', () => { let sut: ProfileComparatorService; @@ -17,6 +21,8 @@ describe('ProfileComparison service', () => { providers: [ ProfileComparatorService, UnitConversion, ReloadDispatcher, DiveSchedules, + PlannerService, ViewSwitchService, + ApplicationSettingsService, WorkersFactoryCommon ] }).compileComponents(); }); @@ -161,4 +167,19 @@ describe('ProfileComparison service', () => { expect(sut.profileBIndex).toEqual(0); }); }); + + xit('Tissue saturation Both have the same amount of samples', () => { + schedules.add(); + schedules.dives[1].depths.planDuration = 14; + sut.selectProfile(1); + const planner = TestBed.inject(PlannerService); + // needed to get the finale 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); + }); });