Skip to content

Commit b066807

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

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

nipype/utils/draw_gantt_chart.py

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

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

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

109127

110128
def calculate_resource_timeseries(events, resource):
@@ -514,7 +532,11 @@ def generate_gantt_chart(
514532
# Create the header of the report with useful information
515533
start_node = nodes_list[0]
516534
last_node = nodes_list[-1]
517-
duration = (last_node["finish"] - start_node["start"]).total_seconds()
535+
duration: float = 0.0
536+
if isinstance(start_node["start"], datetime.date) and isinstance(
537+
last_node["finish"], datetime.date
538+
):
539+
duration = (last_node["finish"] - start_node["start"]).total_seconds()
518540

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

0 commit comments

Comments
 (0)