simplified calculator core
This commit is contained in:
Родитель
5d7a1f45f0
Коммит
1d75668c60
|
@ -13,7 +13,7 @@ from app.models import Webhook
|
|||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/healt")
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return True
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"payload": {
|
||||
"streamId": "762c64bb55",
|
||||
"streamId": "3baa1ec795",
|
||||
"userId": "81fff8de8d",
|
||||
"activityMessage": "Commit created on branch main: 8445f44a50 (Sent 344 objects from Revit2021.)",
|
||||
"event": {
|
||||
|
@ -8,9 +8,9 @@
|
|||
"data": {
|
||||
"id": "8445f44a50",
|
||||
"commit": {
|
||||
"streamId": "762c64bb55",
|
||||
"streamId": "3baa1ec795",
|
||||
"branchName": "main",
|
||||
"objectId": "673863a451b606e6b3967e98ea28696b",
|
||||
"objectId": "96b8d4f656144275ac2ffb62d8219e61",
|
||||
"message": "Sent 344 objects from Revit2021.",
|
||||
"sourceApplication": "Revit2021",
|
||||
"totalChildrenCount": 0,
|
||||
|
@ -27,13 +27,13 @@
|
|||
"description": "This a community deployment of a Speckle Server.",
|
||||
"adminContact": "n/a",
|
||||
"termsOfService": "n/a",
|
||||
"canonicalUrl": "http://anthe.local",
|
||||
"canonicalUrl": "http://localhost:8080",
|
||||
"completed": false,
|
||||
"inviteOnly": false,
|
||||
"version": "custom"
|
||||
},
|
||||
"stream": {
|
||||
"id": "762c64bb55",
|
||||
"id": "3baa1ec795",
|
||||
"name": "Hackathon Revit Demo",
|
||||
"description": "",
|
||||
"isPublic": true,
|
||||
|
@ -55,7 +55,7 @@
|
|||
},
|
||||
"webhook": {
|
||||
"id": "60c710daa1",
|
||||
"streamId": "762c64bb55",
|
||||
"streamId": "3baa1ec795",
|
||||
"url": "http://localhost:8000/calculate",
|
||||
"description": "Do carbon",
|
||||
"triggers": [
|
||||
|
|
|
@ -3,7 +3,10 @@ from specklepy.objects import Base
|
|||
from typing import Dict, List
|
||||
from itertools import chain
|
||||
|
||||
from speckle_calculator.core.carbon_repo import material_properties, type_material_mapping
|
||||
from speckle_calculator.core.carbon_repo import (
|
||||
TYPE_MATERIAL_MAPPING,
|
||||
MATERIAL_PROPERTIES,
|
||||
)
|
||||
|
||||
|
||||
class CarbonDataPoint(Base):
|
||||
|
@ -21,10 +24,6 @@ class CarbonData(Base):
|
|||
results: Dict[str, List[CarbonDataPoint]]
|
||||
|
||||
|
||||
type_material_mapping = type_material_mapping()
|
||||
material_properties_mapping = material_properties()
|
||||
|
||||
|
||||
def calculate_carbon(commit: Base) -> CarbonDataPoint:
|
||||
"""It does the magic."""
|
||||
|
||||
|
@ -38,8 +37,8 @@ def calculate_carbon(commit: Base) -> CarbonDataPoint:
|
|||
for object in objects:
|
||||
if parameters := getattr(object, "parameters", None):
|
||||
if volume := getattr(parameters, "HOST_VOLUME_COMPUTED", None):
|
||||
if material := type_material_mapping.get(object.speckle_type):
|
||||
if material_props := material_properties_mapping.get(material):
|
||||
if material := TYPE_MATERIAL_MAPPING.get(object.speckle_type):
|
||||
if material_props := MATERIAL_PROPERTIES.get(material):
|
||||
density = material_props["density"]
|
||||
co_value = material_props["kgCO2e"]
|
||||
co2_value = volume.value * density * co_value
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
def type_material_mapping():
|
||||
return {
|
||||
"Objects.BuiltElements.Beam:Objects.BuiltElements.Revit.RevitBeam": "Concrete",
|
||||
"Objects.BuiltElements.Ceiling:Objects.BuiltElements.Revit.RevitCeiling": "Concrete",
|
||||
"Objects.BuiltElements.Column:Objects.BuiltElements.Revit.RevitColumn": "Concrete",
|
||||
"Objects.BuiltElements.Floor:Objects.BuiltElements.Revit.RevitFloor": "Concrete",
|
||||
"Objects.BuiltElements.Roof:Objects.BuiltElements.Revit.RevitRoof.RevitRoof:Objects.BuiltElements.Revit.RevitRoof.RevitExtrusionRoof": "Steel",
|
||||
"Objects.BuiltElements.Roof:Objects.BuiltElements.Revit.RevitRoof.RevitRoof:Objects.BuiltElements.Revit.RevitRoof.RevitFootprintRoof": "Timber",
|
||||
"Objects.BuiltElements.Wall:Objects.BuiltElements.Revit.RevitWall": "Timber",
|
||||
"Objects.BuiltElements.Revit.FamilyInstance": "Concrete",
|
||||
"Objects.BuiltElements.Revit.RevitStair": "Concrete",
|
||||
}
|
||||
TYPE_MATERIAL_MAPPING = {
|
||||
"Objects.BuiltElements.Beam:Objects.BuiltElements.Revit.RevitBeam": "Concrete",
|
||||
"Objects.BuiltElements.Ceiling:Objects.BuiltElements.Revit.RevitCeiling": "Concrete",
|
||||
"Objects.BuiltElements.Column:Objects.BuiltElements.Revit.RevitColumn": "Concrete",
|
||||
"Objects.BuiltElements.Floor:Objects.BuiltElements.Revit.RevitFloor": "Concrete",
|
||||
"Objects.BuiltElements.Roof:Objects.BuiltElements.Revit.RevitRoof.RevitRoof:Objects.BuiltElements.Revit.RevitRoof.RevitExtrusionRoof": "Steel",
|
||||
"Objects.BuiltElements.Roof:Objects.BuiltElements.Revit.RevitRoof.RevitRoof:Objects.BuiltElements.Revit.RevitRoof.RevitFootprintRoof": "Timber",
|
||||
"Objects.BuiltElements.Wall:Objects.BuiltElements.Revit.RevitWall": "Timber",
|
||||
"Objects.BuiltElements.Revit.FamilyInstance": "Concrete",
|
||||
"Objects.BuiltElements.Revit.RevitStair": "Concrete",
|
||||
}
|
||||
|
||||
|
||||
def material_properties():
|
||||
return {
|
||||
"Aluminium": {"density": 2700, "kgCO2e": 9.16},
|
||||
"Concrete": {"density": 2400, "kgCO2e": 0.12},
|
||||
"Steel": {"density": 7800, "kgCO2e": 1.46},
|
||||
"Timber": {"density": 650, "kgCO2e": 0.72},
|
||||
}
|
||||
MATERIAL_PROPERTIES = {
|
||||
"Aluminium": {"density": 2700, "kgCO2e": 9.16},
|
||||
"Concrete": {"density": 2400, "kgCO2e": 0.12},
|
||||
"Steel": {"density": 7800, "kgCO2e": 1.46},
|
||||
"Timber": {"density": 650, "kgCO2e": 0.72},
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче