Calculates the number of resources based on required person-hours.

This commit is contained in:
Sigma Dimensions (Yass)
2023-08-23 21:19:16 +01:00
parent 4e31a87c20
commit 52ea4ff44d
2 changed files with 77 additions and 0 deletions
@@ -0,0 +1,71 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# 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 <http://www.gnu.org/licenses/>.
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)
@@ -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)