Proposal to use resource's parent cost, reducing manual insertions

This commit is contained in:
Sigma Dimensions (Yass)
2023-09-23 16:04:01 +01:00
parent 0fc478f2f3
commit e9ed850b78
2 changed files with 32 additions and 19 deletions
@@ -18,6 +18,7 @@
import ifcopenshell.api
import ifcopenshell.util.date
import ifcopenshell.util.resource
class Usecase:
@@ -105,8 +106,10 @@ class Usecase:
total_cost = 0
for resource in resources:
cost = self.get_cost(resource)
quantity = self.get_quantity(resource)
cost = ifcopenshell.util.resource.get_cost(resource)
quantity = ifcopenshell.util.resource.get_quantity(resource)
if not cost:
cost = ifcopenshell.util.resource.get_parent_cost(resource) # Concept to standardise - Not defined in schema, but this makes manual scheduling of resources 10x faster and less duplicate data.
if not cost or not quantity:
continue
total_cost += cost * quantity
@@ -114,20 +117,3 @@ class Usecase:
if total_cost:
cost_value = ifcopenshell.api.run("cost.add_cost_value", self.file, parent=self.settings["cost_item"])
cost_value.AppliedValue = self.file.createIfcMonetaryMeasure(total_cost)
def get_cost(self, resource):
total = 0
for cost_value in resource.BaseCosts or []:
total += cost_value.AppliedValue.wrappedValue if cost_value.AppliedValue else 0
return total
def get_quantity(self, 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
@@ -113,5 +113,32 @@ def get_resource_required_work(resource):
iso_string = f"P{required_work}D"
return iso_string
def get_nested_resources(resource):
return [object for rel in resource.IsNestedBy or [] for object in rel.RelatedObjects]
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
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
def get_parent_cost(resource):
if not resource.Nests:
return
else:
cost = get_cost(resource.Nests[0].RelatingObject)
return cost