def createCategoricalComparison()

in lib/report.py [0:0]


  def createCategoricalComparison(self, segment, metric, metric_type):
    t = get_template("categorical.html")

    # If the histogram has too many buckets, then only display a 
    # set of interesting comparisons instead of all of them.
    indices = set()

    control = self.data["branches"][0]
    n_elem = len(self.data[control][segment][metric_type][metric]["ratios"])
    if n_elem <= 10:
      indices = set(range(0, n_elem-1))

    for branch in self.data["branches"]:
      if branch == control:
        continue
      uplift = self.data[branch][segment][metric_type][metric]["uplift"]
      ratios = self.data[branch][segment][metric_type][metric]["ratios"]
      ratios_control = self.data[control][segment][metric_type][metric]["ratios"]

      for i in range(len(uplift)):
        if abs(uplift[i]) > 0.01 and (ratios[i] >= 0.05 or ratios_control[i] >= 0.1):
          indices.add(i)

    datasets=[]
    for branch in self.data["branches"]:
      ratios_branch = [self.data[branch][segment][metric_type][metric]["ratios"][i] for i in indices]
      datasets.append({
        "branch": branch,
        "ratios": ratios_branch,
      })

      if branch != control:
        ratios_control = [self.data[control][segment][metric_type][metric]["ratios"][i] for i in indices]
        uplift = [self.data[branch][segment][metric_type][metric]["uplift"][i] for i in indices]
        datasets[-1]["uplift"] = uplift

    labels=[self.data[control][segment][metric_type][metric]["labels"][i] for i in indices]
    context = {
      "labels": labels,
      "datasets": datasets,
      "metric": metric,
      "segment": segment
        
    }
    self.doc(t.render(context))