Skip to content

Commit

Permalink
Merge pull request #243 from NREL/issue-205
Browse files Browse the repository at this point in the history
Enhanced KPM Calculations
  • Loading branch information
RLiNREL authored Sep 24, 2024
2 parents 0463c8d + 35bcae8 commit badc52d
Show file tree
Hide file tree
Showing 19 changed files with 547 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export class KeyPerformanceMetricImpactsIdbService {
let companyMetricImpacts: Array<IdbKeyPerformanceMetricImpact> = this.getByKpiGuid(keyPerformanceIndicator.guid);
for (let i = 0; i < companyMetricImpacts.length; i++) {
let metricImpact: IdbKeyPerformanceMetricImpact = companyMetricImpacts[i];
metricImpact.costAdjustment = (metricImpact.modificationValue * keyPerformanceMetric.costPerValue);
if (keyPerformanceMetric.calculationMethod == 'costPerUnit') {
metricImpact.costAdjustment = (metricImpact.modificationValue * keyPerformanceMetric.costPerValue);
} else if (keyPerformanceMetric.calculationMethod == 'percentTotal') {
metricImpact.costAdjustment = keyPerformanceMetric.baselineCost * (metricImpact.modificationValue / 100);
}
await firstValueFrom(this.updateWithObservable(metricImpact));
}
await this.setKeyPerformanceMetricImpacts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class AssessmentNebsFormComponent {

toggleAddNebDropdown() {
this.showAddNebDropdown = !this.showAddNebDropdown;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,75 +56,54 @@

<ng-template [ngIf]="keyPerformanceMetric.isQuantitative" [ngIfElse]="qualitativeMetricBlock">
<div class="form-block">
<app-kpm-details-form [keyPerformanceMetric]="keyPerformanceMetric"
[disableForm]="(metricHasOtherImpacts && !overrideBaseline)" (emitSave)="saveChanges()"
(emitCalculate)="calculateCost()"></app-kpm-details-form>
<div class="row">
<label class="col-sm-6 col-form-label pm-label" for="baselineValue">
Baseline Amount
</label>
<div class="col-6">
<div class="input-group">
<input type="number" class="form-control" [(ngModel)]="keyPerformanceMetric.baselineValue"
name="baselineValue" (input)="calculateBaseline()"
[disabled]="(metricHasOtherImpacts && !overrideBaseline)">
<span class="input-group-text">
<span [innerHTML]="keyPerformanceMetric.totalUnit | unitsDisplay"></span>/yr
</span>
</div>
</div>
</div>

<div class="row">
<label class="col-sm-6 col-form-label pm-label" for="costPerValue">
Cost Per Unit
<label class="col-sm-6 col-form-label" for="modificationValue">
Impact on KPM
</label>
<div class="col-6">
<div class="input-group">
<input type="number" class="form-control" [(ngModel)]="keyPerformanceMetric.costPerValue"
name="costPerValue" (input)="calculateBaseline()"
[disabled]="(metricHasOtherImpacts && !overrideBaseline)">
<span class="input-group-text">
&dollar;/<span [innerHTML]="keyPerformanceMetric.totalUnit | unitsDisplay"></span>
<ng-template [ngIf]="keyPerformanceMetric.goalToIncrease" [ngIfElse]="minusBlock">
&plus;
</ng-template>
<ng-template #minusBlock>
&minus;
</ng-template>
</span>
</div>
</div>
</div>

<div class="row">
<label class="col-sm-6 col-form-label pm-label" for="costPerValue">
Baseline Cost
</label>
<div class="col-6">
<ng-template [ngIf]="keyPerformanceMetric.baselineCost" [ngIfElse]="noCostBlock">
{{keyPerformanceMetric.baselineCost | currency}}/yr
</ng-template>
<ng-template #noCostBlock>
&mdash;
</ng-template>
</div>
</div>

<div class="row">
<label class="col-sm-6 col-form-label pm-label" for="modificationValue">
Impact on KPM
</label>
<div class="col-6">
<div class="input-group">
<input type="number" class="form-control"
[(ngModel)]="keyPerformanceMetricImpact.modificationValue" name="modificationValue"
(input)="calculateCost()">
<span class="input-group-text">
<span [innerHTML]="keyPerformanceMetric.totalUnit | unitsDisplay"></span>/yr
<ng-template [ngIf]="keyPerformanceMetric.calculationMethod == 'costPerUnit'">
<span [innerHTML]="keyPerformanceMetric.totalUnit | unitsDisplay"></span>/yr
</ng-template>
<ng-template [ngIf]="keyPerformanceMetric.calculationMethod == 'directCost'">
&dollar;/yr
</ng-template>
<ng-template [ngIf]="keyPerformanceMetric.calculationMethod == 'percentTotal'">
&percnt;
</ng-template>
</span>
</div>
</div>
</div>

<div class="row">
<label class="col-sm-6 col-form-label pm-label" for="costPerValue">
<div class="row" *ngIf="keyPerformanceMetric.calculationMethod != 'directCost'">
<label class="col-sm-6 col-form-label" for="costPerValue">
Financial Impact
</label>
<div class="col-6">
<ng-template [ngIf]="keyPerformanceMetricImpact.costAdjustment"
[ngIfElse]="noCostAdjustmentBlock">
<ng-template [ngIf]="keyPerformanceMetric.goalToIncrease" [ngIfElse]="minusBlock">
&plus;
</ng-template>
<ng-template #minusBlock>
&minus;
</ng-template>
{{keyPerformanceMetricImpact.costAdjustment | currency}}/yr
</ng-template>
<ng-template #noCostAdjustmentBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getNewIdbKeyPerformanceMetricImpact, IdbKeyPerformanceMetricImpact } fr
import { PrimaryKpiBadgeModule } from 'src/app/shared/primary-kpi-badge/primary-kpi-badge.module';
import { HelperPipesModule } from 'src/app/shared/helper-pipes/helper-pipes.module';
import { FormsModule } from '@angular/forms';
import { KpmDetailsFormModule } from 'src/app/shared/kpm-details-form/kpm-details-form.module';

describe('PerformanceMetricImpactFormComponent', () => {
let component: PerformanceMetricImpactFormComponent;
Expand All @@ -24,18 +25,22 @@ describe('PerformanceMetricImpactFormComponent', () => {
let keyPerformanceIndicatorIdbService: Partial<KeyPerformanceIndicatorsIdbService> = {
getKeyPerformanceMetric: () => {
return {
baselineValue: 0,
costPerValue: 0,
baselineCost: 0,
isCustom: false,
kpiGuid: '',
guid: '',
label: '',
htmlLabel: '',
value: 'TRIR',
label: 'Custom KPM',
htmlLabel: 'Custom KPM',
value: 'custom',
kpiValue: 'other',
isQuantitative: true,
}
isQuantitative: true,
baselineValue: undefined,
costPerValue: undefined,
totalUnit: 'unit',
baselineCost: undefined,
isCustom: true,
kpiGuid: '',
guid: '',
calculationMethod: 'costPerUnit',
goalToIncrease: true,
timePeriod: 'yr'
};
}
};

Expand All @@ -47,7 +52,7 @@ describe('PerformanceMetricImpactFormComponent', () => {
};
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FontAwesomeModule, PrimaryKpiBadgeModule, HelperPipesModule, FormsModule],
imports: [FontAwesomeModule, PrimaryKpiBadgeModule, HelperPipesModule, FormsModule, KpmDetailsFormModule],
declarations: [PerformanceMetricImpactFormComponent],
providers: [
{ provide: OnSiteVisitIdbService, useValue: onSiteVisitIdbService },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export class PerformanceMetricImpactFormComponent {
}

calculateCost() {
this.keyPerformanceMetricImpact.costAdjustment = (this.keyPerformanceMetricImpact.modificationValue * this.keyPerformanceMetric.costPerValue);
if (this.keyPerformanceMetric.calculationMethod == 'costPerUnit') {
this.keyPerformanceMetricImpact.costAdjustment = (this.keyPerformanceMetricImpact.modificationValue * this.keyPerformanceMetric.costPerValue);
} else if (this.keyPerformanceMetric.calculationMethod == 'percentTotal') {
this.keyPerformanceMetricImpact.costAdjustment = this.keyPerformanceMetric.baselineCost * (this.keyPerformanceMetricImpact.modificationValue / 100);
}
this.saveChanges();
}

Expand Down Expand Up @@ -117,6 +121,7 @@ export class PerformanceMetricImpactFormComponent {
openDeleteModal() {
this.showDropdownMenu = false;
this.displayDeleteModal = true;
this.showDropdownMenu = false;
}

closeDeleteModal() {
Expand All @@ -131,9 +136,14 @@ export class PerformanceMetricImpactFormComponent {
setOverrideBaseline(overrideBaseline: boolean) {
this.showDropdownMenu = false;
this.overrideBaseline = overrideBaseline;
this.showDropdownMenu = false;
}

toggleDropdownMenu() {
this.showDropdownMenu = !this.showDropdownMenu;
}

toggleShowDropdownMenu(){
toggleShowDropdownMenu() {
this.showDropdownMenu = !this.showDropdownMenu;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.pm-label{
padding-left: 2.5rem;
}

.form-block{
border-left: solid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ <h6>
<div class="metric-block">
<div class="dropdown">
<button class="btn btn-outline-metric btn-sm dropdown-toggle" type="button"
data-bs-toggle="dropdown" aria-expanded="false" (click)="setDropdownMenuGuid(keyPerformanceMetric.guid)">
data-bs-toggle="dropdown" aria-expanded="false"
(click)="setDropdownMenuGuid(keyPerformanceMetric.guid)">
<fa-icon [icon]="faScaleUnbalancedFlip" class="me-2"></fa-icon>
<span [innerHTML]="keyPerformanceMetric.htmlLabel"></span>
</button>
<ul class="dropdown-menu" [ngClass]="{'show': dropdownMenuGuid == keyPerformanceMetric.guid}">
<ul class="dropdown-menu"
[ngClass]="{'show': dropdownMenuGuid == keyPerformanceMetric.guid}">
<li>
<a class="dropdown-item"
(click)="openDeleteMetricModal(keyPerformanceMetric)">
Expand All @@ -134,11 +136,9 @@ <h6>
</li>
</ul>
</div>


<ng-template [ngIf]="keyPerformanceMetric.isCustom">
<div class="row">
<label class="col-sm-6 col-form-label pm-label"
<label class="col-sm-6 col-form-label"
for="{{'kpmName_'+keyPerformanceMetric.guid}}">
Performance Metric Name
</label>
Expand All @@ -155,85 +155,15 @@ <h6>
</div>
</div>
</ng-template>

<div class="row" *ngIf="keyPerformanceMetric.totalUnit">
<label class="col-sm-6 col-form-label pm-label"
for="{{'isQuantitative_'+keyPerformanceMetric.value}}">
Metric Type
</label>
<div class="col-6">
<select id="{{'isQuantitative_'+keyPerformanceMetric.value}}"
name="{{'isQuantitative_'+keyPerformanceMetric.value}}" class="form-select"
[(ngModel)]="keyPerformanceMetric.isQuantitative" (change)="saveChanges()">
<option [ngValue]="true">Quantitative</option>
<option [ngValue]="false">Qualitative</option>
</select>
</div>
</div>
<ng-template [ngIf]="keyPerformanceMetric.isQuantitative">
<div class="row">
<label class="col-sm-6 col-form-label pm-label"
for="{{'baselineValue_'+keyPerformanceMetric.value}}">
Baseline Amount
</label>
<div class="col-6">
<div class="input-group">
<input type="number" class="form-control"
[(ngModel)]="keyPerformanceMetric.baselineValue"
name="{{'baselineValue_'+keyPerformanceMetric.value}}"
(input)="calculateCost(keyPerformanceMetric)">
<span class="input-group-text">
<span
[innerHTML]="keyPerformanceMetric.totalUnit | unitsDisplay"></span>/yr
</span>
</div>
</div>
</div>

<div class="row">
<label class="col-sm-6 col-form-label pm-label"
for="{{'costPerValue_'+keyPerformanceMetric.value}}">
Cost Per Unit
</label>
<div class="col-6">
<div class="input-group">
<input type="number" class="form-control"
[(ngModel)]="keyPerformanceMetric.costPerValue"
name="{{'costPerValue_'+keyPerformanceMetric.value}}"
(input)="calculateCost(keyPerformanceMetric)">
<span class="input-group-text">
&dollar;/<span
[innerHTML]="keyPerformanceMetric.totalUnit | unitsDisplay"></span>
</span>
</div>
</div>
</div>

<div class="row">
<label class="col-sm-6 col-form-label pm-label"
for="{{'baselineCost_'+keyPerformanceMetric.value}}">
Baseline Cost
</label>
<div class="col-6">
<ng-template [ngIf]="keyPerformanceMetric.baselineCost"
[ngIfElse]="noCostBlock">
{{keyPerformanceMetric.baselineCost | currency}}/yr
</ng-template>
<ng-template #noCostBlock>
&mdash;
</ng-template>
</div>
</div>
</ng-template>
<ng-template [ngIf]="!keyPerformanceMetric.totalUnit">
<div class="alert alert-info small mt-2">
Quantitative results unavailable at this time.
</div>
</ng-template>
<app-kpm-details-form [keyPerformanceMetric]="keyPerformanceMetric"
(emitSave)="saveChanges()"
(emitCalculate)="calculateCost(keyPerformanceMetric)"></app-kpm-details-form>
<ng-template
[ngIf]="(keyPerformanceMetricImpacts | keyPerformanceMetricImpactsList: keyPerformanceMetric.guid).length">
<app-kpm-impacts-table
[kpmGuid]="keyPerformanceMetric.guid"></app-kpm-impacts-table>
<div class="mt-3">
<app-kpm-impacts-table
[kpmGuid]="keyPerformanceMetric.guid"></app-kpm-impacts-table>
</div>
</ng-template>
<div class="row">
<div class="col">
Expand Down
Loading

0 comments on commit badc52d

Please sign in to comment.