Skip to content

Commit

Permalink
fixed total carbon footprint calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Curiosit committed Mar 29, 2024
1 parent 3800b7a commit e3ac35e
Show file tree
Hide file tree
Showing 5 changed files with 605 additions and 23 deletions.
157 changes: 145 additions & 12 deletions src/bim-components/CarbonTool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
components.scene
this._qtoResultByElementName = {}
this._qtoResult = {}

this.callback = this.callback.bind(this);
this.sumGWP = this.sumGWP.bind(this);

this.setUI()
//this.getQuantities()

Expand Down Expand Up @@ -155,6 +159,9 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement

carbonWindowBtn.active = !carbonWindowBtn.active
carbonWindow.visible = carbonWindowBtn.active
if(carbonWindow.visible) {

}

console.log(carbonWindowBtn.active)
console.log(carbonWindow.visible)
Expand Down Expand Up @@ -201,6 +208,51 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
}) */


}
callback() {
console.log("Calling back from card")
this.sumGWP()

}

sumGWP() {
// Initialize the total sum of GWP (Global Warming Potential)
let totalGWP = 0;

// Iterate through each ElementCard in the elementCardList
this.elementCardList.forEach((elementCard) => {
// Check if the elementData and 'CF values' exist to avoid runtime errors
if (elementCard.elementData && elementCard.elementData['CF values']) {
// Access the 'Carbon Footprint' value and add it to the totalGWP
const carbonFootprint = elementCard.elementData['CF values']['Carbon Footprint'];
if (typeof carbonFootprint === 'number') {
totalGWP += carbonFootprint;
}
}
});

// Optionally, you can log or perform further actions with the totalGWP
console.log(`Total Carbon Footprint: ${totalGWP} kg CO2eq`);

// Return the total GWP if needed




const resultsWindow = this.uiElement.get("carbonWindow")
if(this.resultsCard) {
this.resultsCard.removeFromParent()
}
const resultsCard = new ResultsCard(this.components)
this.resultsCard = resultsCard

resultsCard.totalResult = totalGWP

resultsWindow.addChild(resultsCard)



return totalGWP;
}
async updateUI () {
const qtoList = this.uiElement.get("qtoWindow")
Expand All @@ -210,7 +262,8 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
for (const elementName in this._qtoResultByElementName) {
console.log(this._qtoResultByElementName[elementName])

const elementCard = new ElementCard(this.components, this.epdxData, this.constructionComponents);
const elementCard = new ElementCard(this.components, this.epdxData, this.constructionComponents, this.callback);
//elementCard.callback = this.callback()
elementCard.data = this._qtoResultByElementName[elementName]
elementCard.elementName = elementName
console.log(this.materialForm)
Expand Down Expand Up @@ -244,6 +297,8 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
console.log(elementData)
console.log("UPDATING RESULTS")
resultsCard.resultData=elementData
console.log(elementData)
console.log(resultsCard.totalResult)
resultsWindow.addChild(resultsCard)
}
resetWindow() {
Expand Down Expand Up @@ -364,7 +419,7 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
idMap = []
//console.log("________________________________________________________________________")
//console.log(elementID)
//console.log(elements[elementID])
console.log(elements[elementID])
const name = properties[elements[elementID].expressID].Name.value

let nameValue
Expand All @@ -383,24 +438,90 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
//console.log(qtoResultByElementName[nameWithID])
//console.log("________________________________________________________________________")

//console.log(resultRow)
console.log(resultRow)
OBC.IfcPropertiesUtils.getRelationMap(
properties,
WEBIFC.IFCRELDEFINESBYPROPERTIES,
(setID, relatedIDs) => {
//console.log("GET RELATION MAP")

const set = properties[setID]
if ( set.type !== WEBIFC.IFCELEMENTQUANTITY) { return}
//console.log(setID)
//console.log(set)
//console.log(relatedIDs)
/* if ( set.type !== WEBIFC.IFCELEMENTQUANTITY) { return} */

// PROPERTYSETSINGLEVALUE DIMENSIONS (PANELS)
if(elementType == 'curtainPanels') {

console.log("PANELS")
if ( set.type == WEBIFC.IFCPROPERTYSET) {
console.log(set)
const expressIDs = idMap
const workingIDs = expressIDs.filter(id => relatedIDs.includes(id));
if (workingIDs.length > 0) {
console.log('Working IDs:', workingIDs);
} else {
console.log('No common IDs found between expressIDs and relatedIDs');
}
const { name: setName} = OBC.IfcPropertiesUtils.getEntityName(properties, setID)
console.log(setName)
if ( !setName || workingIDs.length === 0 || setName != 'Dimensions') { return}

if (!(setName in resultRow)) {
resultRow[setName] = {}
}
// setName = dimensions
console.log(workingIDs[0])
OBC.IfcPropertiesUtils.getPsetProps(properties, workingIDs[0], (foundID) => {
console.log(`Property found with expressID: ${foundID}`);
})


OBC.IfcPropertiesUtils.getQsetQuantities(
properties,
setID,
(qtoID) => {
console.log(properties[qtoID])
const { name: qtoName} = OBC.IfcPropertiesUtils.getEntityName(properties, qtoID)
console.log(qtoName)
const { value } = OBC.IfcPropertiesUtils.getQuantityValue(properties, qtoID)
console.log(value)
if(!qtoName || !value) {return}
console.log(qtoName)
if (!(qtoName in resultRow[setName])) {
resultRow[setName][qtoName] = value

}
if ((qtoName in resultRow[setName])) {
resultRow[setName][qtoName] = Math.min(resultRow[setName][qtoName], value) //find a lower value, as there are multiple netVolumes !!!!!!

}
//resultRow[setName][qtoName] = value


console.log(resultRow)
}
)

}
console.log(resultRow)
}



// BASE QUANTITIES
if ( set.type !== WEBIFC.IFCELEMENTQUANTITY) { return }
const expressIDs = idMap

const workingIDs = expressIDs.filter(id => relatedIDs.includes(id));
//console.log(workingIDs)


if (workingIDs.length > 0) {
//console.log('Working IDs:', workingIDs);
console.log('Working IDs:', workingIDs);
} else {
//console.log('No common IDs found between expressIDs and relatedIDs');
console.log('No common IDs found between expressIDs and relatedIDs');
}

const { name: setName} = OBC.IfcPropertiesUtils.getEntityName(properties, setID)
Expand All @@ -416,9 +537,9 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
properties,
setID,
(qtoID) => {
//console.log(properties[qtoID])
console.log(properties[qtoID])
const { name: qtoName} = OBC.IfcPropertiesUtils.getEntityName(properties, qtoID)
//console.log(qtoName)
console.log(qtoName)
const { value } = OBC.IfcPropertiesUtils.getQuantityValue(properties, qtoID)
//console.log(value)
if(!qtoName || !value) {return}
Expand All @@ -434,13 +555,13 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
//resultRow[setName][qtoName] = value
}
)
console.log(nameValue)
console.log(qtoResultByElementFamily)
//console.log(nameValue)
//console.log(qtoResultByElementFamily)

if (!(nameValue in qtoResultByElementFamily)) {
qtoResultByElementFamily[nameValue] = {}; // Initialize if not exists
}
console.log(qtoResultByElementFamily[nameValue])
//console.log(qtoResultByElementFamily[nameValue])

if (!("CF values" in qtoResultByElementFamily[nameValue])) {
qtoResultByElementFamily[nameValue]["CF values"] = {
Expand All @@ -460,6 +581,7 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement

console.log(qtoResultByElementName[nameValue])
console.log(elementType)
console.log(resultRow)
console.log(resultRow["BaseQuantities"])
let area
if(elementType == "windows" || elementType == "doors") {
Expand Down Expand Up @@ -540,7 +662,16 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
properties,
WEBIFC.IFCWINDOW
)

const curtainWalls = OBC.IfcPropertiesUtils.getAllItemsOfType(
properties,
WEBIFC.IFCCURTAINWALL
)
console.log(curtainWalls)

const curtainPanels = OBC.IfcPropertiesUtils.getAllItemsOfType(
properties,
WEBIFC.IFCPLATE
)

const elements = typeList

Expand All @@ -555,6 +686,8 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
console.log(doorResults)
const windowResults = this.calculateQuantities(properties, windows, "windows")
console.log(windowResults)
const curtainWallsRes = this.calculateQuantities(properties, curtainPanels, "curtainPanels")
console.log(curtainWallsRes)

this._qtoResultByElementName = { ...wallResults, ...slabResults , ...windowResults, ...doorResults};

Expand Down
18 changes: 12 additions & 6 deletions src/bim-components/CarbonTool/src/ElementCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Component } from "../../../classes/Component"


export class ElementCard extends OBC.SimpleUIComponent {
callback: VoidFunction
onDelete = new OBC.Event()
onCardClick = new OBC.Event()
//elementData
Expand Down Expand Up @@ -74,10 +75,12 @@ export class ElementCard extends OBC.SimpleUIComponent {

}
}

setCallback(callbackFunction) {
this.callback = callbackFunction;
}


constructor(components: OBC.Components, epdxData, constructionComponents) {
constructor(components: OBC.Components, epdxData, constructionComponents, callback) {


const template = `
Expand All @@ -93,9 +96,9 @@ export class ElementCard extends OBC.SimpleUIComponent {
</h3>
</div>
<div>
<h4 id="ElementComponent">
</h4>
<div class="element-component" id="ElementComponent">
...select a component
</div>
</div>
</div>
Expand Down Expand Up @@ -124,7 +127,7 @@ export class ElementCard extends OBC.SimpleUIComponent {
})
this.setSlot("actionButtons", new OBC.SimpleUIComponent(this._components))


this.callback = callback

}
async dispose () {
Expand Down Expand Up @@ -181,6 +184,9 @@ export class ElementCard extends OBC.SimpleUIComponent {

this.elementData = this.elementSet
//this.calculateGWP(this.elementSet)


this.callback()
});


Expand Down
13 changes: 8 additions & 5 deletions src/bim-components/CarbonTool/src/ResultsCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ResultsCard extends OBC.SimpleUIComponent {
return this.resultDataset
}
set resultData(object) {
console.log("Set result")
this.calculateGWP(object)
}
set totalResult(value) {
Expand Down Expand Up @@ -54,6 +55,7 @@ export class ResultsCard extends OBC.SimpleUIComponent {
</div>
<div id=""> </ div>
<div data-tooeen-slot="actionButtons"></div>
</div>
</div>
Expand All @@ -64,14 +66,15 @@ export class ResultsCard extends OBC.SimpleUIComponent {
this.resultContainer = this.getInnerElement("resultsContainer") as HTMLParagraphElement









}


async dispose () {
this.dispose()

Expand All @@ -85,16 +88,16 @@ export class ResultsCard extends OBC.SimpleUIComponent {

}
calculateGWP(list) {
//console.log("Calculating GWP")
console.log("Calculating GWP")
let tempResult = 0
for (const item in list) {
const sets = list[item]
for(const setName in sets) {
//console.log(setName)
console.log(setName)
if(setName == "CF values") {
const element = sets[setName]
//console.log(element)
//console.log(element["Carbon Footprint"])
console.log(element)
console.log(element["Carbon Footprint"])
const result = element["Carbon Footprint"]
tempResult += result

Expand Down
Loading

0 comments on commit e3ac35e

Please sign in to comment.