Skip to content

Commit

Permalink
Merge pull request #909 from ORNL-AMO/result-settings-bug
Browse files Browse the repository at this point in the history
bug fix for results settings addition
  • Loading branch information
pshires authored Nov 21, 2017
2 parents 73dce1d + 48c525c commit ae2cdc0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 25 deletions.
16 changes: 14 additions & 2 deletions src/app/phast/phast-report/phast-report.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IndexedDbService } from '../../indexedDb/indexed-db.service';
import { Directory } from '../../shared/models/directory';
import { ReportRollupService } from '../../report-rollup/report-rollup.service';
import { WindowRefService } from '../../indexedDb/window-ref.service';
import { SettingsService } from '../../settings/settings.service';

@Component({
selector: 'app-phast-report',
Expand All @@ -25,14 +26,19 @@ export class PhastReportComponent implements OnInit {
assessment: Assessment;
@Input()
inRollup: boolean;

currentTab: string = 'energy-used';
assessmentDirectories: Array<Directory>;
createdDate: Date;
constructor(private phastService: PhastService, private indexedDbService: IndexedDbService, private reportRollupService: ReportRollupService, private windowRefService: WindowRefService) { }
constructor(private phastService: PhastService, private indexedDbService: IndexedDbService, private reportRollupService: ReportRollupService, private windowRefService: WindowRefService, private settingsService: SettingsService) { }

ngOnInit() {
this.createdDate = new Date();
if(this.settings){
if (!this.settings.energyResultUnit) {
this.settings = this.settingsService.setEnergyResultUnitSetting(this.settings);
}
}
if (this.assessment.phast && this.settings && !this.phast) {
this.phast = this.assessment.phast;
} else if (this.assessment.phast && !this.settings) {
Expand Down Expand Up @@ -60,6 +66,9 @@ export class PhastReportComponent implements OnInit {
getSettings() {
this.indexedDbService.getAssessmentSettings(this.assessment.id).then(results => {
if (results.length != 0) {
if (!results[0].energyResultUnit) {
results[0] = this.settingsService.setEnergyResultUnitSetting(results[0]);
}
this.settings = results[0];
} else {
this.getParentDirectorySettings(this.assessment.directoryId);
Expand All @@ -72,6 +81,9 @@ export class PhastReportComponent implements OnInit {
this.indexedDbService.getDirectorySettings(dirId).then(
resultSettings => {
if (resultSettings.length != 0) {
if (resultSettings[0].energyResultUnit) {
resultSettings[0] = this.settingsService.setEnergyResultUnitSetting(resultSettings[0]);
}
this.settings = resultSettings[0];
} else {
this.indexedDbService.getDirectory(dirId).then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export class PhastPieChartComponent implements OnInit {
} else {
this.phastReportService.modificationChartLabels.next(this.chartData.pieChartLabels);
}
console.log(this.chartData.pieChartLabels);
}

getLossPercent(totalLosses: number, loss: number): number {
Expand Down
55 changes: 36 additions & 19 deletions src/app/phast/phast-results.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { PhastService } from './phast.service';
import { Settings } from '../shared/models/settings';
import { AuxEquipmentService } from './aux-equipment/aux-equipment.service';
import { ConvertUnitsService } from '../shared/convert-units/convert-units.service';
import { FlueGasLossesService } from './losses/flue-gas-losses/flue-gas-losses.service';
import { EnergyInputExhaustGasService } from './losses/energy-input-exhaust-gas-losses/energy-input-exhaust-gas.service';
import { EnergyInputService } from './losses/energy-input/energy-input.service';


@Injectable()
export class PhastResultsService {

constructor(private phastService: PhastService, private auxEquipmentService: AuxEquipmentService, private convertUnitsService: ConvertUnitsService) { }
constructor(private phastService: PhastService, private auxEquipmentService: AuxEquipmentService, private convertUnitsService: ConvertUnitsService, private flueGasLossesService: FlueGasLossesService, private energyInputExhaustGasService: EnergyInputExhaustGasService, private energyInputService: EnergyInputService) { }
checkLoss(loss: any) {
if (!loss) {
return false;
Expand Down Expand Up @@ -100,17 +105,23 @@ export class PhastResultsService {


if (resultCats.showEnInput1 && this.checkLoss(phast.losses.energyInputEAF)) {
let tmpResults = this.phastService.energyInputEAF(phast.losses.energyInputEAF[0], settings);
results.energyInputTotalChemEnergy = tmpResults.totalChemicalEnergyInput;
results.energyInputHeatDelivered = tmpResults.heatDelivered;
let tmpForm = this.energyInputService.getFormFromLoss(phast.losses.energyInputEAF[0]);
if (tmpForm.status == 'VALID') {
let tmpResults = this.phastService.energyInputEAF(phast.losses.energyInputEAF[0], settings);
results.energyInputTotalChemEnergy = tmpResults.totalChemicalEnergyInput;
results.energyInputHeatDelivered = tmpResults.heatDelivered;
}
}

if (resultCats.showEnInput2 && this.checkLoss(phast.losses.energyInputExhaustGasLoss)) {
let tmpResults = this.phastService.energyInputExhaustGasLosses(phast.losses.energyInputExhaustGasLoss[0], settings)
results.energyInputHeatDelivered = tmpResults.heatDelivered;
results.totalExhaustGas = tmpResults.exhaustGasLosses;
results.grossHeatInput = results.totalInput - results.exothermicHeat;
results.availableHeatPercent = this.phastService.availableHeat(phast.losses.energyInputExhaustGasLoss[0], settings);
let tmpForm = this.energyInputExhaustGasService.getFormFromLoss(phast.losses.energyInputExhaustGasLoss[0]);
if (tmpForm.status == 'VALID') {
let tmpResults = this.phastService.energyInputExhaustGasLosses(phast.losses.energyInputExhaustGasLoss[0], settings)
results.energyInputHeatDelivered = tmpResults.heatDelivered;
results.totalExhaustGas = tmpResults.exhaustGasLosses;
results.grossHeatInput = results.totalInput - results.exothermicHeat;
results.availableHeatPercent = this.phastService.availableHeat(phast.losses.energyInputExhaustGasLoss[0], settings);
}
}

if (phast.systemEfficiency && resultCats.showSystemEff) {
Expand All @@ -124,17 +135,23 @@ export class PhastResultsService {
let tmpFlueGas = phast.losses.flueGasLosses[0];
if (tmpFlueGas) {
if (tmpFlueGas.flueGasType == 'By Mass') {
let tmpVal = this.phastService.flueGasByMass(tmpFlueGas.flueGasByMass, settings);
results.flueGasAvailableHeat = tmpVal * 100;
results.flueGasGrossHeat = (results.totalInput / tmpVal);
results.flueGasSystemLosses = results.flueGasGrossHeat * (1 - tmpVal);
results.totalFlueGas = results.flueGasSystemLosses;
let tmpForm = this.flueGasLossesService.initByMassFormFromLoss(tmpFlueGas);
if (tmpForm.status == 'VALID') {
let tmpVal = this.phastService.flueGasByMass(tmpFlueGas.flueGasByMass, settings);
results.flueGasAvailableHeat = tmpVal * 100;
results.flueGasGrossHeat = (results.totalInput / tmpVal);
results.flueGasSystemLosses = results.flueGasGrossHeat * (1 - tmpVal);
results.totalFlueGas = results.flueGasSystemLosses;
}
} else if (tmpFlueGas.flueGasType == 'By Volume') {
let tmpVal = this.phastService.flueGasByVolume(tmpFlueGas.flueGasByVolume, settings);
results.flueGasAvailableHeat = tmpVal * 100;
results.flueGasGrossHeat = (results.totalInput / tmpVal);
results.flueGasSystemLosses = results.flueGasGrossHeat * (1 - tmpVal);
results.totalFlueGas = results.flueGasSystemLosses;
let tmpForm = this.flueGasLossesService.initByVolumeFormFromLoss(tmpFlueGas);
if (tmpForm.status == 'VALID') {
let tmpVal = this.phastService.flueGasByVolume(tmpFlueGas.flueGasByVolume, settings);
results.flueGasAvailableHeat = tmpVal * 100;
results.flueGasGrossHeat = (results.totalInput / tmpVal);
results.flueGasSystemLosses = results.flueGasGrossHeat * (1 - tmpVal);
results.totalFlueGas = results.flueGasSystemLosses;
}
}
results.grossHeatInput = results.totalInput + results.flueGasSystemLosses - results.exothermicHeat;
}
Expand Down
16 changes: 15 additions & 1 deletion src/app/report-rollup/report-rollup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { PhastResultsService } from '../phast/phast-results.service';
import { ExecutiveSummaryService } from '../phast/phast-report/executive-summary.service';
import * as _ from 'lodash';
import { PsatService } from '../psat/psat.service';
import { SettingsService } from '../settings/settings.service';
import { Settings } from '../shared/models/settings';


@Injectable()
export class ReportRollupService {
Expand All @@ -29,7 +32,7 @@ export class ReportRollupService {
phastResults: BehaviorSubject<Array<PhastResultsData>>;
allPhastResults: BehaviorSubject<Array<AllPhastResultsData>>;

constructor(private indexedDbService: IndexedDbService, private psatService: PsatService, private phastResultsService: PhastResultsService, private executiveSummaryService: ExecutiveSummaryService) {
constructor(private indexedDbService: IndexedDbService, private psatService: PsatService, private executiveSummaryService: ExecutiveSummaryService, private settingsService: SettingsService) {
this.initSummary();
}

Expand Down Expand Up @@ -128,6 +131,7 @@ export class ReportRollupService {
psatArr.forEach(val => {
if (val.psat.setupDone && (val.psat.modifications.length != 0)) {
this.indexedDbService.getAssessmentSettings(val.id).then(settings => {
settings[0] = this.checkSettings(settings[0]);
let baselineResults = this.psatService.resultsExisting(JSON.parse(JSON.stringify(val.psat.inputs)), settings[0]);
let modResultsArr = new Array<PsatOutputs>();
val.psat.modifications.forEach(mod => {
Expand All @@ -150,6 +154,7 @@ export class ReportRollupService {
let tmpResultsArr = new Array<PsatResultsData>();
selectedPsats.forEach(val => {
this.indexedDbService.getAssessmentSettings(val.assessmentId).then(settings => {
settings[0] = this.checkSettings(settings[0]);
let modificationResults;
let baselineResults = this.psatService.resultsExisting(JSON.parse(JSON.stringify(val.baseline.inputs)), settings[0]);
if (val.modification.inputs.optimize_calculation) {
Expand Down Expand Up @@ -194,6 +199,7 @@ export class ReportRollupService {
if (val.phast.setupDone && val.phast.modifications) {
if (val.phast.modifications.length != 1) {
this.indexedDbService.getAssessmentSettings(val.id).then(settings => {
settings[0] = this.checkSettings(settings[0]);
let baselineResults = this.executiveSummaryService.getSummary(val.phast, false, settings[0], val.phast)
let modResultsArr = new Array<ExecutiveSummary>();
val.phast.modifications.forEach(mod => {
Expand All @@ -212,6 +218,7 @@ export class ReportRollupService {
let tmpResultsArr = new Array<PhastResultsData>();
selectedPhasts.forEach(val => {
this.indexedDbService.getAssessmentSettings(val.assessmentId).then(settings => {
settings[0] = this.checkSettings(settings[0]);
let baselineResults = this.executiveSummaryService.getSummary(val.baseline, false, settings[0], val.baseline);
let modificationResults = this.executiveSummaryService.getSummary(val.modification, true, settings[0], val.baseline, baselineResults);
tmpResultsArr.push({ baselineResults: baselineResults, modificationResults: modificationResults, assessmentId: val.assessmentId });
Expand All @@ -220,6 +227,13 @@ export class ReportRollupService {
})
}

checkSettings(settings: Settings){
if(!settings.energyResultUnit){
settings = this.settingsService.setEnergyResultUnitSetting(settings);
}
return settings;
}

}

export interface PsatCompare {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component, OnInit, Input } from '@angular/core';
import { Assessment } from '../../../shared/models/assessment';
import { ReportRollupService, PsatCompare, PhastResultsData } from '../../report-rollup.service';
import * as _ from 'lodash';
import { PsatService } from '../../../psat/psat.service';
import { IndexedDbService } from '../../../indexedDb/indexed-db.service';

@Component({
Expand All @@ -16,7 +15,7 @@ export class PhastSummaryComponent implements OnInit {
energySavingsPotential: number = 0;
totalCost: number = 0;
totalEnergy: number = 0;
constructor(private reportRollupService: ReportRollupService, private indexedDbService: IndexedDbService, private psatService: PsatService) { }
constructor(private reportRollupService: ReportRollupService, private indexedDbService: IndexedDbService) { }

ngOnInit() {
this.reportRollupService.phastAssessments.subscribe(val => {
Expand Down

0 comments on commit ae2cdc0

Please sign in to comment.