Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 249, 247, 163, 207 #268

Merged
merged 13 commits into from
Oct 9, 2024
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
3 changes: 2 additions & 1 deletion src/app/indexed-db/assessment-idb.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, firstValueFrom } from 'rxjs';
import { IdbAssessment } from '../models/assessment';
import { NgxIndexedDBService } from 'ngx-indexed-db';
import { guidType } from '../shared/constants/guidTypes';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -58,7 +59,7 @@ export class AssessmentIdbService {
return assessments.find(_assessment => { return _assessment.guid == guid });
}

getByOtherGuid(guid: string, idType: string): Array<IdbAssessment> {
getByOtherGuid(guid: string, idType: guidType): Array<IdbAssessment> {
let assessments: Array<IdbAssessment> = this.assessments.getValue();
if (idType == 'company') {
return assessments.filter(_assessment => { return _assessment.companyId == guid });
Expand Down
16 changes: 16 additions & 0 deletions src/app/indexed-db/energy-opportunity-idb.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { IdbEnergyOpportunity } from '../models/energyOpportunity';
import { NgxIndexedDBService } from 'ngx-indexed-db';
import { BehaviorSubject, Observable, firstValueFrom } from 'rxjs';
import { guidType } from '../shared/constants/guidTypes';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -59,4 +60,19 @@ export class EnergyOpportunityIdbService {
return opportunity.guid == guid;
});
}

getByOtherGuid(guid: string, idType: guidType): Array<IdbEnergyOpportunity> {
let energyOpportunities: Array<IdbEnergyOpportunity> = this.energyOpportunities.getValue();
if (idType == 'company') {
return energyOpportunities.filter(opportunity => {
return opportunity.companyId == guid;
});
} else if (idType == 'facility') {
return energyOpportunities.filter(opportunity => {
return opportunity.facilityId == guid;
});
} else {
return [];
}
}
}
15 changes: 15 additions & 0 deletions src/app/indexed-db/facility-idb.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, firstValueFrom } from 'rxjs';
import { IdbFacility, getNewIdbFacility } from '../models/facility';
import { NgxIndexedDBService } from 'ngx-indexed-db';
import { guidType } from '../shared/constants/guidTypes';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -67,4 +68,18 @@ export class FacilityIdbService {
await this.setFacilities();
return newFacility.guid;
}

getByOtherGuid(guid: string, idType: guidType): Array<IdbFacility> {
let facilities: Array<IdbFacility> = this.facilities.getValue();
let _facilities: Array<IdbFacility> = facilities.filter(facility => {
if (idType == 'company') {
return facility.companyId == guid;
} else if (idType == 'user') {
return facility.userId == guid;
} else {
return false;
}
});
return _facilities;
}
}
10 changes: 3 additions & 7 deletions src/app/models/assessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export interface IdbAssessment extends IdbEntry {
assessmentType: AssessmentType,
utilityTypes: Array<UtilityType>, // track all utility types associated with assessment type
utilityEnergyUses: Array<UtilityEnergyUse>, // track all utility energy uses
utilityType: UtilityType,
unitOptionValue: string,
equipmentId: string,
energyUse: number,
cost: number,
Expand All @@ -41,15 +39,13 @@ export function getNewIdbAssessment(userId: string, companyId: string, facilityI
assessmentType: defaultAssessmentType,
utilityTypes: defaultUtilityTypes,
utilityEnergyUses: getDefaultUtilityEnergyUses(facilityUnitSettings),
utilityType: undefined,
unitOptionValue: undefined,
equipmentId: undefined,
energyUse: 0,
cost: 0,
energySavings: undefined,
costSavings: undefined,
energySavings: 0,
costSavings: 0,
notes: undefined,
visitDate: undefined,
implementationCost: undefined
implementationCost: 0
}
}
16 changes: 16 additions & 0 deletions src/app/models/unitSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,50 @@ export interface UnitSettings {
electricityUse: number,
electricityUnit: string,
electricityPrice: number,
electricityHHV: number,
electricityEnergyUnit: string,

includeNaturalGas: boolean,
naturalGasUse: number,
naturalGasUnit: string,
naturalGasPrice: number,
naturalGasHHV: number,
naturalGasEnergyUnit: string,

includeSteam: boolean,
steamUse: number,
steamUnit: string,
steamPrice: number,
steamHHV: number,
steamEnergyUnit: string,

includeWater: boolean,
waterUse: number,
waterUnit: string,
waterPrice: number,
waterHHV: number,
waterEnergyUnit: string,

includeWasteWater: boolean,
wasteWaterUse: number,
wasteWaterUnit: string,
wasteWaterPrice: number,
wasteWaterHHV: number,
wasteWaterEnergyUnit: string,

includeOtherFuels: boolean,
otherFuelsUse: number,
otherFuelsUnit: string,
otherFuelsPrice: number,
otherFuelsHHV: number,
otherFuelsEnergyUnit: string,

includeCompressedAir: boolean,
compressedAirUse: number,
compressedAirUnit: string,
compressedAirPrice: number,
compressedAirHHV: number,
compressedAirEnergyUnit: string,
}

