From 39d072d0ca91313397c6509d703cf18355c09efb Mon Sep 17 00:00:00 2001 From: "Sigma Dimensions (Yass)" <79010126+myoualid@users.noreply.github.com> Date: Wed, 23 Aug 2023 21:19:16 +0100 Subject: [PATCH] Calculates the number of resources based on required person-hours. --- .../api/resource/calculate_resource_usage.py | 71 +++++++++++++++++++ .../ifcopenshell/util/resource.py | 6 ++ 2 files changed, 77 insertions(+) create mode 100644 src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_usage.py diff --git a/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_usage.py b/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_usage.py new file mode 100644 index 0000000000..1137b23cf3 --- /dev/null +++ b/src/ifcopenshell-python/ifcopenshell/api/resource/calculate_resource_usage.py @@ -0,0 +1,71 @@ +# IfcOpenShell - IFC toolkit and geometry engine +# Copyright (C) 2021 Dion Moult +# +# This file is part of IfcOpenShell. +# +# IfcOpenShell is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# IfcOpenShell is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with IfcOpenShell. If not, see . + +import math +import ifcopenshell.api +import ifcopenshell.util.date +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 execute(self): + metrics = ifcopenshell.util.constraint.has_metric_constraints( + self.settings["resource"], "Usage.ScheduleUsage" + ) + if ( + metrics + and metrics[0].ConstraintGrade == "HARD" + and metrics[0].Benchmark == "EQUALTO" + ): + return + if ( + not self.settings["resource"].Usage + or not self.settings["resource"].Usage.ScheduleWork + ): + return + + task = ifcopenshell.util.resource.get_task_assignments( + self.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 + + 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 + ) + + required_resources = person_hours.total_seconds() / seconds + self.settings["resource"].Usage.ScheduleUsage = float(required_resources) diff --git a/src/ifcopenshell-python/ifcopenshell/util/resource.py b/src/ifcopenshell-python/ifcopenshell/util/resource.py index 477a4e2af6..f4ce388dc5 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/resource.py +++ b/src/ifcopenshell-python/ifcopenshell/util/resource.py @@ -84,6 +84,12 @@ def get_parametric_resource_products(resource): products.append(rel2.RelatingProduct) return products +def get_task_assignments(resource): + for rel in resource.HasAssignments or []: + if not rel.is_a("IfcRelAssignsToProcess"): + continue + return rel.RelatingProcess + def get_resource_required_work(resource): productivity = get_productivity(resource)