consider unit basis for calculating resource costs #4122

This commit is contained in:
Sigma Dimensions (Yass)
2023-12-20 14:18:55 +01:00
parent 73aeafb063
commit 46454c5c94
2 changed files with 16 additions and 12 deletions
@@ -119,22 +119,25 @@ def get_nested_resources(resource):
def get_cost(resource):
total = 0
for cost_value in resource.BaseCosts or []:
total += cost_value.AppliedValue.wrappedValue if cost_value.AppliedValue else 0
return total
costs = [
ifcopenshell.util.cost.calculate_applied_value(resource, cost_value)
for cost_value in getattr(resource, "BaseCosts", [])
]
cost = costs[0] if costs else None
unit_basis = next(
(cost_value.UnitBasis for cost_value in getattr(resource, "BaseCosts", []) if cost_value.UnitBasis),
None
)
unit = unit_basis.UnitComponent.Name if unit_basis and unit_basis.UnitComponent.is_a("IfcConversionBasedUnit") else None
return cost, unit
def get_quantity(resource):
total = 0
if resource.BaseQuantity:
return resource.BaseQuantity[3]
if resource.Usage and resource.Usage.ScheduleWork:
# For now we assume either hourly or daily depending on how duration is stored
duration = ifcopenshell.util.date.ifc2datetime(resource.Usage.ScheduleWork)
if duration.days:
return duration.days
return duration.seconds / 60 / 60
return duration.total_seconds() / 3600
def get_parent_cost(resource):
if not resource.Nests: