From 70ba681b35ccd39971ceb880b8f3fbbb271bdd7c Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 20 Sep 2021 13:27:22 +1000 Subject: [PATCH] Resource work duration can now be calculated based on counting produced products. --- .../api/resource/calculate_resource_work.py | 14 +++++------ .../resource/test_calculate_resource_work.py | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_work.py b/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_work.py index 92a0ae82a8..e690b79d35 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_work.py +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_work.py @@ -48,12 +48,12 @@ class Usecase: for rel2 in rel.RelatingProcess.HasAssignments or []: if not rel2.is_a("IfcRelAssignsToProduct"): continue - psets = ifcopenshell.util.element.get_psets(rel2.RelatingProduct) - for pset in psets.values(): - for name, value in pset.items(): - if name == self.unit_produced_name: - try: + if self.unit_produced_name == "Count": + total += 1 + else: + psets = ifcopenshell.util.element.get_psets(rel2.RelatingProduct) + for pset in psets.values(): + for name, value in pset.items(): + if name == self.unit_produced_name: total += float(value) - except: - pass return total diff --git a/src/ifcopenshell-python/test/api/resource/test_calculate_resource_work.py b/src/ifcopenshell-python/test/api/resource/test_calculate_resource_work.py index 931539e11c..f9a8a59a25 100644 --- a/src/ifcopenshell-python/test/api/resource/test_calculate_resource_work.py +++ b/src/ifcopenshell-python/test/api/resource/test_calculate_resource_work.py @@ -68,3 +68,27 @@ class TestCalculateResourceWork(test.bootstrap.IFC4): ifcopenshell.api.run("resource.calculate_resource_work", self.file, resource=resource) assert resource.Usage is None + + def test_calculating_resource_work_based_on_a_counted_quantity(self): + ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject") + + resource = ifcopenshell.api.run("resource.add_resource", self.file, ifc_class="IfcLaborResource") + pset = ifcopenshell.api.run("pset.add_pset", self.file, product=resource, name="EPset_Productivity") + ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={ + "BaseQuantityConsumed": "PT1H", + "BaseQuantityProducedName": "Count", + "BaseQuantityProducedValue": 2, + }) + + slab = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab") + qto = ifcopenshell.api.run("pset.add_qto", self.file, product=slab, name="Qto_SlabBaseQuantities") + ifcopenshell.api.run("pset.edit_qto", self.file, qto=qto, properties={"GrossVolume": 20}) + + ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=slab, related_object=resource) + + schedule = ifcopenshell.api.run("sequence.add_work_schedule", self.file) + task = ifcopenshell.api.run("sequence.add_task", self.file, work_schedule=schedule) + ifcopenshell.api.run("sequence.assign_product", self.file, relating_product=slab, related_object=task) + ifcopenshell.api.run("sequence.assign_process", self.file, relating_process=task, related_object=resource) + ifcopenshell.api.run("resource.calculate_resource_work", self.file, resource=resource) + assert resource.Usage.ScheduleWork == "PT0.5H"