def parseMetricFile()

in tooling/query-metrics-alerts/parse_analysis.py [0:0]


def parseMetricFile(file):
  metrics = {}

  with open(file, 'r', encoding="utf-8") as f:
    lines = f.readlines()

  # Remove lines that don't begin with |
  lines = [line for line in lines if line.startswith('|')]

  # remove second line
  lines.pop(1)

  header = lines[0].split('|')
  header = [item.strip() for item in header if  item.strip() != '']

  for line in lines[1:]:
    line = line.split('|')
    line = line[1:-1]
    line = [item.strip() for item in line]

    metric = {}
    for i in range(len(header)):
      metric[header[i]] = line[i]

    metric['Description'] = metric.pop("Metric").split('<p>')[-1]
    key = metric['Name'].replace('`',  '')
    metric.pop('Name')

    metrics[key] = metric

  return metrics