mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
fix editing null task duration values #3091
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
import isodate
|
||||
from dateutil import parser
|
||||
import ifcopenshell.util.date as ifcdateutils
|
||||
import ifcopenshell.util.date
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ def canonicalise_time(time):
|
||||
def parse_duration_as_blender_props(dt, simplify=True):
|
||||
if simplify:
|
||||
if isinstance(dt, str):
|
||||
dt = ifcdateutils.ifc2datetime(dt)
|
||||
dt = ifcopenshell.util.date.ifc2datetime(dt)
|
||||
|
||||
seconds = getattr(dt, "seconds", 0)
|
||||
hours, seconds = divmod(seconds, 3600)
|
||||
@@ -66,7 +66,7 @@ def parse_duration_as_blender_props(dt, simplify=True):
|
||||
}
|
||||
|
||||
|
||||
def simplify_duration(durations_attributes, duration_type, prop_name):
|
||||
def blender_props_to_iso_duration(durations_attributes, duration_type, prop_name):
|
||||
duration_props = None
|
||||
for collection in durations_attributes:
|
||||
if collection.name == prop_name:
|
||||
@@ -81,7 +81,7 @@ def simplify_duration(durations_attributes, duration_type, prop_name):
|
||||
duration_props.minutes if duration_props.minutes else 0,
|
||||
duration_props.seconds if duration_props.seconds else 0,
|
||||
)
|
||||
duration_object = ifcdateutils.ifc2datetime(duration_string)
|
||||
duration_object = ifcopenshell.util.date.ifc2datetime(duration_string)
|
||||
elif duration_props and duration_type == "WORKTIME":
|
||||
years = (duration_props.years * 365 * 24 * 60 * 60) if duration_props.years else 0
|
||||
months = (duration_props.months * 30 * 24 * 60 * 60) if duration_props.months else 0
|
||||
@@ -98,6 +98,8 @@ def simplify_duration(durations_attributes, duration_type, prop_name):
|
||||
extra_days, seconds_left = divmod(total_seconds, calendar_seconds_per_day)
|
||||
total_days = days_subtotal + extra_days
|
||||
duration_object = timedelta(days=total_days, seconds=seconds_left)
|
||||
else:
|
||||
return None
|
||||
if duration_object:
|
||||
total_days = int(duration_object.days)
|
||||
seconds_left = int(duration_object.seconds)
|
||||
@@ -115,20 +117,21 @@ def simplify_duration(durations_attributes, duration_type, prop_name):
|
||||
|
||||
hours, seconds = divmod(seconds_left, 3600)
|
||||
minutes, seconds = divmod(seconds, 60)
|
||||
|
||||
duration_string = "P"
|
||||
if years > 0:
|
||||
duration_string += "{}Y".format(int(years))
|
||||
if months > 0:
|
||||
duration_string += "{}M".format(int(months))
|
||||
if total_days > 0:
|
||||
duration_string += "{}D".format(int(total_days))
|
||||
if hours > 0 or minutes > 0 or seconds > 0:
|
||||
duration_string += "T"
|
||||
if hours > 0:
|
||||
duration_string += "{}H".format(int(hours))
|
||||
if minutes > 0:
|
||||
duration_string += "{}M".format(int(minutes))
|
||||
if seconds > 0:
|
||||
duration_string += "{}S".format(int(seconds))
|
||||
return duration_string
|
||||
if years > 0 or months > 0 or total_days > 0 or hours > 0 or minutes > 0 or seconds > 0:
|
||||
duration_string = "P"
|
||||
duration_string += "{}Y".format(int(years)) if years > 0 else ""
|
||||
duration_string += "{}M".format(int(months)) if months > 0 else ""
|
||||
duration_string += "{}D".format(int(total_days)) if total_days > 0 else ""
|
||||
if hours > 0 or minutes > 0 or seconds > 0:
|
||||
duration_string += "T"
|
||||
if hours > 0:
|
||||
duration_string += "{}H".format(int(hours))
|
||||
if minutes > 0:
|
||||
duration_string += "{}M".format(int(minutes))
|
||||
if seconds > 0:
|
||||
duration_string += "{}S".format(int(seconds))
|
||||
return duration_string
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -358,7 +358,7 @@ class Resource(blenderbim.core.tool.Resource):
|
||||
props = bpy.context.scene.BIMResourceProductivity
|
||||
productivity = {}
|
||||
if props.quantity_consumed:
|
||||
productivity["BaseQuantityConsumed"] = helper.simplify_duration(
|
||||
productivity["BaseQuantityConsumed"] = helper.blender_props_to_iso_duration(
|
||||
props.quantity_consumed, "ELAPSEDTIME", "BaseQuantityConsumed"
|
||||
)
|
||||
productivity["BaseQuantityProducedValue"] = props.quantity_produced
|
||||
|
||||
@@ -394,7 +394,7 @@ class Sequence(blenderbim.core.tool.Sequence):
|
||||
return True
|
||||
else:
|
||||
duration_type = attributes["DurationType"] if "DurationType" in attributes else None
|
||||
time_split_iso_duration = helper.simplify_duration(
|
||||
time_split_iso_duration = helper.blender_props_to_iso_duration(
|
||||
props.durations_attributes, duration_type, prop.name
|
||||
)
|
||||
attributes[prop.name] = time_split_iso_duration
|
||||
|
||||
Reference in New Issue
Block a user