Skip to content

Commit

Permalink
BUG: Reading serialized event requires conversion of dates
Browse files Browse the repository at this point in the history
This patch attempts to convert string date representations
back to datetime.date objects so that compuations
can be done on them.
  • Loading branch information
hjmjohnson committed Nov 15, 2023
1 parent 682abac commit b066807
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions nipype/utils/draw_gantt_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,26 @@ def log_to_dict(logfile):

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

def _convert_string_to_datetime(datestring):
try:
datetime_object: datetime.datetime = datetime.datetime.strptime(
datestring, "%Y-%m-%dT%H:%M:%S.%f"
)
return datetime_object
except Exception as _:
pass
return datestring

date_object_node_list: list = list()
for n in nodes_list:
if "start" in n.keys():
n["start"] = _convert_string_to_datetime(n["start"])
if "finish" in n.keys():
n["finish"] = _convert_string_to_datetime(n["finish"])
date_object_node_list.append(n)

# Return list of nodes
return nodes_list
return date_object_node_list


def calculate_resource_timeseries(events, resource):
Expand Down Expand Up @@ -514,7 +532,11 @@ def generate_gantt_chart(
# Create the header of the report with useful information
start_node = nodes_list[0]
last_node = nodes_list[-1]
duration = (last_node["finish"] - start_node["start"]).total_seconds()
duration: float = 0.0
if isinstance(start_node["start"], datetime.date) and isinstance(
last_node["finish"], datetime.date
):
duration = (last_node["finish"] - start_node["start"]).total_seconds()

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

0 comments on commit b066807

Please sign in to comment.