mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-10 06:00:51 +00:00
Updating a task duration now auto calculates the scheduled finish times based on the working calendar
This commit is contained in:
@@ -5,78 +5,6 @@ from dateutil import parser
|
||||
from ifcopenshell.api.sequence.data import Data
|
||||
|
||||
|
||||
def count_working_days(start, finish, calendar):
|
||||
result = 0
|
||||
current_date = datetime.date(start.year, start.month, start.day)
|
||||
finish_date = datetime.date(finish.year, finish.month, finish.day)
|
||||
while current_date <= finish_date:
|
||||
if is_working_day(current_date, calendar):
|
||||
result += 1
|
||||
current_date += datetime.timedelta(days=1)
|
||||
return result
|
||||
|
||||
|
||||
def is_working_day(day, calendar):
|
||||
is_working_day = False
|
||||
for work_time_id in calendar["WorkingTimes"] or []:
|
||||
if is_work_time_applicable_to_day(Data.work_times[work_time_id], day):
|
||||
is_working_day = True
|
||||
break
|
||||
if not is_working_day:
|
||||
return is_working_day
|
||||
for work_time_id in calendar["ExceptionTimes"] or []:
|
||||
if is_work_time_applicable_to_day(Data.work_times[work_time_id], day):
|
||||
is_working_day = False
|
||||
break
|
||||
return is_working_day
|
||||
|
||||
|
||||
def is_work_time_applicable_to_day(work_time, day):
|
||||
if work_time["Start"] and work_time["Start"] > day:
|
||||
return False
|
||||
|
||||
if work_time["Finish"] and work_time["Finish"] < day:
|
||||
return False
|
||||
|
||||
if not work_time["RecurrencePattern"]:
|
||||
return True
|
||||
|
||||
recurrence = Data.recurrence_patterns[work_time["RecurrencePattern"]]
|
||||
|
||||
if recurrence["RecurrenceType"] == "DAILY":
|
||||
if not recurrence["Interval"] and not recurrence["Occurrences"]:
|
||||
return True
|
||||
if not work_time["Start"]:
|
||||
return False
|
||||
return False # TODO
|
||||
elif recurrence["RecurrenceType"] == "WEEKLY":
|
||||
if not recurrence["Interval"] and not recurrence["Occurrences"]:
|
||||
return (day.weekday() + 1) in recurrence["WeekdayComponent"]
|
||||
if not work_time["Start"]:
|
||||
return False
|
||||
return False # TODO
|
||||
elif recurrence["RecurrenceType"] == "MONTHLY_BY_DAY_OF_MONTH":
|
||||
if not recurrence["Interval"] and not recurrence["Occurrences"]:
|
||||
return day.day in recurrence["DayComponent"]
|
||||
return False # TODO
|
||||
elif recurrence["RecurrenceType"] == "MONTHLY_BY_POSITION":
|
||||
if not recurrence["Interval"] and not recurrence["Occurrences"]:
|
||||
return (day.weekday() + 1) in recurrence["WeekdayComponent"] and math.floor(day.day / 7) + 1 == recurrence[
|
||||
"Position"
|
||||
]
|
||||
return False # TODO
|
||||
elif recurrence["RecurrenceType"] == "YEARLY_BY_DAY_OF_MONTH":
|
||||
if not recurrence["Interval"] and not recurrence["Occurrences"]:
|
||||
return day.month in recurrence["MonthComponent"] and day.day in recurrence["DayComponent"]
|
||||
return False # TODO
|
||||
elif recurrence["RecurrenceType"] == "YEARLY_BY_POSITION":
|
||||
if not recurrence["Interval"] and not recurrence["Occurrences"]:
|
||||
return (
|
||||
day.month in recurrence["MonthComponent"]
|
||||
and (day.weekday() + 1) in recurrence["WeekdayComponent"]
|
||||
and math.floor(day.day / 7) + 1 == recurrence["Position"]
|
||||
)
|
||||
return False # TODO
|
||||
|
||||
|
||||
def derive_date(ifc_definition_id, attribute_name, date=None, is_earliest=False, is_latest=False):
|
||||
@@ -96,14 +24,6 @@ def derive_date(ifc_definition_id, attribute_name, date=None, is_earliest=False,
|
||||
return date
|
||||
|
||||
|
||||
def derive_calendar(ifc_definition_id):
|
||||
task = Data.tasks[ifc_definition_id]
|
||||
if task["HasAssignmentsWorkCalendar"]:
|
||||
return Data.work_calendars[task["HasAssignmentsWorkCalendar"][0]]
|
||||
if task["Nests"]:
|
||||
return derive_calendar(task["Nests"][0])
|
||||
|
||||
|
||||
def derive_duration(ifc_definition_id, attribute_name):
|
||||
task = Data.tasks[ifc_definition_id]
|
||||
if task["TaskTime"]:
|
||||
|
||||
@@ -8,6 +8,7 @@ import pystache
|
||||
import webbrowser
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.util.date
|
||||
import ifcopenshell.util.sequence
|
||||
import blenderbim.bim.helper
|
||||
import blenderbim.bim.module.sequence.helper as helper
|
||||
from datetime import datetime
|
||||
@@ -275,6 +276,7 @@ class LoadTaskProperties(bpy.types.Operator):
|
||||
task: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.file = IfcStore.get_file()
|
||||
self.props = context.scene.BIMWorkScheduleProperties
|
||||
self.tprops = context.scene.BIMTaskTreeProperties
|
||||
self.props.is_task_update_enabled = False
|
||||
@@ -292,7 +294,9 @@ class LoadTaskProperties(bpy.types.Operator):
|
||||
Data.sequences[r]["RelatingProcess"] for r in task["IsSuccessorFrom"]
|
||||
]
|
||||
|
||||
calendar = helper.derive_calendar(item.ifc_definition_id)
|
||||
calendar = ifcopenshell.util.sequence.derive_calendar(self.file.by_id(item.ifc_definition_id))
|
||||
if calendar:
|
||||
calendar = Data.work_calendars[calendar.id()]
|
||||
if task["HasAssignmentsWorkCalendar"]:
|
||||
item.calendar = calendar["Name"] or "Unnamed"
|
||||
else:
|
||||
@@ -312,7 +316,9 @@ class LoadTaskProperties(bpy.types.Operator):
|
||||
item.derived_start = self.canonicalise_time(derived_start) if derived_start else ""
|
||||
item.derived_finish = self.canonicalise_time(derived_finish) if derived_finish else ""
|
||||
if derived_start and derived_finish and calendar:
|
||||
derived_duration = helper.count_working_days(derived_start, derived_finish, calendar)
|
||||
derived_duration = ifcopenshell.util.sequence.count_working_days(
|
||||
derived_start, derived_finish, self.file.by_id(calendar["id"])
|
||||
)
|
||||
item.derived_duration = f"P{derived_duration}D"
|
||||
item.start = "-"
|
||||
item.finish = "-"
|
||||
@@ -460,7 +466,6 @@ class EditTaskTime(bpy.types.Operator):
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMWorkScheduleProperties
|
||||
attributes = blenderbim.bim.helper.export_attributes(props.task_time_attributes, self.export_attributes)
|
||||
attributes = self.convert_strings_to_date_times(attributes)
|
||||
|
||||
self.file = IfcStore.get_file()
|
||||
ifcopenshell.api.run(
|
||||
@@ -475,10 +480,10 @@ class EditTaskTime(bpy.types.Operator):
|
||||
|
||||
def export_attributes(self, attributes, prop):
|
||||
if "Start" in prop.name or "Finish" in prop.name or prop.name == "StatusTime":
|
||||
attributes[prop.name] = helper.parse_datetime(value)
|
||||
attributes[prop.name] = helper.parse_datetime(prop.string_value)
|
||||
return True
|
||||
elif prop.name == "ScheduleDuration":
|
||||
attributes[prop.name] = helper.parse_duration(value)
|
||||
attributes[prop.name] = helper.parse_duration(prop.string_value)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user