Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions src/app/calculator/steam/steam-leak/convert-steam-leak.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { Injectable } from '@angular/core';
import { FacilitySteamLeakData, SteamLeakSurveyData, SteamLeakSurveyInput, SteamLeakSurveyResult } from '../../../shared/models/standalone';
import { ConvertUnitsService } from '../../../shared/convert-units/convert-units.service';
import { Settings } from '../../../shared/models/settings';
import { roundVal } from '../../../shared/helperFunctions';

@Injectable()
export class ConvertSteamLeakService {

constructor(private convertUnitsService: ConvertUnitsService) { }

// Convert metric inputs to Imperial before passing to calculation suite
convertInputs(inputArray: Array<SteamLeakSurveyData>, settings: Settings): void {
if (settings.unitsOfMeasure === 'Metric') {
for (let i = 0; i < inputArray.length; i++) {
inputArray[i].estimateMethodData.leakRate = this.convertUnitsService.value(inputArray[i].estimateMethodData.leakRate).from('kg').to('lb');

inputArray[i].estimateTurbineMethodData.leakRate = this.convertUnitsService.value(inputArray[i].estimateTurbineMethodData.leakRate).from('kg').to('lb');

inputArray[i].orificeMethodData.holeSize = this.convertUnitsService.value(inputArray[i].orificeMethodData.holeSize).from('cm').to('in');
inputArray[i].orificeMethodData.atmosphericPressure = this.convertUnitsService.value(inputArray[i].orificeMethodData.atmosphericPressure).from('kPaa').to('psia');

inputArray[i].plumeMethodData.plumeLength = this.convertUnitsService.value(inputArray[i].plumeMethodData.plumeLength).from('cm').to('in');
inputArray[i].plumeMethodData.ambientTemperature = this.convertUnitsService.value(inputArray[i].plumeMethodData.ambientTemperature).from('C').to('F');
}
}
}

// Convert FacilitySteamLeakData metric inputs to Imperial before passing to suite
convertFacilityInputs(facilityData: FacilitySteamLeakData, settings: Settings): FacilitySteamLeakData {
if (settings.unitsOfMeasure === 'Metric') {
facilityData.steamTemperature = this.convertUnitsService.value(facilityData.steamTemperature).from('C').to('F');
facilityData.steamPressure = this.convertUnitsService.value(facilityData.steamPressure).from('kPaa').to('psia');
facilityData.feedwaterTemperature = this.convertUnitsService.value(facilityData.feedwaterTemperature).from('C').to('F');
}
return facilityData;
}

// Convert suite result (always Imperial) to display units
convertResult(result: SteamLeakSurveyResult, settings: Settings): SteamLeakSurveyResult {
if (settings.unitsOfMeasure === 'Metric') {
result.leakRate = this.convertUnitsService.value(result.leakRate).from('lb').to('kg');
result.steamLoss = this.convertUnitsService.value(result.steamLoss).from('Btu').to('kJ');
result.energyLoss = this.convertUnitsService.value(result.energyLoss).from('Btu').to('kJ');
}
return result;
}

convertInputDataImperialToMetric(inputData: SteamLeakSurveyData): SteamLeakSurveyData {
inputData.estimateMethodData.leakRate = this.convertUnitsService.value(inputData.estimateMethodData.leakRate).from('lb').to('kg');
inputData.estimateMethodData.leakRate = roundVal(inputData.estimateMethodData.leakRate);

inputData.estimateTurbineMethodData.leakRate = this.convertUnitsService.value(inputData.estimateTurbineMethodData.leakRate).from('lb').to('kg');
inputData.estimateTurbineMethodData.leakRate = roundVal(inputData.estimateTurbineMethodData.leakRate);

inputData.orificeMethodData.holeSize = this.convertUnitsService.value(inputData.orificeMethodData.holeSize).from('in').to('cm');
inputData.orificeMethodData.holeSize = roundVal(inputData.orificeMethodData.holeSize);
inputData.orificeMethodData.atmosphericPressure = this.convertUnitsService.value(inputData.orificeMethodData.atmosphericPressure).from('psia').to('kPaa');
inputData.orificeMethodData.atmosphericPressure = roundVal(inputData.orificeMethodData.atmosphericPressure);

inputData.plumeMethodData.plumeLength = this.convertUnitsService.value(inputData.plumeMethodData.plumeLength).from('in').to('cm');
inputData.plumeMethodData.plumeLength = roundVal(inputData.plumeMethodData.plumeLength);
inputData.plumeMethodData.ambientTemperature = this.convertUnitsService.value(inputData.plumeMethodData.ambientTemperature).from('F').to('C');
inputData.plumeMethodData.ambientTemperature = roundVal(inputData.plumeMethodData.ambientTemperature);

return inputData;
}

convertInputDataMetricToImperial(inputData: SteamLeakSurveyData): SteamLeakSurveyData {
inputData.estimateMethodData.leakRate = this.convertUnitsService.value(inputData.estimateMethodData.leakRate).from('kg').to('lb');
inputData.estimateMethodData.leakRate = roundVal(inputData.estimateMethodData.leakRate);

inputData.estimateTurbineMethodData.leakRate = this.convertUnitsService.value(inputData.estimateTurbineMethodData.leakRate).from('kg').to('lb');
inputData.estimateTurbineMethodData.leakRate = roundVal(inputData.estimateTurbineMethodData.leakRate);

inputData.orificeMethodData.holeSize = this.convertUnitsService.value(inputData.orificeMethodData.holeSize).from('cm').to('in');
inputData.orificeMethodData.holeSize = roundVal(inputData.orificeMethodData.holeSize);
inputData.orificeMethodData.atmosphericPressure = this.convertUnitsService.value(inputData.orificeMethodData.atmosphericPressure).from('kPaa').to('psia');
inputData.orificeMethodData.atmosphericPressure = roundVal(inputData.orificeMethodData.atmosphericPressure);

inputData.plumeMethodData.plumeLength = this.convertUnitsService.value(inputData.plumeMethodData.plumeLength).from('cm').to('in');
inputData.plumeMethodData.plumeLength = roundVal(inputData.plumeMethodData.plumeLength);
inputData.plumeMethodData.ambientTemperature = this.convertUnitsService.value(inputData.plumeMethodData.ambientTemperature).from('C').to('F');
inputData.plumeMethodData.ambientTemperature = roundVal(inputData.plumeMethodData.ambientTemperature);

return inputData;
}

convertFacilitySteamLeakData(
inputData: FacilitySteamLeakData,
oldSettings: Settings,
newSettings?: Settings
): FacilitySteamLeakData {
if (oldSettings.unitsOfMeasure === 'Imperial' && (!newSettings || newSettings.unitsOfMeasure === 'Metric')) {
inputData = this.convertImperialFacilitySteamLeakData(inputData);
} else if (oldSettings.unitsOfMeasure === 'Metric' && (!newSettings || newSettings.unitsOfMeasure === 'Imperial')) {
inputData = this.convertMetricFacilitySteamLeakData(inputData);
}
return inputData;
}

convertImperialFacilitySteamLeakData(inputData: FacilitySteamLeakData): FacilitySteamLeakData {
inputData.steamTemperature = this.convertUnitsService.value(inputData.steamTemperature).from('F').to('C');
inputData.steamTemperature = roundVal(inputData.steamTemperature);
inputData.steamPressure = this.convertUnitsService.value(inputData.steamPressure).from('psia').to('kPaa');
inputData.steamPressure = roundVal(inputData.steamPressure);
inputData.feedwaterTemperature = this.convertUnitsService.value(inputData.feedwaterTemperature).from('F').to('C');
inputData.feedwaterTemperature = roundVal(inputData.feedwaterTemperature);
return inputData;
}

convertMetricFacilitySteamLeakData(inputData: FacilitySteamLeakData): FacilitySteamLeakData {
inputData.steamTemperature = this.convertUnitsService.value(inputData.steamTemperature).from('C').to('F');
inputData.steamTemperature = roundVal(inputData.steamTemperature);
inputData.steamPressure = this.convertUnitsService.value(inputData.steamPressure).from('kPaa').to('psia');
inputData.steamPressure = roundVal(inputData.steamPressure);
inputData.feedwaterTemperature = this.convertUnitsService.value(inputData.feedwaterTemperature).from('C').to('F');
inputData.feedwaterTemperature = roundVal(inputData.feedwaterTemperature);
return inputData;
}

convertExample(steamLeakInputExample: SteamLeakSurveyInput): SteamLeakSurveyInput {
steamLeakInputExample.steamLeakSurveyInputVec.forEach((inputData, index) => {
steamLeakInputExample.steamLeakSurveyInputVec[index] = this.convertInputDataImperialToMetric(inputData);
});
steamLeakInputExample.facilitySteamLeakData = this.convertImperialFacilitySteamLeakData(steamLeakInputExample.facilitySteamLeakData);
return steamLeakInputExample;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class SteamLeakSurveyFormComponent implements OnDestroy {
addLeak(): void {
const current = this.surveyService.steamLeakInput();
if (!current) return;
const emptyLeak = this.formService.getEmptySteamLeakData();
const emptyLeak = this.formService.getEmptySteamLeakData(this.settings());
const updatedLeaks = [...current.steamLeakSurveyInputVec, emptyLeak];
this.surveyService.steamLeakInput.set({ ...current, steamLeakSurveyInputVec: updatedLeaks });
this.surveyService.currentLeakIndex.set(updatedLeaks.length - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SteamLeakSurveyData,
} from '../../../../shared/models/standalone';
import { SteamLeakMeasurementMethod } from '../steam-leak-constants';
import { ConvertSteamLeakService } from '../convert-steam-leak.service';

const HOURS_PER_YEAR = 8760;

Expand Down Expand Up @@ -56,6 +57,7 @@ export interface FacilitySteamLeakFormControls {
@Injectable()
export class SteamLeakSurveyFormService {
private readonly fb = inject(FormBuilder);
private readonly convertSteamLeakService = inject(ConvertSteamLeakService);

buildLeakMetaForm(leak: SteamLeakSurveyData): FormGroup<LeakMetaFormControls> {
return this.fb.group<LeakMetaFormControls>({
Expand Down Expand Up @@ -127,8 +129,8 @@ export class SteamLeakSurveyFormService {
};
}

getEmptySteamLeakData(): SteamLeakSurveyData {
return {
getEmptySteamLeakData(settings?: Settings): SteamLeakSurveyData {
let data: SteamLeakSurveyData = {
leakDescription: 'New Leak Description',
name: 'New Leak',
selected: true,
Expand All @@ -139,5 +141,9 @@ export class SteamLeakSurveyFormService {
plumeMethodData: { turbineEfficiency: 0, plumeLength: 0, ambientTemperature: 0 },
units: 0,
};
if (settings?.unitsOfMeasure === 'Metric') {
data = this.convertSteamLeakService.convertInputDataImperialToMetric(data);
}
return data;
}
}
49 changes: 29 additions & 20 deletions src/app/calculator/steam/steam-leak/steam-leak-survey-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { Settings } from '../../../shared/models/settings';
import { FacilitySteamLeakData, SteamLeakSurveyData, SteamLeakSurveyInput, SteamLeakSurveyOutput, SteamLeakSurveyResult } from '../../../shared/models/standalone';
import { copyObject } from '../../../shared/helperFunctions';
import { StandaloneService } from '../../standalone.service';
import { ConvertSteamLeakService } from './convert-steam-leak.service';
import { SteamLeakSurveyFormService } from './steam-leak-survey-form/steam-leak-survey-form.service';
@Injectable()
export class SteamLeakSurveyService {

private readonly standaloneService = inject(StandaloneService);
private readonly convertSteamLeakService = inject(ConvertSteamLeakService);
private readonly formService = inject(SteamLeakSurveyFormService);
settings: Settings;

Expand All @@ -29,17 +31,21 @@ export class SteamLeakSurveyService {

initDefaultEmptyInputs(settings: Settings): void {
this.steamLeakInput.set({
steamLeakSurveyInputVec: [this.formService.getEmptySteamLeakData()],
steamLeakSurveyInputVec: [this.formService.getEmptySteamLeakData(settings)],
facilitySteamLeakData: this.getDefaultFacilityData(settings),
});
}

generateExampleData(settings: Settings): void {
this.currentLeakIndex.set(0);
this.steamLeakInput.set({
let example: SteamLeakSurveyInput = {
steamLeakSurveyInputVec: [this.getExampleLeakData()],
facilitySteamLeakData: this.getDefaultFacilityData(settings),
});
};
if (settings.unitsOfMeasure !== 'Imperial') {
example = this.convertSteamLeakService.convertExample(example);
}
this.currentLeakIndex.set(0);
this.steamLeakInput.set(example);
this.resetEventsSubject.next();
}

Expand All @@ -60,7 +66,7 @@ export class SteamLeakSurveyService {
if (this.settings) {
this.initDefaultEmptyInputs(this.settings);
} else {
const emptyLeak = this.formService.getEmptySteamLeakData();
const emptyLeak = this.formService.getEmptySteamLeakData(this.settings);
this.steamLeakInput.set({ ...current, steamLeakSurveyInputVec: [emptyLeak] });
}
this.resetEventsSubject.next();
Expand Down Expand Up @@ -120,8 +126,8 @@ export class SteamLeakSurveyService {
};
}

private getDefaultFacilityData(_settings: Settings): FacilitySteamLeakData {
return {
private getDefaultFacilityData(settings: Settings): FacilitySteamLeakData {
let data: FacilitySteamLeakData = {
annualOperatingHours: 8760,
utilityType: 1,
steamCost: 0,
Expand All @@ -134,12 +140,17 @@ export class SteamLeakSurveyService {
boilerEfficiency: 80,
systemEfficiency: 75,
};
if (settings?.unitsOfMeasure === 'Metric') {
data = this.convertSteamLeakService.convertImperialFacilitySteamLeakData(data);
}
return data;
}

getResults(settings: Settings, input: SteamLeakSurveyInput): SteamLeakSurveyOutput {
const inputCopy: SteamLeakSurveyInput = copyObject(input);

//WK Conversion Spot.
this.convertSteamLeakService.convertInputs(inputCopy.steamLeakSurveyInputVec, settings);
inputCopy.facilitySteamLeakData = this.convertSteamLeakService.convertFacilityInputs(inputCopy.facilitySteamLeakData, settings);

const individualLeaks: Array<SteamLeakSurveyResult> = [];
let cumulativeModifiactionResults: SteamLeakSurveyResult = emptyResult();
Expand All @@ -154,23 +165,21 @@ export class SteamLeakSurveyService {
leakResult.leakDescription = leak.leakDescription;
leakResult.selected = leak.selected;

//WK CONVERSION SPOT
// const convertedResult =
// leak.measurementMethod === LeakMeasurementMethod.
const convertedResult = this.convertSteamLeakService.convertResult(leakResult, settings);

if (!leak?.selected) {
cumulativeModifiactionResults.leakRate += leakResult.leakRate;
cumulativeModifiactionResults.steamLoss += leakResult.steamLoss;
cumulativeModifiactionResults.energyLoss += leakResult.energyLoss;
cumulativeModifiactionResults.leakCost += leakResult.leakCost;
cumulativeModifiactionResults.leakRate += convertedResult.leakRate;
cumulativeModifiactionResults.steamLoss += convertedResult.steamLoss;
cumulativeModifiactionResults.energyLoss += convertedResult.energyLoss;
cumulativeModifiactionResults.leakCost += convertedResult.leakCost;
}

individualLeaks.push(leakResult);
individualLeaks.push(convertedResult);
return {
leakRate: cumulative.leakRate + leakResult.leakRate,
steamLoss: cumulative.steamLoss + leakResult.steamLoss,
energyLoss: cumulative.energyLoss + leakResult.energyLoss,
leakCost: cumulative.leakCost + leakResult.leakCost,
leakRate: cumulative.leakRate + convertedResult.leakRate,
steamLoss: cumulative.steamLoss + convertedResult.steamLoss,
energyLoss: cumulative.energyLoss + convertedResult.energyLoss,
leakCost: cumulative.leakCost + convertedResult.leakCost,
};
},
emptyResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ExportableResultsTableModule } from '../../../shared/exportable-results

import { SteamLeakSurveyComponent } from './steam-leak-survey.component';
import { SteamLeakSurveyService } from './steam-leak-survey-service';
import { ConvertSteamLeakService } from './convert-steam-leak.service';
import { SteamLeakSurveyFormComponent } from './steam-leak-survey-form/steam-leak-survey-form.component';
import { SteamLeakSurveyFormService } from './steam-leak-survey-form/steam-leak-survey-form.service';
import { SteamEstimateMethodFormComponent } from './steam-leak-survey-form/steam-estimate-method-form/steam-estimate-method-form.component';
Expand All @@ -21,7 +22,7 @@ import { SteamLeakSurveyResultsTableComponent } from './steam-leak-survey-result
SteamLeakSurveyFormComponent,
SteamEstimateMethodFormComponent,
SteamOrificeMethodFormComponent,
SteamPlumeMethodFormComponent
SteamPlumeMethodFormComponent,
CostOfSteamFormComponent,
SteamLeakSurveyResultsTableComponent
],
Expand All @@ -35,7 +36,8 @@ import { SteamLeakSurveyResultsTableComponent } from './steam-leak-survey-result
exports: [SteamLeakSurveyComponent],
providers: [
SteamLeakSurveyService,
SteamLeakSurveyFormService
SteamLeakSurveyFormService,
ConvertSteamLeakService
]
})
export class SteamLeakSurveyModule {}