diff --git a/projects/planner/src/app/profilechart/profilechart.component.ts b/projects/planner/src/app/profilechart/profilechart.component.ts index d0e059e4..24cefa10 100644 --- a/projects/planner/src/app/profilechart/profilechart.component.ts +++ b/projects/planner/src/app/profilechart/profilechart.component.ts @@ -1,6 +1,5 @@ import { Component, OnInit } from '@angular/core'; import { takeUntil } from 'rxjs'; -import { WayPoint } from '../shared/models'; import { DiveResults } from '../shared/diveresults'; import { faChartArea } from '@fortawesome/free-solid-svg-icons'; import * as Plotly from 'plotly.js-basic-dist'; @@ -11,6 +10,7 @@ import { ReloadDispatcher } from '../shared/reloadDispatcher'; import { ChartPlotter, ChartPlotterFactory } from '../shared/chartPlotter'; import { UnitConversion } from '../shared/UnitConversion'; import { ResamplingService } from '../shared/ResamplingService'; +import { WayPoint } from '../shared/wayPoint'; @Component({ selector: 'app-profilechart', diff --git a/projects/planner/src/app/shared/ResamplingService.ts b/projects/planner/src/app/shared/ResamplingService.ts index 37773571..ea2f6b64 100644 --- a/projects/planner/src/app/shared/ResamplingService.ts +++ b/projects/planner/src/app/shared/ResamplingService.ts @@ -1,8 +1,8 @@ import { Injectable } from '@angular/core'; -import { WayPoint } from './models'; import { Event, EventType, StandardGases, Precision, Ceiling } from 'scuba-physics'; import { UnitConversion } from './UnitConversion'; import { DateFormats } from './formaters'; +import { WayPoint } from './wayPoint'; export interface AxisValues { xValues: Date[]; diff --git a/projects/planner/src/app/shared/TestbedExtensions.spec.ts b/projects/planner/src/app/shared/TestbedExtensions.spec.ts index 64a2b032..d24f1695 100644 --- a/projects/planner/src/app/shared/TestbedExtensions.spec.ts +++ b/projects/planner/src/app/shared/TestbedExtensions.spec.ts @@ -1,9 +1,9 @@ -import { WayPoint } from './models'; import { - CalculatedProfile, Segment, StandardGases + Segment, StandardGases } from 'scuba-physics'; import { WayPointsService } from './waypoints.service'; import { UnitConversion } from './UnitConversion'; +import { WayPoint } from './wayPoint'; export class TestBedExtensions { public static sampleWayPoints(): WayPoint[] { diff --git a/projects/planner/src/app/shared/chartPlotter.ts b/projects/planner/src/app/shared/chartPlotter.ts index f60e7986..21679147 100644 --- a/projects/planner/src/app/shared/chartPlotter.ts +++ b/projects/planner/src/app/shared/chartPlotter.ts @@ -4,8 +4,8 @@ import { UnitConversion } from './UnitConversion'; import { ResamplingService } from './ResamplingService'; import { DiveResults } from './diveresults'; import { DateFormats } from './formaters'; -import { WayPoint } from './models'; import { Ceiling, Event } from 'scuba-physics'; +import { WayPoint } from './wayPoint'; /** Cant be Injectable because is builder pattern which keeps state from last configuration */ export class ChartPlotterFactory { diff --git a/projects/planner/src/app/shared/diff/ComparedWaypoint.ts b/projects/planner/src/app/shared/diff/ComparedWaypoint.ts index e5793284..32320a1a 100644 --- a/projects/planner/src/app/shared/diff/ComparedWaypoint.ts +++ b/projects/planner/src/app/shared/diff/ComparedWaypoint.ts @@ -1,4 +1,4 @@ -import { WayPoint } from '../models'; +import { WayPoint } from '../wayPoint'; export class ComparedWaypoint { public selected = false; diff --git a/projects/planner/src/app/shared/diff/profileComparatorService.ts b/projects/planner/src/app/shared/diff/profileComparatorService.ts index 66206132..cb7f68d1 100644 --- a/projects/planner/src/app/shared/diff/profileComparatorService.ts +++ b/projects/planner/src/app/shared/diff/profileComparatorService.ts @@ -4,9 +4,9 @@ import { DiveResults } from '../diveresults'; import { Observable, Subject, takeUntil } from 'rxjs'; import { ConsumptionByMix, IConsumedMix } from 'scuba-physics'; import { ComparedWaypoint } from './ComparedWaypoint'; -import { WayPoint } from '../models'; import { ReloadDispatcher } from '../reloadDispatcher'; import { Streamed } from '../streamed'; +import { WayPoint } from '../wayPoint'; @Injectable() export class ProfileComparatorService extends Streamed { 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 a53b62b2..463717ce 100644 --- a/projects/planner/src/app/shared/diff/profileCompoarator.service.spec.ts +++ b/projects/planner/src/app/shared/diff/profileCompoarator.service.spec.ts @@ -3,8 +3,8 @@ import { DiveSchedules } from '../dive.schedules'; import { ProfileComparatorService } from './profileComparatorService'; import { ReloadDispatcher } from '../reloadDispatcher'; import { UnitConversion } from '../UnitConversion'; -import { WayPoint } from '../models'; import { ConsumptionByMix, IConsumedMix, Segment, StandardGases, Tank } from 'scuba-physics'; +import { WayPoint } from '../wayPoint'; describe('ProfileComparison service', () => { let sut: ProfileComparatorService; diff --git a/projects/planner/src/app/shared/diveresults.ts b/projects/planner/src/app/shared/diveresults.ts index 8af45bbe..d9da2b5d 100644 --- a/projects/planner/src/app/shared/diveresults.ts +++ b/projects/planner/src/app/shared/diveresults.ts @@ -1,8 +1,8 @@ import { Ceiling, EventType, Event, HighestDensity, OtuCalculator, LoadedTissue } from 'scuba-physics'; -import { WayPoint } from './models'; import { Injectable } from '@angular/core'; +import { WayPoint } from './wayPoint'; @Injectable() export class DiveResults { diff --git a/projects/planner/src/app/shared/models.ts b/projects/planner/src/app/shared/models.ts index 2f9cc57a..bc27e68e 100644 --- a/projects/planner/src/app/shared/models.ts +++ b/projects/planner/src/app/shared/models.ts @@ -1,6 +1,5 @@ import { - Time, Segment, - StandardGases, Tank, + Time, Segment, Tank, Precision, TankTemplate, Options, Diver, GasDensity } from 'scuba-physics'; @@ -238,111 +237,3 @@ export class TankBound implements IGasContent, ITankSize { this.tank.assignStandardGas(gasName); } } - -export enum SwimAction { - hover = 0, - ascent = 1, - descent = 2, - switch = 3 -} - -export class WayPoint { - public selected = false; - - /** in seconds */ - public startTime = 0; - /** in seconds */ - public endTime = 0; - /** in meters */ - private _startDepth = 0; - /** in meters */ - private _endDepth = 0; - /** meters per sec */ - private speed = 0; - - private action: SwimAction = SwimAction.hover; - - private _gasName = ''; - - /** - * @param duration in seconds - * @param newDepth in meters - * @param previousDepth in meters - */ - private constructor(private units: UnitConversion, public duration: number, newDepth: number, previousDepth: number = 0) { - this.endTime = Precision.roundTwoDecimals(duration); - this._endDepth = newDepth; - this._startDepth = previousDepth; - this.updateSwimAction(); - } - - public get gasName(): string { - return this._gasName; - } - - /** in respective units */ - public get startDepth(): number { - return this.units.fromMeters(this._startDepth); - } - - /** in meters */ - public get startDepthMeters(): number { - return this._startDepth; - } - - /** in respective units */ - public get endDepth(): number { - return this.units.fromMeters(this._endDepth); - } - - /** in meters */ - public get endDepthMeters(): number { - return this._endDepth; - } - - public get swimAction(): SwimAction { - return this.action; - } - - public static fromSegment(units: UnitConversion, segment: Segment): WayPoint { - const newWayPoint = new WayPoint(units, segment.duration, segment.endDepth); - const gasName = StandardGases.nameFor(segment.gas.fO2, segment.gas.fHe); - newWayPoint._gasName = gasName; - newWayPoint.speed = segment.speed; - return newWayPoint; - } - - public asGasSwitch(): void { - this.action = SwimAction.switch; - } - - public toLevel(segment: Segment): WayPoint { - const result = WayPoint.fromSegment(this.units, segment); - result.startTime = this.endTime; - const end = this.endTime + segment.duration; - result.endTime = Precision.roundTwoDecimals(end); - result._startDepth = this._endDepth; - result.updateSwimAction(); - return result; - } - - public fits(timeStamp: number): boolean { - return this.startTime <= timeStamp && timeStamp < this.endTime; - } - - public depthAt(duration: number): number { - return Segment.depthAt(this._startDepth, this.speed, duration); - } - - private updateSwimAction(): void { - this.action = SwimAction.hover; - - if (this._startDepth < this._endDepth) { - this.action = SwimAction.descent; - } - - if (this._startDepth > this._endDepth) { - this.action = SwimAction.ascent; - } - } -} diff --git a/projects/planner/src/app/shared/planner.service.ts b/projects/planner/src/app/shared/planner.service.ts index 0b2f8d31..67c42453 100644 --- a/projects/planner/src/app/shared/planner.service.ts +++ b/projects/planner/src/app/shared/planner.service.ts @@ -16,10 +16,10 @@ import { IBackgroundTask } from '../workers/background-task'; import { Streamed } from './streamed'; import { DiveSchedule, DiveSchedules } from './dive.schedules'; import { UnitConversion } from './UnitConversion'; -import { WayPoint } from './models'; import { ReloadDispatcher } from './reloadDispatcher'; import { Logger } from './Logger'; import { ViewSwitchService } from './viewSwitchService'; +import { WayPoint } from './wayPoint'; @Injectable() diff --git a/projects/planner/src/app/shared/selectedwaypointService.spec.ts b/projects/planner/src/app/shared/selectedwaypointService.spec.ts index cd4cc076..a038b524 100644 --- a/projects/planner/src/app/shared/selectedwaypointService.spec.ts +++ b/projects/planner/src/app/shared/selectedwaypointService.spec.ts @@ -1,11 +1,11 @@ import { SelectedWaypoint } from './selectedwaypointService'; import { inject, TestBed } from '@angular/core/testing'; import { Segment, StandardGases } from 'scuba-physics'; -import { WayPoint } from './models'; import { UnitConversion } from './UnitConversion'; import {ReloadDispatcher} from './reloadDispatcher'; import {DiveSchedules} from './dive.schedules'; import {TestBedExtensions} from './TestbedExtensions.spec'; +import { WayPoint } from './wayPoint'; describe('Selected Waypoint', () => { const segment = new Segment(5, 10, StandardGases.air, 60); diff --git a/projects/planner/src/app/shared/selectedwaypointService.ts b/projects/planner/src/app/shared/selectedwaypointService.ts index 2fcb5652..162456f1 100644 --- a/projects/planner/src/app/shared/selectedwaypointService.ts +++ b/projects/planner/src/app/shared/selectedwaypointService.ts @@ -1,7 +1,7 @@ import { EventEmitter, Injectable, Input, Output } from '@angular/core'; -import { WayPoint } from './models'; import { DiveSchedules } from './dive.schedules'; import { DateFormats } from './formaters'; +import { WayPoint } from './wayPoint'; @Injectable() export class SelectedWaypoint { diff --git a/projects/planner/src/app/shared/stopsFilter.service.ts b/projects/planner/src/app/shared/stopsFilter.service.ts index af21eae8..4d840ca2 100644 --- a/projects/planner/src/app/shared/stopsFilter.service.ts +++ b/projects/planner/src/app/shared/stopsFilter.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; -import { SwimAction, WayPoint } from './models'; import { DiveResults } from './diveresults'; import { DiveSchedules } from './dive.schedules'; +import { WayPoint, SwimAction } from './wayPoint'; @Injectable() export class StopsFilter { diff --git a/projects/planner/src/app/shared/wayPoint.ts b/projects/planner/src/app/shared/wayPoint.ts new file mode 100644 index 00000000..e8b0dd8f --- /dev/null +++ b/projects/planner/src/app/shared/wayPoint.ts @@ -0,0 +1,110 @@ +import { UnitConversion } from './UnitConversion'; +import { Precision, Segment, StandardGases } from 'scuba-physics'; + +export enum SwimAction { + hover = 0, + ascent = 1, + descent = 2, + switch = 3 +} + +export class WayPoint { + public selected = false; + + /** in seconds */ + public startTime = 0; + /** in seconds */ + public endTime = 0; + /** in meters */ + private _startDepth = 0; + /** in meters */ + private _endDepth = 0; + /** meters per sec */ + private speed = 0; + + private action: SwimAction = SwimAction.hover; + + private _gasName = ''; + + /** + * @param duration in seconds + * @param newDepth in meters + * @param previousDepth in meters + */ + private constructor(private units: UnitConversion, public duration: number, newDepth: number, previousDepth: number = 0) { + this.endTime = Precision.roundTwoDecimals(duration); + this._endDepth = newDepth; + this._startDepth = previousDepth; + this.updateSwimAction(); + } + + public get gasName(): string { + return this._gasName; + } + + /** in respective units */ + public get startDepth(): number { + return this.units.fromMeters(this._startDepth); + } + + /** in meters */ + public get startDepthMeters(): number { + return this._startDepth; + } + + /** in respective units */ + public get endDepth(): number { + return this.units.fromMeters(this._endDepth); + } + + /** in meters */ + public get endDepthMeters(): number { + return this._endDepth; + } + + public get swimAction(): SwimAction { + return this.action; + } + + public static fromSegment(units: UnitConversion, segment: Segment): WayPoint { + const newWayPoint = new WayPoint(units, segment.duration, segment.endDepth); + const gasName = StandardGases.nameFor(segment.gas.fO2, segment.gas.fHe); + newWayPoint._gasName = gasName; + newWayPoint.speed = segment.speed; + return newWayPoint; + } + + public asGasSwitch(): void { + this.action = SwimAction.switch; + } + + public toLevel(segment: Segment): WayPoint { + const result = WayPoint.fromSegment(this.units, segment); + result.startTime = this.endTime; + const end = this.endTime + segment.duration; + result.endTime = Precision.roundTwoDecimals(end); + result._startDepth = this._endDepth; + result.updateSwimAction(); + return result; + } + + public fits(timeStamp: number): boolean { + return this.startTime <= timeStamp && timeStamp < this.endTime; + } + + public depthAt(duration: number): number { + return Segment.depthAt(this._startDepth, this.speed, duration); + } + + private updateSwimAction(): void { + this.action = SwimAction.hover; + + if (this._startDepth < this._endDepth) { + this.action = SwimAction.descent; + } + + if (this._startDepth > this._endDepth) { + this.action = SwimAction.ascent; + } + } +} diff --git a/projects/planner/src/app/shared/waypoints.service.ts b/projects/planner/src/app/shared/waypoints.service.ts index 92bd7cb1..30fab151 100644 --- a/projects/planner/src/app/shared/waypoints.service.ts +++ b/projects/planner/src/app/shared/waypoints.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { UnitConversion } from './UnitConversion'; -import { WayPoint } from './models'; import { Segment } from 'scuba-physics'; +import { WayPoint } from "./wayPoint"; @Injectable() export class WayPointsService { diff --git a/projects/planner/src/app/waypoints/waypoints.component.ts b/projects/planner/src/app/waypoints/waypoints.component.ts index 30f46fa5..ec6595bb 100644 --- a/projects/planner/src/app/waypoints/waypoints.component.ts +++ b/projects/planner/src/app/waypoints/waypoints.component.ts @@ -1,5 +1,4 @@ import { Component } from '@angular/core'; -import { WayPoint, SwimAction } from '../shared/models'; import { faArrowDown, faArrowUp, faArrowRight, faTasks, faRandom, IconDefinition, faFilter @@ -8,6 +7,7 @@ import { UnitConversion } from '../shared/UnitConversion'; import { SelectedWaypoint } from '../shared/selectedwaypointService'; import { ViewSwitchService } from '../shared/viewSwitchService'; import { StopsFilter } from '../shared/stopsFilter.service'; +import { WayPoint, SwimAction } from '../shared/wayPoint'; @Component({ selector: 'app-waypoints',