Skip to content

Commit

Permalink
added summing up by IFC family name
Browse files Browse the repository at this point in the history
  • Loading branch information
Curiosit committed Mar 29, 2024
1 parent 2280d8a commit 4dd6d13
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 78 deletions.
141 changes: 108 additions & 33 deletions src/bim-components/CarbonTool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
this._qtoResultByElementName = {}
this._qtoResult = {}
this.setUI()
this.getQuantities()
//this.getQuantities()

}
async loadData() {
Expand Down Expand Up @@ -340,11 +340,13 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement

let idMap = new Array()
let qtoResultByElementName: QtoResultByElementName
let qtoResultByElementFamily: QtoResultByElementName
let result

qtoResultByElementName = {}
qtoResultByElementFamily = {}
console.log(qtoResultByElementName)

console.log(qtoResultByElementFamily)
console.log("________________________________________________________________________")
console.log("________________________________________________________________________")
console.log("________________________________________________________________________")
Expand All @@ -357,26 +359,36 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
}
}
console.log(elements)
const byInstance = false
for (const elementID in elements) {
idMap = []
console.log("________________________________________________________________________")
console.log(elementID)
console.log(elements[elementID])
//console.log("________________________________________________________________________")
//console.log(elementID)
//console.log(elements[elementID])
const name = properties[elements[elementID].expressID].Name.value
const nameWithID = name + '#' + elements[elementID].expressID

let nameValue
if (byInstance) {
const nameWithID = name + '#' + elements[elementID].expressID
nameValue = nameWithID
}
else {
const family = properties[elements[elementID].expressID].ObjectType.value
nameValue = family
}
idMap.push(elements[elementID].expressID)

qtoResultByElementName[nameWithID] = {}
const resultRow = qtoResultByElementName[nameWithID]
console.log(qtoResultByElementName[nameWithID])
console.log("________________________________________________________________________")
qtoResultByElementName[nameValue] = {}
const resultRow = qtoResultByElementName[nameValue]
//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")
//console.log("GET RELATION MAP")

const set = properties[setID]
if ( set.type !== WEBIFC.IFCELEMENTQUANTITY) { return}
Expand Down Expand Up @@ -406,9 +418,9 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
(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)
//console.log(value)
if(!qtoName || !value) {return}
//console.log(qtoName)
if (!(qtoName in resultRow[setName])) {
Expand All @@ -422,31 +434,80 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
//resultRow[setName][qtoName] = value
}
)
console.log("Element thickness: ")
const thickness = resultRow["BaseQuantities"]["Width"] / 1000
console.log(thickness)
console.log("Element volume: ")
const volume = resultRow["BaseQuantities"]["NetVolume"]
console.log(volume)

console.log("Element area: ")
const area = volume / thickness
console.log(area)
//qtoResultByElementName[nameWithID]["CF values"]["Area"] = area
//qtoResultByElementName[nameWithID]["CF values"]["Element GWP"] = 0
qtoResultByElementName[nameWithID]["CF values"] = {
"Amount": area,
"Element GWP / unit": 0,
"Carbon Footprint": 0
}
console.log(nameValue)
console.log(qtoResultByElementFamily)

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

if (!("CF values" in qtoResultByElementFamily[nameValue])) {
qtoResultByElementFamily[nameValue]["CF values"] = {
"Amount": 0, // Initialize with 0
"Element GWP / unit": 0,
"Carbon Footprint": 0
};
}

if (!("CF values" in qtoResultByElementName[nameValue])) {
qtoResultByElementName[nameValue]["CF values"] = {
"Amount": 0, // Initialize with 0
"Element GWP / unit": 0,
"Carbon Footprint": 0
};
}

console.log(qtoResultByElementName[nameValue])
console.log(elementType)
console.log(resultRow["BaseQuantities"])
let area
if(elementType == "windows" || elementType == "doors") {

console.log("Element width: ")
const width = resultRow["BaseQuantities"]["Width"] / 1000
console.log(width)
console.log("Element height: ")
const height = resultRow["BaseQuantities"]["Height"] / 1000
console.log(height)



console.log("Element area: ")
area = height * width
console.log(area)
//qtoResultByElementName[nameWithID]["CF values"]["Area"] = area
//qtoResultByElementName[nameWithID]["CF values"]["Element GWP"] = 0

}

else {


console.log("Element thickness: ")
const thickness = resultRow["BaseQuantities"]["Width"] / 1000
console.log(thickness)
console.log("Element volume: ")
const volume = resultRow["BaseQuantities"]["NetVolume"]
console.log(volume)

console.log("Element area: ")
area = volume / thickness
console.log(area)
//qtoResultByElementName[nameWithID]["CF values"]["Area"] = area
//qtoResultByElementName[nameWithID]["CF values"]["Element GWP"] = 0

}
qtoResultByElementName[nameValue]["CF values"]["Amount"] += area;
qtoResultByElementFamily[nameValue]["CF values"]["Amount"] += area;
}

)
console.log(resultRow)


}
return qtoResultByElementName
return qtoResultByElementFamily

}

Expand Down Expand Up @@ -475,13 +536,27 @@ export class CarbonTool extends OBC.Component<BuildingCarbonFootprint> implement
properties,
WEBIFC.IFCDOOR
)
const windows = OBC.IfcPropertiesUtils.getAllItemsOfType(
properties,
WEBIFC.IFCWINDOW
)


const elements = typeList

//const elements = slabs
console.log(elements)

