Skip to content

Commit

Permalink
Fixed formatting in dive results diff
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Mar 22, 2024
1 parent 9549af9 commit 5214262
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
</div>
</td>
</tr>
<tr *ngIf="showMaxBottomTimeOfProfile">
<tr *ngIf="diff.showMaxBottomTime">
<td>Maximum bottom time [min]:</td>
<td>
<div>
Expand All @@ -162,14 +162,14 @@
<div>
{{ diff.highestDensity.valueA | number:'1.0-2' }}
<br>
({{densityTextOfProfile(profileA)}})
({{diff.densityGasA}})
</div>
</td>
<td>
<div>
{{ diff.highestDensity.valueB | number:'1.0-2' }}
<br>
({{densityTextOfProfile(profileB)}})
({{diff.densityGasB}})
</div>
</td>
<td class="{{diff.highestDensity.bgColor}}">
Expand Down Expand Up @@ -206,18 +206,18 @@
<td>CNS toxicity [%]:</td>
<td>
<div>
{{cnsTextOfProfile(profileA)}}
{{diff.cnsA}}
</div>
</td>
<td>
<div>
{{cnsTextOfProfile(profileB)}}
{{diff.cnsB}}
</div>
</td>
<td class="{{diff.cns.bgColor}}">
<div class="delta d-flex justify-content-between align-items-center">
<strong>
{{ cnsDifferenceText(diff.cns.difference) | number:'1.0-0' }}
{{ diff.cnsDifference | number:'1.0-0' }}
</strong>
<fa-icon [icon] ="diff.cns.arrow"/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,80 +58,115 @@ class ResultDiff {
}
}

@Component({
selector: 'app-diff-diveresults-table',
templateUrl: './diff-diveresults-table.component.html',
styleUrls: ['./diff-diveresults-table.component.scss', '../../diff.component.scss']
})
export class DiveResultsTableDifferenceComponent {
public diff = {
totalDuration: new ResultDiff(this.profileA, this.profileB, 1, d => d.totalDuration),
timeToSurface: new ResultDiff(this.profileA, this.profileB, -1, d => d.timeToSurface),
averageDepth: new ResultDiff(this.profileA, this.profileB, -1, d => d.averageDepth),
emergencyAscentStart: new ResultDiff(this.profileA, this.profileB, -1, d => d.emergencyAscentStart),
noDeco: new ResultDiff(this.profileA, this.profileB, 1, d => d.noDecoTime),
maxTime: new ResultDiff(this.profileA, this.profileB, 1, d => d.maxTime),
highestDensity: new ResultDiff(this.profileA, this.profileB, -1, d => d.highestDensity.density),
otu: new ResultDiff(this.profileA, this.profileB, -1, d => d.otu),
cns: new ResultDiff(this.profileA, this.profileB, -1, d => d.cns),
};

class DiveResulsDiff {
public totalDuration = new ResultDiff(this.profileA, this.profileB, 1,
d => d.totalDuration);
public timeToSurface = new ResultDiff(this.profileA, this.profileB, -1,
d => d.timeToSurface);
public averageDepth = new ResultDiff(this.profileA, this.profileB, -1,
d => this.units.fromMeters(d.averageDepth));
public emergencyAscentStart = new ResultDiff(this.profileA, this.profileB, -1,
d => d.emergencyAscentStart);
public noDeco = new ResultDiff(this.profileA, this.profileB, 1,
d => d.noDecoTime);
public maxTime = new ResultDiff(this.profileA, this.profileB, 1,
d => d.maxTime);
public highestDensity = new ResultDiff(this.profileA, this.profileB, -1,
d => this.density(d));
public otu = new ResultDiff(this.profileA, this.profileB, -1,
d => d.otu);
public cns = new ResultDiff(this.profileA, this.profileB, -1,
d => d.cns);

private readonly maxCns = 1000;
private readonly cnsDifferenceUnderMinusOneThousand = '< -1000';

constructor(
public viewSwitch: ViewSwitchService,
public units: UnitConversion,
public profilesDiff: ProfileComparatorService) {
public constructor(private units: UnitConversion, private profileA: DiveResults, private profileB: DiveResults) {
}

public get profileA(): DiveResults {
return this.profilesDiff.profileAResults;
public get densityGasA(): string {
return this.densityFormatted(this.profileA);
}

public get profileB(): DiveResults {
return this.profilesDiff.profileBResults;
public get densityGasB(): string {
return this.densityFormatted(this.profileA);
}

public get diveInfosCalculated(): boolean {
return this.profilesDiff.areDiveInfosCalculated();
public get cnsA(): string {
return this.cnsFormatted(this.profileA);
}

public get areProfilesCalculated(): boolean {
return this.profilesDiff.areProfilesCalculated();
public get cnsB(): string {
return this.cnsFormatted(this.profileA);
}

public cnsDifferenceText(diff: number): string {
if(diff >= 1000) {
public get cnsDifference(): string {
const diff = this.cns.difference;

if(diff >= this.maxCns) {
return TextConstants.cnsOverOneThousand;
}

if(diff <= -1000) {
if(diff <= -this.maxCns) {
return this.cnsDifferenceUnderMinusOneThousand;
}

return formatNumber(diff, 'en', '1.0-0');
}

public showMaxBottomTimeOfProfile(profile: DiveResults): boolean {
return profile.maxTime > 0;
}

public highestDensityOfProfile(profile: DiveResults): number {
const density = profile.highestDensity.density;
return this.units.fromGramPerLiter(density);
public get showMaxBottomTime(): boolean {
return this.profileA.maxTime > 0 && this.profileB.maxTime > 0;
}

public densityTextOfProfile(profile: DiveResults): string {
private densityFormatted(profile: DiveResults): string {
const gas = profile.highestDensity.gas.name;
const depth = this.units.fromMeters(profile.highestDensity.depth);
return `${gas} at ${depth} ${this.units.length}`;
}

public cnsTextOfProfile(profile: DiveResults): string {
if(profile.cns >= 1000) {
private density(profile: DiveResults): number {
const density = profile.highestDensity.density;
return this.units.fromGramPerLiter(density);
}

private cnsFormatted(profile: DiveResults): string {
if(profile.cns >= this.maxCns) {
return TextConstants.cnsOverOneThousand;
}

return formatNumber(profile.cns, 'en', '1.0-0');
}
}

@Component({
selector: 'app-diff-diveresults-table',
templateUrl: './diff-diveresults-table.component.html',
styleUrls: ['./diff-diveresults-table.component.scss', '../../diff.component.scss']
})
export class DiveResultsTableDifferenceComponent {
public constructor(
public viewSwitch: ViewSwitchService,
public units: UnitConversion,
public profilesDiff: ProfileComparatorService) {
}

public get diff(): DiveResulsDiff {
return new DiveResulsDiff(this.units, this.profileA, this.profileB);
}

public get profileA(): DiveResults {
return this.profilesDiff.profileAResults;
}

public get profileB(): DiveResults {
return this.profilesDiff.profileBResults;
}

public get diveInfosCalculated(): boolean {
return this.profilesDiff.areDiveInfosCalculated();
}

public get areProfilesCalculated(): boolean {
return this.profilesDiff.areProfilesCalculated();
}
}

0 comments on commit 5214262

Please sign in to comment.