def GatherResultsFromMultipleFiles(results_by_file):
  """Gather multiple results to organize them by check name and file name.

  Args:
    results_by_file: A dict of check results indexed by file name.

  Returns:
    A dict of check results in the form of:
    {`check_name`: {`file_name`: {
        'warning': {
            'range': [lower_bound, upper_bound]
            'count': number of occurrences that fall into the range,
            'total': total number of data points,
        },
        'error': ...
    }}}
  """

  merged = {}
  for filename, results in results_by_file.iteritems():
    if results:
      for check_name, values in results.iteritems():
        if check_name not in merged:
          merged[check_name] = {filename: values}
        else:
          merged[check_name][filename] = values
  return merged