mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-02 04:59:52 +00:00
Improved date calculations during import and editing ensure that start / finish dates are always on working days.
This commit is contained in:
@@ -126,7 +126,7 @@ def updateTaskduration(self, context):
|
|||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file())
|
Data.load(IfcStore.get_file())
|
||||||
if props.active_task_id == self.ifc_definition_id:
|
if props.active_task_id == self.ifc_definition_id:
|
||||||
attribute = props.task_attributes.get("Duration")
|
attribute = props.task_time_attributes.get("Duration")
|
||||||
attribute.string_value = self.duration
|
attribute.string_value = self.duration
|
||||||
bpy.ops.bim.load_task_properties(task=props.active_task_id)
|
bpy.ops.bim.load_task_properties(task=props.active_task_id)
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,27 @@ class Usecase:
|
|||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
# If the user specifies both an end date and a duration, the duration takes priority
|
# If the user specifies both an end date and a duration, the duration takes priority
|
||||||
if "ScheduleDuration" in self.settings["attributes"].keys() and "ScheduleFinish" in self.settings["attributes"].keys():
|
if (
|
||||||
|
"ScheduleDuration" in self.settings["attributes"].keys()
|
||||||
|
and "ScheduleFinish" in self.settings["attributes"].keys()
|
||||||
|
):
|
||||||
del self.settings["attributes"]["ScheduleFinish"]
|
del self.settings["attributes"]["ScheduleFinish"]
|
||||||
if "ActualDuration" in self.settings["attributes"].keys() and "ActualFinish" in self.settings["attributes"].keys():
|
if (
|
||||||
|
"ActualDuration" in self.settings["attributes"].keys()
|
||||||
|
and "ActualFinish" in self.settings["attributes"].keys()
|
||||||
|
):
|
||||||
del self.settings["attributes"]["ActualFinish"]
|
del self.settings["attributes"]["ActualFinish"]
|
||||||
|
|
||||||
|
duration_type = self.settings["attributes"].get("DurationType", self.settings["task_time"].DurationType)
|
||||||
|
if "ScheduleFinish" in self.settings["attributes"]:
|
||||||
|
self.settings["attributes"]["ScheduleFinish"] = ifcopenshell.util.sequence.get_soonest_working_day(
|
||||||
|
self.settings["attributes"]["ScheduleFinish"], duration_type, self.get_calendar()
|
||||||
|
)
|
||||||
|
if "ScheduleStart" in self.settings["attributes"]:
|
||||||
|
self.settings["attributes"]["ScheduleStart"] = ifcopenshell.util.sequence.get_soonest_working_day(
|
||||||
|
self.settings["attributes"]["ScheduleStart"], duration_type, self.get_calendar()
|
||||||
|
)
|
||||||
|
|
||||||
for name, value in self.settings["attributes"].items():
|
for name, value in self.settings["attributes"].items():
|
||||||
if value:
|
if value:
|
||||||
if "Start" in name or "Finish" in name or name == "StatusTime":
|
if "Start" in name or "Finish" in name or name == "StatusTime":
|
||||||
@@ -37,21 +53,13 @@ class Usecase:
|
|||||||
self.calculate_duration()
|
self.calculate_duration()
|
||||||
|
|
||||||
def calculate_finish(self):
|
def calculate_finish(self):
|
||||||
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
|
finish_date = ifcopenshell.util.sequence.get_finish_date(
|
||||||
current_date = datetime.date(start.year, start.month, start.day)
|
ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart),
|
||||||
duration = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleDuration).days
|
ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleDuration),
|
||||||
|
self.settings["task_time"].DurationType,
|
||||||
calendar = self.get_calendar()
|
self.get_calendar(),
|
||||||
|
)
|
||||||
while duration >= 0:
|
self.settings["task_time"].ScheduleFinish = ifcopenshell.util.date.datetime2ifc(finish_date, "IfcDateTime")
|
||||||
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")
|
|
||||||
|
|
||||||
def calculate_duration(self):
|
def calculate_duration(self):
|
||||||
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
|
start = ifcopenshell.util.date.ifc2datetime(self.settings["task_time"].ScheduleStart)
|
||||||
|
|||||||
+10
-10
@@ -70,7 +70,7 @@ class P62Ifc:
|
|||||||
exceptions = {}
|
exceptions = {}
|
||||||
holiday_or_exceptions = calendar.find("pr:HolidayOrExceptions", self.ns)
|
holiday_or_exceptions = calendar.find("pr:HolidayOrExceptions", self.ns)
|
||||||
holiday_or_exception = []
|
holiday_or_exception = []
|
||||||
if holiday_or_exceptions:
|
if holiday_or_exceptions is not None:
|
||||||
holiday_or_exception = holiday_or_exceptions.findall("pr:HolidayOrException", self.ns)
|
holiday_or_exception = holiday_or_exceptions.findall("pr:HolidayOrException", self.ns)
|
||||||
for exception in holiday_or_exception:
|
for exception in holiday_or_exception:
|
||||||
d = datetime.datetime.fromisoformat(exception.find("pr:Date", self.ns).text).date()
|
d = datetime.datetime.fromisoformat(exception.find("pr:Date", self.ns).text).date()
|
||||||
@@ -337,6 +337,15 @@ class P62Ifc:
|
|||||||
)
|
)
|
||||||
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=activity["ifc"])
|
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=activity["ifc"])
|
||||||
calendar = self.calendars[activity["CalendarObjectId"]]
|
calendar = self.calendars[activity["CalendarObjectId"]]
|
||||||
|
# Seems intermittently crashy - can we investigate for larger files?
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"control.assign_control",
|
||||||
|
self.file,
|
||||||
|
**{
|
||||||
|
"relating_control": calendar["ifc"],
|
||||||
|
"related_object": activity["ifc"],
|
||||||
|
},
|
||||||
|
)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"sequence.edit_task_time",
|
"sequence.edit_task_time",
|
||||||
self.file,
|
self.file,
|
||||||
@@ -353,15 +362,6 @@ class P62Ifc:
|
|||||||
else None,
|
else None,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# Seems intermittently crashy - can we investigate for larger files?
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"control.assign_control",
|
|
||||||
self.file,
|
|
||||||
**{
|
|
||||||
"relating_control": calendar["ifc"],
|
|
||||||
"related_object": activity["ifc"],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
def create_rel_sequences(self):
|
def create_rel_sequences(self):
|
||||||
self.sequence_type_map = {
|
self.sequence_type_map = {
|
||||||
|
|||||||
Reference in New Issue
Block a user