Skip to content

Commit 89670b9

Browse files
committed
BUG: Reading serialized event requires conversion of dates
This patch attempts to convert string date representations back to datetime.date objects to that compuations can be done on them.
1 parent 5d436ba commit 89670b9

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Diff for: nipype/utils/draw_gantt_chart.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,26 @@ def log_to_dict(logfile):
104104

105105
nodes_list = [json.loads(l) for l in lines]
106106

107+
def _convert_string_to_datetime(datestring):
108+
try:
109+
datetime_object: datetime.datetime = datetime.datetime.strptime(
110+
datestring, "%Y-%m-%dT%H:%M:%S.%f"
111+
)
112+
return datetime_object
113+
except Exception as _:
114+
pass
115+
return datestring
116+
117+
date_object_node_list: list = list()
118+
for n in nodes_list:
119+
if "start" in n.keys():
120+
n["start"] = _convert_string_to_datetime(n["start"])
121+
if "finish" in n.keys():
122+
n["finish"] = _convert_string_to_datetime(n["finish"])
123+
date_object_node_list.append(n)
124+
107125
# Return list of nodes
108-
return nodes_list
126+
return date_object_node_list
109127

110128

111129
def calculate_resource_timeseries(events, resource):
@@ -515,7 +533,11 @@ def generate_gantt_chart(
515533
# Create the header of the report with useful information
516534
start_node = nodes_list[0]
517535
last_node = nodes_list[-1]
518-
duration = (last_node["finish"] - start_node["start"]).total_seconds()
536+
duration: float = 0.0
537+
if isinstance(start_node["start"], datetime.date) and isinstance(
538+
last_node["finish"], datetime.date
539+
):
540+
duration = (last_node["finish"] - start_node["start"]).total_seconds()
519541

520542
# Get events based dictionary of node run stats
521543
events = create_event_dict(start_node["start"], nodes_list)

0 commit comments

Comments
 (0)