export function getDefaultUnitSettings(): UnitSettings {
Expand All @@ -47,6 +61,8 @@ export function getDefaultUnitSettings(): UnitSettings {
settings[`${camelCaseType}Use`] = 0;
settings[`${camelCaseType}Unit`] = option.energyDefaultUnit.value;
settings[`${camelCaseType}Price`] = 0;
settings[`${camelCaseType}HHV`] = 0;
settings[`${camelCaseType}EnergyUnit`] = 'MMBtu';
return settings;
}, {} as UnitSettings);
// set defaults to include electricity and natural gas
Expand Down
25 changes: 21 additions & 4 deletions src/app/models/utilityEnergyUses.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

import { FacilityIdbService } from "../indexed-db/facility-idb.service";
import { UtilityOptions, UtilityType } from "../shared/constants/utilityTypes";
import { energy } from "../shared/conversions/definitions/energy";
import { getDefaultUnitSettings, UnitSettings } from "./unitSettings";

export interface UtilityEnergyUse {
utilityType: UtilityType;
include: boolean;
energyUse: number;
unit: string;
energyUnit: string;
energyHHV?: number;
energyUnitStandard?: string;
isKnown?: boolean; // TO DO: allow user to enter estimated values
}

export function getDefaultUtilityEnergyUses(facilityUnitSettings: UnitSettings): Array<UtilityEnergyUse> {
Expand All @@ -16,14 +20,27 @@ export function getDefaultUtilityEnergyUses(facilityUnitSettings: UnitSettings):
const camelCaseType = utilityType.charAt(0).toLowerCase()
+ utilityType.slice(1);
let energyUnit = option.energyDefaultUnit.value;
if (facilityUnitSettings[`${camelCaseType}Unit`] && facilityUnitSettings[`include${utilityType}`]) {
energyUnit = facilityUnitSettings[`${camelCaseType}Unit`];
let energyHHV = 0;
let energyUnitStandard = 'MMBtu';
if (facilityUnitSettings[`include${utilityType}`]) {
if (facilityUnitSettings[`${camelCaseType}Unit`]) {
energyUnit = facilityUnitSettings[`${camelCaseType}Unit`];
}
if (facilityUnitSettings[`${camelCaseType}HHV`]) {
energyHHV = facilityUnitSettings[`${camelCaseType}HHV`];
}
if (facilityUnitSettings[`${camelCaseType}EnergyUnit`]) {
energyUnitStandard = facilityUnitSettings[`${camelCaseType}EnergyUnit`];
}
}
return {
utilityType: option.utilityType,
include: false,
energyUnitStandard: energyUnitStandard,
energyHHV: energyHHV,
energyUse: 0,
unit: energyUnit
energyUnit: energyUnit,
isKnown: true
};
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.disabled-input-label{
background-color: white;
border: none;
border-left: var(--bs-border-width) solid var(--bs-border-color);
}

.utility-row:hover, .utility-row:hover .disabled-input-label {
background-color: #efefef;
}

.disabled-input-label-secondary{
background-color: white;
border: none;
margin-left: 28px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,107 @@
</div>
</div>

<div class="row">
<label class="col-sm-5 col-form-label" for="utilityType">Utility Type</label>
<div class="col-sm-7">

<select name="utilityType" class="form-select"
id="utilityType"
[(ngModel)]="assessment.utilityType"
(change)="utilityTypeChange()">
<option
*ngFor="let utilityType of assessment.utilityTypes"
[ngValue]="utilityType">
{{utilityType}}
</option>
</select>

<hr>
<h6>Utility Types</h6>
<p class="fw-light">Select the utility types that are
applicable to this assessment and enter the annual energy
use for each type.</p>
<ng-container *ngFor="let use of assessment.utilityEnergyUses">
<div class="row mb-1 utility-row"
*ngIf="assessment.utilityTypes.includes(use.utilityType)">
<div class="col-4">
<div class="input-group">
<div class="input-group-text">
<input class="form-check-input" type="checkbox"
name="{{'include_utilityType_' + use.utilityType + assessment.guid}}"
id="{{'include_utilityType_' + use.utilityType + assessment.guid}}"
[(ngModel)]="use.include"
(change)="calculateEnergyUseCost()">
</div>
<input type="text"
class="form-control disabled-input-label"
[value]="use.utilityType" [disabled]="true">
</div>
</div>
<ng-container *ngIf="use.include">
<div class="col-8">
<div class="form-group row align-items-center">
<div class="input-group">
<input type="number" class="form-control"
name="{{'energyUse_' + use.utilityType + assessment.guid}}"
id="{{'energyUse_' + use.utilityType + assessment.guid}}"
[(ngModel)]="use.energyUse"
(input)="calculateEnergyUseCost()">
<select class="input-group-text"
name="{{'energyUnit_' + use.utilityType + assessment.guid}}"
id="{{'energyUnit_' + use.utilityType + assessment.guid}}"
[(ngModel)]="use.energyUnit"
(change)="calculateEnergyUseCost()">
<option
*ngFor="let unitOption of (use.utilityType | linkedUnitOptions: 'Energy')"
[ngValue]="unitOption.value">
<span
[innerHTML]="unitOption.value | unitsDisplay"></span>
</option>
</select>
</div>
</div>
</div>
</ng-container>
<ng-container *ngIf="use.include
&& !(use.utilityType | isStandardUnit :use.energyUnit : 'Energy')">
<div class="col-4">
<div class="input-group">
<input type="text" class="disabled-input-label-secondary" [disabled]="true"
value="{{use.utilityType | utilityHhvDisplay}}">
</div>
</div>
<div class="col-8">
<div class="input-group">
<input class="form-control" type="number" step="any" min="0"
name="{{'energyHHV_' + use.utilityType + assessment.guid}}"
id="{{'energyHHV_' + use.utilityType + assessment.guid}}"
[(ngModel)]="use.energyHHV"
(change)="calculateEnergyUseCost()">
<select class="input-group-text"
name="{{'energyUnitStandard_' + use.utilityType + assessment.guid}}"
id="{{'energyUnitStandard_' + use.utilityType + assessment.guid}}"
[(ngModel)]="use.energyUnitStandard"
(change)="calculateEnergyUseCost()">
<option *ngFor="let energyUnitOption of energyUnitOptions"
[ngValue]="energyUnitOption.value">
<span [innerHTML]="energyUnitOption.value | unitsDisplay">
</span>/<span [innerHTML]="use.energyUnit| unitsDisplay">
</span>
</option>
</select>
</div>
</div>
</ng-container>
</div>
</div>
</ng-container>
<hr>

<div class="row">
<label class="col-sm-5 col-form-label" for="energyUse">Annual Energy
Use</label>
<div class="col-sm-7">
<div class="input-group">
<input name="energy" type="number" class="form-control" [(ngModel)]="assessment.energyUse"
(input)="saveChanges()" id="energyUse">
<select name="energyUnit" class="input-group-text" id="energyUnit" name="energyUnit"
[(ngModel)]="assessment.unitOptionValue"
(change)="saveChanges()">
<option *ngFor="let unitOption of (assessment.utilityType | linkedUnitOptions: 'Energy')"
[ngValue]="unitOption.value">
<span [innerHTML]="unitOption.value | unitsDisplay"></span>
</option>
</select>
<div class="col-sm-7" id="{{'energyUse_'+assessment.guid}}">
{{assessment.energyUse | number:'1.0-2'}}&nbsp;
<span [innerHTML]="companyEnergyUnit | unitsDisplay">
</span>
</div>
</div>
</div>
</div>

<div class="row">
<label class="col-sm-5 col-form-label" for="cost">Annual
<label class="col-sm-5 col-form-label"
for="{{'cost_'+assessment.guid}}">Annual
Costs</label>
<div class="col-sm-7">
<div class="input-group">
<input name="cost" type="number" class="form-control" [(ngModel)]="assessment.cost"
(input)="saveChanges()" id="cost">
<span class="input-group-text">&dollar;</span>
</div>
<div class="col-sm-7" id="{{'cost_'+assessment.guid}}">
{{assessment.cost | currency:'USD':'symbol':'1.0-2'}}
</div>
</div>

Expand Down Expand Up @@ -95,7 +150,7 @@
<div class="input-group">
<input name="energySavings" type="number" class="form-control" [(ngModel)]="assessment.energySavings"
(input)="saveChanges()" id="energySavings">
<span class="input-group-text">MMBtu/yr</span>
<span class="input-group-text" [innerHTML]="(companyEnergyUnit | unitsDisplay) + '/yr'"></span>
</div>
</div>
</div>
Expand Down
Loading
Loading