mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 10:57:49 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -23,42 +23,29 @@ import ifcopenshell.util.element
|
||||
import ifcopenshell.util.resource
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, resource=None):
|
||||
"""Calculates the number of resources required to perform scheduled work on a task.
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"resource": resource}
|
||||
def calculate_resource_usage(file, resource=None) -> None:
|
||||
"""Calculates the number of resources required to perform scheduled work on a task."""
|
||||
settings = {"resource": resource}
|
||||
|
||||
def execute(self):
|
||||
if ifcopenshell.util.constraint.is_attribute_locked(self.settings["resource"], "Usage.ScheduleUsage"):
|
||||
return
|
||||
if (
|
||||
not self.settings["resource"].Usage
|
||||
or not self.settings["resource"].Usage.ScheduleWork
|
||||
):
|
||||
return
|
||||
if ifcopenshell.util.constraint.is_attribute_locked(settings["resource"], "Usage.ScheduleUsage"):
|
||||
return
|
||||
if not settings["resource"].Usage or not settings["resource"].Usage.ScheduleWork:
|
||||
return
|
||||
|
||||
task = ifcopenshell.util.resource.get_task_assignments(
|
||||
self.settings["resource"]
|
||||
)
|
||||
if not task or not task.TaskTime:
|
||||
return
|
||||
task = ifcopenshell.util.resource.get_task_assignments(settings["resource"])
|
||||
if not task or not task.TaskTime:
|
||||
return
|
||||
|
||||
if not task.TaskTime.DurationType or task.TaskTime.DurationType == "WORKTIME":
|
||||
hours_per_day = 8
|
||||
else:
|
||||
hours_per_day = 24
|
||||
if not task.TaskTime.DurationType or task.TaskTime.DurationType == "WORKTIME":
|
||||
hours_per_day = 8
|
||||
else:
|
||||
hours_per_day = 24
|
||||
|
||||
task_duration = ifcopenshell.util.date.ifc2datetime(
|
||||
task.TaskTime.ScheduleDuration
|
||||
)
|
||||
seconds = task_duration.days * hours_per_day * 60 * 60
|
||||
seconds += task_duration.seconds
|
||||
task_duration = ifcopenshell.util.date.ifc2datetime(task.TaskTime.ScheduleDuration)
|
||||
seconds = task_duration.days * hours_per_day * 60 * 60
|
||||
seconds += task_duration.seconds
|
||||
|
||||
person_hours = ifcopenshell.util.date.ifc2datetime(
|
||||
self.settings["resource"].Usage.ScheduleWork
|
||||
)
|
||||
person_hours = ifcopenshell.util.date.ifc2datetime(settings["resource"].Usage.ScheduleWork)
|
||||
|
||||
required_resources = person_hours.total_seconds() / seconds
|
||||
self.settings["resource"].Usage.ScheduleUsage = float(required_resources)
|
||||
required_resources = person_hours.total_seconds() / seconds
|
||||
settings["resource"].Usage.ScheduleUsage = float(required_resources)
|
||||
|
||||
Reference in New Issue
Block a user