Generate functions for all API usecases for better static code features. See #2693.

This commit is contained in:
Dion Moult
2024-05-06 14:35:39 +10:00
parent 10f894e2ea
commit d11ec67129
330 changed files with 13283 additions and 13751 deletions
@@ -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)