def annotateHistograms()

in lib/parser.py [0:0]


def annotateHistograms(config, probeIndex):
  histograms = config['histograms'].copy()
  config['histograms'] = {}
  for i,hist in enumerate(histograms):
    config['histograms'][hist] = {}
    hist_name = hist.split('.')[-1]

    # Annotate legacy probe.
    if hist_name.upper() in probeIndex["legacy"]:
      schema = probeIndex["legacy"][hist_name.upper()]
      config['histograms'][hist]["glean"] = False
      config['histograms'][hist]["desc"] = schema["description"]
      config['histograms'][hist]["available_on_desktop"] = True
      config['histograms'][hist]["available_on_android"] = False
      kind = schema["details"]["kind"]
      print(hist, kind)
      if kind=="categorical" or kind=="boolean" or kind=="enumerated":
        config['histograms'][hist]["kind"] = "categorical"
        if "labels" in schema["details"]:
          config['histograms'][hist]["labels"] = schema["details"]["labels"]
        elif kind=="boolean":
          config['histograms'][hist]["labels"] = ["no", "yes"]
        elif "n_buckets" in schema["details"]:
          n_buckets = schema["details"]["n_buckets"]
          config['histograms'][hist]["labels"] = list(range(0, n_buckets))
      else:
        config['histograms'][hist]["kind"] = "numerical"


    # Annotate glean probe.
    elif hist_name in probeIndex["glean"]:
      schema = probeIndex["glean"][hist_name]
      config['histograms'][hist]["glean"] = True
      config['histograms'][hist]["desc"] = schema["description"]
  
      # Mark if the probe is available on desktop or mobile.
      config['histograms'][hist]["available_on_desktop"] = False
      config['histograms'][hist]["available_on_android"] = False

      if "gecko" in schema["repos"]:
        config['histograms'][hist]["available_on_desktop"] = True
        config['histograms'][hist]["available_on_android"] = True
      elif "fenix" in schema["repos"]:
        config['histograms'][hist]["available_on_android"] = True
      elif "desktop" in schema["repos"]:
        config['histograms'][hist]["available_on_desktop"] = True

      # Only support timing distribution types for now.
      if schema["type"] == "timing_distribution":
        config['histograms'][hist]["kind"] = "numerical"
      else:
        type=schema["type"]
        print(f"ERROR: Type {type} for {hist_name} not currently supported.") 
        sys.exit(1)

      # Use the high and low values from the legacy mirror as bounds.
      if "telemetry_mirror" in probeIndex["glean"][hist_name]:
        legacy_mirror = probeIndex["glean"][hist_name]["telemetry_mirror"]
        high = probeIndex["legacy"][legacy_mirror]["details"]["high"]
        config['histograms'][hist]['max'] = high

    else:
      print(f"ERROR: {hist_name} not found in histograms schema.") 
      sys.exit(1)