mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
- refactor IOS.API resource calculation to re-use shared utilities
- run black
This commit is contained in:
@@ -21,7 +21,12 @@ import ifcopenshell.api
|
||||
|
||||
class Usecase:
|
||||
def __init__(
|
||||
self, file, parent_resource=None, ifc_class="IfcCrewResource", name=None, predefined_type="NOTDEFINED"
|
||||
self,
|
||||
file,
|
||||
parent_resource=None,
|
||||
ifc_class="IfcCrewResource",
|
||||
name=None,
|
||||
predefined_type="NOTDEFINED",
|
||||
):
|
||||
"""Add a new construction resource
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import math
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.date
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.resource
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -59,28 +60,10 @@ class Usecase:
|
||||
self.settings = {"resource": resource}
|
||||
|
||||
def execute(self):
|
||||
self.productivity = ifcopenshell.util.element.get_psets(
|
||||
amount_worked = ifcopenshell.util.resource.get_resource_required_work(
|
||||
self.settings["resource"]
|
||||
).get("EPset_Productivity", None)
|
||||
if not self.productivity:
|
||||
# Proposal for Schema - If instance doesn't have any productivity, use the parent's productivity - if any.
|
||||
if not self.settings["resource"].Nests:
|
||||
return
|
||||
else:
|
||||
parent_resource = self.settings["resource"].Nests[0].RelatingObject
|
||||
self.productivity = ifcopenshell.util.element.get_psets(
|
||||
parent_resource
|
||||
).get("EPset_Productivity", None)
|
||||
if not self.productivity:
|
||||
return
|
||||
|
||||
unit_consumed = self.get_unit_consumed()
|
||||
self.unit_produced_name = self.productivity.get(
|
||||
"BaseQuantityProducedName", None
|
||||
)
|
||||
unit_produced = self.productivity.get("BaseQuantityProducedValue", None)
|
||||
total_produced = self.get_total_produced()
|
||||
if not unit_consumed or not unit_produced or not total_produced:
|
||||
if not amount_worked:
|
||||
return
|
||||
if not self.settings["resource"].Usage:
|
||||
ifcopenshell.api.run(
|
||||
@@ -88,37 +71,4 @@ class Usecase:
|
||||
self.file,
|
||||
resource=self.settings["resource"],
|
||||
)
|
||||
if "T" in self.productivity.get("BaseQuantityConsumed", None):
|
||||
seconds = (unit_consumed.days * 24 * 60 * 60) + unit_consumed.seconds
|
||||
amount_worked = total_produced / unit_produced * seconds
|
||||
self.settings[
|
||||
"resource"
|
||||
].Usage.ScheduleWork = f"PT{amount_worked / 60 / 60}H"
|
||||
else:
|
||||
days = unit_consumed.days + (unit_consumed.seconds / (24 * 60 * 60))
|
||||
amount_worked = total_produced / unit_produced * days
|
||||
self.settings["resource"].Usage.ScheduleWork = f"P{amount_worked}D"
|
||||
|
||||
def get_unit_consumed(self):
|
||||
duration = self.productivity.get("BaseQuantityConsumed", None)
|
||||
if not duration:
|
||||
return
|
||||
return ifcopenshell.util.date.ifc2datetime(duration)
|
||||
|
||||
def get_total_produced(self):
|
||||
total = 0
|
||||
for rel in self.settings["resource"].HasAssignments or []:
|
||||
if not rel.is_a("IfcRelAssignsToProcess"):
|
||||
continue
|
||||
for rel2 in rel.RelatingProcess.HasAssignments or []:
|
||||
if not rel2.is_a("IfcRelAssignsToProduct"):
|
||||
continue
|
||||
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)
|
||||
return total
|
||||
self.settings["resource"].Usage.ScheduleWork = amount_worked
|
||||
|
||||
@@ -51,7 +51,10 @@ class Usecase:
|
||||
physical_quantity=time, attributes={"TimeValue": 8.0})
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"physical_quantity": physical_quantity, "attributes": attributes or {}}
|
||||
self.settings = {
|
||||
"physical_quantity": physical_quantity,
|
||||
"attributes": attributes or {},
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
for name, value in self.settings["attributes"].items():
|
||||
|
||||
Reference in New Issue
Block a user