Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/sequence/edit_task_time.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
2.5 KiB
Python
Raw Normal View History

import datetime
2021-04-20 17:11:06 +10:00
import ifcopenshell.util.date
import ifcopenshell.util.sequence
2021-04-20 17:11:06 +10:00
2021-04-20 05:12:13 +00:00
class Usecase:
def __init__(self, file, **settings):
self.file = file
2021-04-20 17:11:06 +10:00
self.settings = {"task_time": None, "attributes": {}}
2021-04-20 05:12:13 +00:00
for key, value in settings.items():
self.settings[key] = value
def execute(self):
# If the user specifies both an end date and a duration, the duration takes priority
2021-05-14 23:25:54 +00:00
if "ScheduleDuration" in self.settings["attributes"].keys():
if self.settings["task_time"].ScheduleFinish:
del self.settings["attributes"]["ScheduleFinish"]
if "ActualDuration" in self.settings["attributes"].keys():
del self.settings["attributes"]["ActualFinish"]
2021-04-20 05:12:13 +00:00
for name, value in self.settings["attributes"].items():
if value:
if "Start" in name or "Finish" in name or name == "StatusTime":
2021-04-20 17:11:06 +10:00
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDateTime")
elif name == "ScheduleDuration" or name == "ActualDuration" or name == "RemainingTime":
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDuration")
2021-04-20 17:11:06 +10:00
setattr(self.settings["task_time"], name, value)
if (
"ScheduleDuration" in self.settings["attributes"].keys()
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
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]
calendar = ifcopenshell.util.sequence.derive_calendar(task)
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")