Skip to content

Commit

Permalink
Extracted waypoint from model
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Aug 9, 2024
1 parent 78b382d commit ce25fc3
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/ResamplingService.ts
Original file line number Diff line number Diff line change
@@ -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[];
Expand Down
4 changes: 2 additions & 2 deletions projects/planner/src/app/shared/TestbedExtensions.spec.ts
Original file line number Diff line number Diff line change
@@ -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[] {
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/chartPlotter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/diff/ComparedWaypoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WayPoint } from '../models';
import { WayPoint } from '../wayPoint';

export class ComparedWaypoint {
public selected = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/diveresults.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
111 changes: 1 addition & 110 deletions projects/planner/src/app/shared/models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Time, Segment,
StandardGases, Tank,
Time, Segment, Tank,
Precision, TankTemplate, Options,
Diver, GasDensity
} from 'scuba-physics';
Expand Down Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/planner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/selectedwaypointService.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/stopsFilter.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
110 changes: 110 additions & 0 deletions projects/planner/src/app/shared/wayPoint.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 1 addition & 1 deletion projects/planner/src/app/shared/waypoints.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion projects/planner/src/app/waypoints/waypoints.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component } from '@angular/core';
import { WayPoint, SwimAction } from '../shared/models';
import {
faArrowDown, faArrowUp, faArrowRight, faTasks,
faRandom, IconDefinition, faFilter
Expand All @@ -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',
Expand Down

0 comments on commit ce25fc3

Please sign in to comment.