diff --git a/projects/planner/src/app/shared/PlanUrlSerialization.spec.ts b/projects/planner/src/app/shared/PlanUrlSerialization.spec.ts index 83274fc8..ec611c00 100644 --- a/projects/planner/src/app/shared/PlanUrlSerialization.spec.ts +++ b/projects/planner/src/app/shared/PlanUrlSerialization.spec.ts @@ -30,7 +30,7 @@ describe('Url Serialization', () => { const dispatcher = new ReloadDispatcher(); units.imperialUnits = imperial; const schedules = new DiveSchedules(units, dispatcher); - const planner = new PlannerService(irrelevantFactory, schedules, dispatcher, units); + const planner = new PlannerService(schedules, dispatcher, irrelevantFactory, units); const viewSwitch = new ViewSwitchService(schedules); const preferences = new Preferences(viewSwitch, units, schedules, new ViewStates()); const urlSerialization = new PlanUrlSerialization(viewSwitch, units, schedules, preferences); diff --git a/projects/planner/src/app/shared/depths.service.spec.ts b/projects/planner/src/app/shared/depths.service.spec.ts index 7bf946a8..36182dfb 100644 --- a/projects/planner/src/app/shared/depths.service.spec.ts +++ b/projects/planner/src/app/shared/depths.service.spec.ts @@ -53,7 +53,6 @@ describe('Depths service', () => { describe('When Calculated', () => { it('Max bottom time is applied', () => { - console.log(depthService.segments); depthService.applyMaxDuration(); expect(depthService.planDuration).toBe(expectedDuration); }); diff --git a/projects/planner/src/app/shared/diveresults.ts b/projects/planner/src/app/shared/diveresults.ts index 8c317acf..2cbe4ee2 100644 --- a/projects/planner/src/app/shared/diveresults.ts +++ b/projects/planner/src/app/shared/diveresults.ts @@ -102,4 +102,10 @@ export class DiveResults { this.ceilings = []; this.events = []; } + + public endCalculation(): void { + this.profileCalculated = true; + this.diveInfoCalculated = true; + this.calculated = true; + } } diff --git a/projects/planner/src/app/shared/planner.service.ts b/projects/planner/src/app/shared/planner.service.ts index 4016ac23..d10335a1 100644 --- a/projects/planner/src/app/shared/planner.service.ts +++ b/projects/planner/src/app/shared/planner.service.ts @@ -34,26 +34,26 @@ export class PlannerService extends Streamed { private waypoints: WayPointsService; constructor( - private workerFactory: WorkersFactoryCommon, private schedules: DiveSchedules, private dispatcher: ReloadDispatcher, + workerFactory: WorkersFactoryCommon, units: UnitConversion) { super(); this.waypoints = new WayPointsService(units); - this.profileTask = this.workerFactory.createProfileWorker(); + this.profileTask = workerFactory.createProfileWorker(); this.profileTask.calculated$.pipe(takeUntil(this.unsubscribe$)) .subscribe((data) => this.continueCalculation(data)); this.profileTask.failed$.pipe(takeUntil(this.unsubscribe$)) .subscribe(() => this.profileFailed()); - this.diveInfoTask = this.workerFactory.createDiveInfoWorker(); + this.diveInfoTask = workerFactory.createDiveInfoWorker(); this.diveInfoTask.calculated$.pipe(takeUntil(this.unsubscribe$)) .subscribe((calculated) => this.finishDiveInfo(calculated)); this.diveInfoTask.failed$.pipe(takeUntil(this.unsubscribe$)) .subscribe(() => this.profileFailed()); - this.consumptionTask = this.workerFactory.createConsumptionWorker(); + this.consumptionTask = workerFactory.createConsumptionWorker(); this.consumptionTask.calculated$.pipe(takeUntil(this.unsubscribe$)) .subscribe((data) => this.finishCalculation(data)); this.consumptionTask.failed$.pipe(takeUntil(this.unsubscribe$)) @@ -88,9 +88,7 @@ export class PlannerService extends Streamed { this.calculatingProfile = false; this.calculatingDiveInfo = false; const dive = this.diveResult(diveId); - dive.profileCalculated = true; - dive.diveInfoCalculated = true; - dive.calculated = true; + dive.endCalculation(); } private showStillRunning(diveId: number): void { @@ -119,7 +117,7 @@ export class PlannerService extends Streamed { const tankData = dive.tanksService.tankData; const calculatedProfile = DtoSerialization.toProfile(result.profile, tankData); const events = DtoSerialization.toEvents(result.events); - const diveResult = this.diveResult(result.diveId); + const diveResult = dive.diveResult; diveResult.wayPoints = this.wayPointsFromResult(calculatedProfile); diveResult.ceilings = calculatedProfile.ceilings; diveResult.events = events.items; @@ -127,29 +125,32 @@ export class PlannerService extends Streamed { diveResult.averageDepth = Segments.averageDepth(calculatedProfile.segments); if (diveResult.endsOnSurface) { - const infoRequest = this.createProfileRequest(calculatedProfile.tissues, result.diveId); - this.diveInfoTask.calculate(infoRequest); - - const consumptionRequest = { - diveId: result.diveId, - plan: infoRequest.plan, - profile: DtoSerialization.fromSegments(calculatedProfile.segments), - options: infoRequest.options, - diver: DtoSerialization.fromDiver(dive.optionsService.getDiver()), - tanks: infoRequest.tanks - }; - this.consumptionTask.calculate(consumptionRequest); - - diveResult.profileCalculated = true; - this.calculatingProfile = false; - this.dispatcher.sendWayPointsCalculated(); + this.processCalculatedProfile(calculatedProfile, result, dive); } else { // fires info finished before the profile finished, case of error it doesn't matter this.profileFailed(result.diveId); - console.table(calculatedProfile.errors); } } + private processCalculatedProfile(calculatedProfile: CalculatedProfile, result: ProfileResultDto, dive: DiveSchedule) { + const infoRequest = this.createProfileRequest(calculatedProfile.tissues, result.diveId); + this.diveInfoTask.calculate(infoRequest); + + const consumptionRequest = { + diveId: result.diveId, + plan: infoRequest.plan, + profile: DtoSerialization.fromSegments(calculatedProfile.segments), + options: infoRequest.options, + diver: DtoSerialization.fromDiver(dive.optionsService.getDiver()), + tanks: infoRequest.tanks + }; + this.consumptionTask.calculate(consumptionRequest); + + dive.diveResult.profileCalculated = true; + this.calculatingProfile = false; + this.dispatcher.sendWayPointsCalculated(); + } + private createProfileRequest(previousDivetissues: LoadedTissue[], diveId: number): ProfileRequestDto { const dive = this.diveBy(diveId); const serializableTanks = dive.tanksService.tanks as ITankBound[];