import json


def get_prefix_counts(filename):
  """Builds a dictionary mapping key prefixes to their counts.

  Args:
      filename: The name of a JSON file.

  Returns:
      A dictionary mapping each key prefix to its count.
  """
  prefixes = {}
  f = open(filename)
  keys = json.load(f)
  total = 0
  for key in keys:
    prefix = key.split('.')[0]
    if prefix != '@metadata':
      weight = 1
      if key.endswith('Tooltip'):
        weight = .2
      elif key.endswith('HelpUrl'):
        weight = .1
      prefixes[prefix] = prefixes.get(prefix, 0) + weight
      total += weight
  f.close()
  prefixes['ALL'] = total
  return prefixes