docs: def log_to_raw_structure(execution_history_items):
      """
      :param dict execution_history_items: history items, in the simplest case
             directly the opened shelve log file
      :return: start_item, the StateMachineStartItem of the log file
               previous, a dict mapping history_item_id --> history_item_id of previous history item
               next_, a dict mapping history_item_id --> history_item_id of the next history item (except if
                      next item is a concurrent execution branch)
               concurrent, a dict mapping history_item_id --> []list of concurrent next history_item_ids
                           (if present)
               grouped, a dict mapping run_id --> []list of history items with this run_id
      :rtype: tuple
      """
      previous = {}
      next_ = {}
      concurrent = {}
      grouped_by_run_id = {}
      start_item = None
  
      for k,v in execution_history_items.items():
          if v['item_type'] == 'StateMachineStartItem':
              start_item = v
          else:
              # connect the item to its predecessor
              prev_item_id = native_str(v['prev_history_item_id'])
  
              if prev_item_id in execution_history_items:
                  ## should always be the case except if shelve is broken/missing data
  
                  previous[k] = prev_item_id
                  if execution_history_items[prev_item_id]['item_type'] == 'ConcurrencyItem' and \
                     execution_history_items[k]['item_type'] != 'ReturnItem':
                      # this is not a return  item, thus this 'previous' relationship of this
                      # item must be a call item of one of the concurrent branches of
                      # the concurrency state
                      if prev_item_id in concurrent:
                          concurrent[prev_item_id].append(k)
                      else:
                          concurrent[prev_item_id] = [k]
                  else:
                      # this is a logical 'next' relationship
                      next_[prev_item_id] = k
              else:
                  logger.warning('HistoryItem is referring to a non-existing previous history item, HistoryItem was %s' % str(v))
  
          rid = v['run_id']
          if rid in grouped_by_run_id:
              grouped_by_run_id[rid].append(v)
          else:
              grouped_by_run_id[rid] = [v]
  
      return start_item, previous, next_, concurrent, grouped_by_run_id