code: def calculate_resource_timeseries(events, resource):
      """
      Given as event dictionary, calculate the resources used
      as a timeseries
  
      Parameters
      ----------
      events : dictionary
          a dictionary of event-based node dictionaries of the workflow
          execution statistics
      resource : string
          the resource of interest to return the time-series of;
          e.g. 'runtime_memory_gb', 'estimated_threads', etc
  
      Returns
      -------
      time_series : pandas Series
          a pandas Series object that contains timestamps as the indices
          and the resource amount as values
      """
  
      # Import packages
      import pandas as pd
  
      # Init variables
      res = OrderedDict()
      all_res = 0.0
  
      # Iterate through the events
      for _, event in sorted(events.items()):
          if event["event"] == "start":
              if resource in event and event[resource] != "Unknown":
                  all_res += float(event[resource])
              current_time = event["start"]
          elif event["event"] == "finish":
              if resource in event and event[resource] != "Unknown":
                  all_res -= float(event[resource])
              current_time = event["finish"]
          res[current_time] = all_res
  
      # Formulate the pandas timeseries
      time_series = pd.Series(
          data=list(res.values()), index=list(res.keys())
      )
      # Downsample where there is only value-diff
      ts_diff = time_series.diff()
      time_series = time_series[ts_diff != 0]
  
      # Return the new time series
      return time_series
  
file_path: nipype/nipype/utils/draw_gantt_chart.py
imports: import sys
  import random
  import datetime
  import simplejson
  from collections import OrderedDict
label_desc: Use image node_id 3 for calling a global function with example usage: calculate_resource_timeseries(events, resource) and returns: time_series