this._qtoResultByElementName = this.calculateQuantities(properties, walls, "walls")
const wallResults = this.calculateQuantities(properties, walls, "walls")
console.log(wallResults)
const slabResults = this.calculateQuantities(properties, slabs, "slabs")
console.log(slabResults)
const doorResults = this.calculateQuantities(properties, doors, "doors")
console.log(doorResults)
const windowResults = this.calculateQuantities(properties, windows, "windows")
console.log(windowResults)

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

console.log(this._qtoResultByElementName)
this.resetWindow()
Expand Down
50 changes: 25 additions & 25 deletions src/bim-components/CarbonTool/src/ElementCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ export class ElementCard extends OBC.SimpleUIComponent {
}
set elementData(object) {
this.elementSet = object
console.log("setting elementData")
//console.log("setting elementData")
this.elementDataset = object
this.calculateGWP(object)
console.log(this.elementDataset)
//console.log(this.elementDataset)
const set = object
console.log(set)
//console.log(set)
if (this.setList) {
while (this.setList.firstChild) {
console.log("clearing children:")
console.log(this.setList.firstChild)
//console.log("clearing children:")
//console.log(this.setList.firstChild)
const setCard = this.setList.firstChild

this.setList.removeChild(this.setList.firstChild)
Expand All @@ -57,16 +57,16 @@ export class ElementCard extends OBC.SimpleUIComponent {
}

for (const setName in set) {
console.log(setName)
//console.log(setName)
if(setName == "CF values") {
console.log(set[setName])
//console.log(set[setName])
if (set.hasOwnProperty(setName)) {
const setCard = new ElementSetNameCard(this.components)

setCard.setName = setName
setCard.setData = set[setName]

console.log(setCard)
//console.log(setCard)
this.setList.appendChild(setCard.domElement)
//this.addChild(setCard)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ export class ElementCard extends OBC.SimpleUIComponent {

this._qtyElement = this.getInnerElement("ElementName") as HTMLParagraphElement
this.setList = this.getInnerElement("setList") as HTMLParagraphElement
console.log(this._qtyElement)
//console.log(this._qtyElement)


const cardElement = this.get()
Expand All @@ -130,8 +130,8 @@ export class ElementCard extends OBC.SimpleUIComponent {
async dispose () {

while (this._qtyElement.firstChild) {
console.log("child:")
console.log(this._qtyElement.firstChild)
//console.log("child:")
//console.log(this._qtyElement.firstChild)
this._qtyElement.removeChild(this._qtyElement.firstChild)
}

Expand All @@ -140,8 +140,8 @@ export class ElementCard extends OBC.SimpleUIComponent {

async setupOnClick(materialForm: OBC.FloatingWindow) {
this.onCardClick.add(() => {
console.log("Setup onclick");
console.log(this.constructionComponents);
//console.log("Setup onclick");
//console.log(this.constructionComponents);
const constructionComponents = this.constructionComponents
// Clear existing content in materialForm if any
var parentElement = materialForm.slots.content.domElement;
Expand Down Expand Up @@ -176,7 +176,7 @@ export class ElementCard extends OBC.SimpleUIComponent {
// Optional: Update UI or other properties as needed
this.elementComponent = constructionComponents.find(c => c.id === selectedComponentID)?.name;

console.log("Selected Component ID:", this.elementComponentID);
//console.log("Selected Component ID:", this.elementComponentID);


this.elementData = this.elementSet
Expand Down Expand Up @@ -209,14 +209,14 @@ export class ElementCard extends OBC.SimpleUIComponent {


calculateGWPold(set) {
console.log("Calculating GWP")
//console.log("Calculating GWP")

for (const setName in set) {
console.log(setName)
//console.log(setName)
if(setName == "CF values") {
console.log(set["CF values"])
console.log(set["CF values"]["Amount"])
console.log(set["CF values"]["Element GWP / unit"])
//console.log(set["CF values"])
//console.log(set["CF values"]["Amount"])
//console.log(set["CF values"]["Element GWP / unit"])
set["CF values"]["Amount"] * set["CF values"]["Element GWP / unit"]
set["CF values"]["Carbon Footprint"] = set["CF values"]["Amount"] * set["CF values"]["Element GWP / unit"]
}
Expand All @@ -225,9 +225,9 @@ export class ElementCard extends OBC.SimpleUIComponent {

}
calculateGWP(set) {
console.log("Calculating GWP")
//console.log("Calculating GWP")
let compGWP = 0
console.log("Component GWP:")
//console.log("Component GWP:")
if (this.elementComponentID) {


Expand All @@ -245,15 +245,15 @@ export class ElementCard extends OBC.SimpleUIComponent {


compGWP = calculateTotalComponentGWP(layers,this.epdxData)
console.log(compGWP)
//console.log(compGWP)

}
}

for (const setName in set) {
console.log(setName)
//console.log(setName)
if(setName == "CF values") {
console.log(set["CF values"])
//console.log(set["CF values"])
//console.log(set["CF values"]["Amount"])
//console.log(set["CF values"]["Element GWP / unit"])
//set["CF values"]["Amount"] * set["CF values"]["Element GWP / unit"]
Expand All @@ -262,7 +262,7 @@ export class ElementCard extends OBC.SimpleUIComponent {
//set["CF values"]["Carbon Footprint"] = set["CF values"]["Amount"] * set["CF values"]["Element GWP / unit"]


console.log(set["CF values"])
//console.log(set["CF values"])
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bim-components/CarbonTool/src/ElementQtyCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ElementQtyCard extends OBC.SimpleUIComponent {
qtyDataset

set qtyValuePairData (object: QtyValuePairData) {
console.log(object)
//console.log(object)
this.qtyDataset = object

const [name, value] = Object.entries(object)[0]
Expand Down
Loading

0 comments on commit 4dd6d13

Please sign in to comment.