Fix failing tests in preparation for release.

This commit is contained in:
Dion Moult
2023-05-06 11:05:13 +10:00
parent 89310d19cb
commit b8431a8c33
12 changed files with 88 additions and 62 deletions
@@ -21,36 +21,36 @@ import ifcopenshell.util.date
def get_productivity(resource, should_inherit=True):
productivity = ifcopenshell.util.element.get_psets(
resource
).get("EPset_Productivity", None)
productivity = ifcopenshell.util.element.get_psets(resource).get("EPset_Productivity", None)
if should_inherit and not productivity:
# Proposal for Schema - If instance doesn't have any productivity, inherit it's parent's productivity
if not resource.Nests:
return None
else:
parent_resource = resource.Nests[0].RelatingObject
productivity = ifcopenshell.util.element.get_psets(
parent_resource
).get("EPset_Productivity", None)
productivity = ifcopenshell.util.element.get_psets(parent_resource).get("EPset_Productivity", None)
return productivity
def get_unit_consumed(productivity):
duration = productivity.get("BaseQuantityConsumed", None)
if not duration:
return
return ifcopenshell.util.date.ifc2datetime(duration)
def get_quantity_produced(productivity):
if not productivity:
return 0
return productivity.get("BaseQuantityProducedValue", 0)
def get_quantity_produced_name(productivity):
if not productivity:
return ""
return productivity.get("BaseQuantityProducedName", "")
def get_total_quantity_produced(resource, quantity_name_in_process):
def get_product_quantity(product, quantity_name):
psets = ifcopenshell.util.element.get_psets(product)
@@ -65,9 +65,10 @@ def get_total_quantity_produced(resource, quantity_name_in_process):
total = len(products)
else:
for product in products:
total += get_product_quantity(product, quantity_name_in_process)
total += get_product_quantity(product, quantity_name_in_process) or 0
return total
def get_parametric_resource_products(resource):
products = []
for rel in resource.HasAssignments or []:
@@ -79,6 +80,7 @@ def get_parametric_resource_products(resource):
products.append(rel2.RelatingProduct)
return products
def get_resource_required_work(resource):
productivity = get_productivity(resource)
if productivity:
@@ -92,11 +94,11 @@ def get_resource_required_work(resource):
if "T" in productivity.get("BaseQuantityConsumed", ""):
seconds = (time_consumed.days * 24 * 60 * 60) + time_consumed.seconds
productivity_ratio = seconds / quantity_produced
required_work = total_quantity_to_produce * productivity_ratio
required_work = total_quantity_to_produce * productivity_ratio
iso_string = f"PT{required_work / 60 / 60}H"
else:
days = time_consumed.days + (time_consumed.seconds / (24 * 60 * 60))
productivity_ratio = days / quantity_produced
productivity_ratio = days / quantity_produced
required_work = total_quantity_to_produce * productivity_ratio
iso_string = f"P{required_work}D"
return iso_string
return iso_string
@@ -159,9 +159,7 @@ class Selector:
if not inverse_relationship:
return results
return cls.parse_inverse_relationship(
results, inverse_relationship.children[0].data
)
return cls.parse_inverse_relationship(results, inverse_relationship.children[0].data)
@classmethod
def parse_inverse_relationship(cls, elements, inverse_relationship):
@@ -193,13 +191,8 @@ class Selector:
if cls.elements is None:
elements = cls.file.by_type(class_selector.children[0])
else:
elements = [
e for e in cls.elements if e.is_a(class_selector.children[0])
]
if (
len(class_selector.children) > 1
and class_selector.children[1].data == "filter"
):
elements = [e for e in cls.elements if e.is_a(class_selector.children[0])]
if len(class_selector.children) > 1 and class_selector.children[1].data == "filter":
return cls.filter_elements(elements, class_selector.children[1])
return elements
@@ -227,9 +220,7 @@ class Selector:
element_value = cls.get_element_value(element, filter_query["keys"], is_regex=filter_query["is_regex"])
if element_value is None and value is not None and "not" not in comparison:
continue
if comparison and cls.filter_element(
element, element_value, comparison, value
):
if comparison and cls.filter_element(element, element_value, comparison, value):
results.append(element)
elif not comparison and element_value:
results.append(element)
@@ -243,9 +234,9 @@ class Selector:
keys = [keys]
elif keys.data == "keys_regex":
is_regex = True
keys = [k[1:-1].replace("\\\"", '"') for k in keys.children]
keys = [k[1:-1].replace('\\"', '"') for k in keys.children]
elif keys.data == "keys_quoted":
keys = [k[1:-1].replace("\\\"", '"') for k in keys.children]
keys = [k[1:-1].replace('\\"', '"') for k in keys.children]
elif keys.data == "keys_simple":
keys = keys.children
return {"keys": keys, "is_regex": is_regex}
@@ -273,6 +264,9 @@ class Selector:
elif key == "class":
value = value.is_a()
elif isinstance(value, ifcopenshell.entity_instance):
if key == "Name" and value.is_a("IfcMaterialLayerSet"):
key = "LayerSetName" # This oddity in the IFC spec is annoying so we account for it.
attribute = value.get_info().get(key, None)
if attribute is not None:
@@ -290,7 +284,7 @@ class Selector:
result = ifcopenshell.util.element.get_pset(value, key)
value = result
elif isinstance(value, dict): # Such as from the result of a prior get_pset
elif isinstance(value, dict): # Such as from the result of a prior get_pset
if is_regex:
results = []
for prop_name, prop_value in value.items():
@@ -302,7 +296,7 @@ class Selector:
value = results
else:
value = value.get(key, None)
elif isinstance(value, (list, tuple)): # If we use regex
elif isinstance(value, (list, tuple)): # If we use regex
if key.isnumeric():
try:
value = value[int(key)]