updating a duration will not auto update schedule usage

This commit is contained in:
Sigma Dimensions (Yass)
2023-08-24 15:51:33 +01:00
parent dd02925cc4
commit a29ae07b72
15 changed files with 60 additions and 53 deletions
@@ -31,14 +31,7 @@ class Usecase:
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"
):
if ifcopenshell.util.constraint.is_attribute_locked(self.settings["resource"], "Usage.ScheduleUsage"):
return
if (
not self.settings["resource"].Usage
@@ -60,7 +60,7 @@ class Usecase:
self.settings = {"resource": resource}
def execute(self):
if self.has_hard_constraint():
if ifcopenshell.util.constraint.is_attribute_locked(self.settings["resource"], "Usage.ScheduleWork"):
return
amount_worked = ifcopenshell.util.resource.get_resource_required_work(
self.settings["resource"]
@@ -74,15 +74,3 @@ class Usecase:
resource=self.settings["resource"],
)
self.settings["resource"].Usage.ScheduleWork = amount_worked
def has_hard_constraint(self):
metrics = ifcopenshell.util.constraint.has_metric_constraints(
self.settings["resource"], "Usage.ScheduleWork"
)
if (
metrics
and metrics[0].ConstraintGrade == "HARD"
and metrics[0].Benchmark == "EQUALTO"
):
return True
return False
@@ -77,10 +77,10 @@ class Usecase:
del self.settings["attributes"]["ActualFinish"]
for name, value in self.settings["attributes"].items():
metrics = ifcopenshell.util.constraint.has_metric_constraints(
metrics = ifcopenshell.util.constraint.get_metric_constraints(
self.resource, "Usage." + name
)
if metrics and self.is_hard_constraint(metrics[0]):
if metrics and ifcopenshell.util.constraint.is_hard_constraint(metrics[0]):
continue
if value:
if "Start" in name or "Finish" in name or name == "StatusTime":
@@ -94,7 +94,7 @@ class Usecase:
setattr(self.settings["resource_time"], name, value)
if (
name == "ScheduleUsage"
and ifcopenshell.util.constraint.has_metric_constraints(
and ifcopenshell.util.constraint.get_metric_constraints(
self.resource, "Usage.ScheduleWork"
)
):
@@ -104,9 +104,6 @@ class Usecase:
"sequence.calculate_task_duration", self.file, task=task
)
def is_hard_constraint(self, metric):
return bool(metric.ConstraintGrade == "HARD" and metric.Benchmark == "EQUALTO")
def get_resource(self):
return [
e
@@ -125,6 +125,8 @@ class Usecase:
or "ScheduleDuration" in self.settings["attributes"].keys()
):
ifcopenshell.api.run("sequence.cascade_schedule", self.file, task=self.task)
if self.settings["task_time"].ScheduleDuration:
self.handle_resource_calculation()
def calculate_finish(self):
finish = ifcopenshell.util.sequence.get_start_or_finish_date(
@@ -173,3 +175,12 @@ class Usecase:
for e in self.file.get_inverse(self.settings["task_time"])
if e.is_a("IfcTask")
][0]
def handle_resource_calculation(self):
resources = ifcopenshell.util.sequence.get_task_resources(self.task, is_deep=False)
for resource in resources:
if ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleWork"):
ifcopenshell.api.run("resource.calculate_resource_usage", self.file, resource=resource)
#TODO: If the duration changes, this implies the productivity rate must change to accomModate the new Schedule Work to be calculated.
# elif ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleUsage"):
# ifcopenshell.api.run("resource.calculate_resource_work", self.file, resource=resource)