Updating either a duration, start, or finish date for a task now auto-updates the other attribute

This commit is contained in:
Dion Moult
2021-05-31 12:42:02 +10:00
parent c041dd13ad
commit 452631b997
2 changed files with 43 additions and 17 deletions
@@ -30,24 +30,48 @@ class Usecase:
and self.settings["task_time"].ScheduleDuration
and self.settings["task_time"].ScheduleStart
):
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
current_date = datetime.date(start.year, start.month, start.day)
duration = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleDuration).days
self.calculate_finish()
elif "ScheduleStart" in self.settings["attributes"].keys() and self.settings["task_time"].ScheduleDuration:
self.calculate_finish()
elif "ScheduleFinish" in self.settings["attributes"].keys() and self.settings["task_time"].ScheduleStart:
self.calculate_duration()
task = [e for e in self.file.get_inverse(self.settings["task_time"]) if e.is_a("IfcTask")]
if not task:
return
else:
task = task[0]
def calculate_finish(self):
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
current_date = datetime.date(start.year, start.month, start.day)
duration = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleDuration).days
calendar = ifcopenshell.util.sequence.derive_calendar(task)
calendar = self.get_calendar()
while duration >= 0:
if self.settings["task_time"].DurationType == "ELAPSEDTIME" or not calendar:
duration -= 1
elif ifcopenshell.util.sequence.is_working_day(current_date, calendar):
duration -= 1
current_date += datetime.timedelta(days=1)
while duration >= 0:
if self.settings["task_time"].DurationType == "ELAPSEDTIME" or not calendar:
duration -= 1
elif ifcopenshell.util.sequence.is_working_day(current_date, calendar):
duration -= 1
current_date += datetime.timedelta(days=1)
current_date -= datetime.timedelta(days=1)
self.settings["task_time"].ScheduleFinish = ifcopenshell.util.date.datetime2ifc(current_date, "IfcDateTime")
current_date -= datetime.timedelta(days=1)
self.settings["task_time"].ScheduleFinish = ifcopenshell.util.date.datetime2ifc(current_date, "IfcDateTime")
def calculate_duration(self):
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
finish = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleFinish)
current_date = datetime.date(start.year, start.month, start.day)
finish_date = datetime.date(finish.year, finish.month, finish.day)
calendar = self.get_calendar()
duration = datetime.timedelta()
while current_date < finish_date:
if self.settings["task_time"].DurationType == "ELAPSEDTIME" or not calendar:
duration += datetime.timedelta(days=1)
elif ifcopenshell.util.sequence.is_working_day(current_date, calendar):
duration += datetime.timedelta(days=1)
current_date += datetime.timedelta(days=1)
self.settings["task_time"].ScheduleDuration = ifcopenshell.util.date.datetime2ifc(duration, "IfcDuration")
def get_calendar(self):
task = [e for e in self.file.get_inverse(self.settings["task_time"]) if e.is_a("IfcTask")]
if not task:
return
else:
task = task[0]
return ifcopenshell.util.sequence.derive_calendar(task)