private static TableLayout layoutUserTable(
      TableLayoutBuilder master, MeasurementSuite measurements) {
    TableLayoutBuilder perUser = master.clone();
    perUser.addColumn("User");
    perUser.addColumn("TestTime");
    perUser.addColumn("TrainEvents");
    perUser.addColumn("TestEvents");

    for (MetricFactory<?> mf : measurements.getMetricFactories()) {
      List<String> userColumnLabels = mf.getUserColumnLabels();
      if (userColumnLabels != null) {
        for (String c : userColumnLabels) {
          perUser.addColumn(c);
        }
      }
    }

    return perUser.build();
  }
  private static TableLayout layoutAggregateOutput(
      TableLayoutBuilder master, MeasurementSuite measurements) {
    TableLayoutBuilder output = master.clone();
    output.addColumn("BuildTime");
    output.addColumn("TestTime");

    for (MetricFactory<?> mf : measurements.getMetricFactories()) {
      List<String> labels = mf.getColumnLabels();
      if (labels != null) {
        for (String c : labels) {
          output.addColumn(c);
        }
      }
    }

    return output.build();
  }
  /**
   * Create an experiment output layout.
   *
   * @param experiments The experiments.
   * @param measurements The measurements.
   * @return An output layout for the suite of experiments.
   */
  public static ExperimentOutputLayout create(
      ExperimentSuite experiments, MeasurementSuite measurements) {
    TableLayoutBuilder master = new TableLayoutBuilder();
    master.addColumn("Algorithm");
    Map<String, Integer> dataColumns = new HashMap<String, Integer>();
    for (String attr : experiments.getDataAttributes()) {
      dataColumns.put(attr, master.getColumnCount());
      master.addColumn(attr);
    }

    Map<String, Integer> algoColumns = new HashMap<String, Integer>();
    for (String attr : experiments.getAlgorithmAttributes()) {
      algoColumns.put(attr, master.getColumnCount());
      master.addColumn(attr);
    }

    TableLayout common = master.build();

    TableLayout results = layoutAggregateOutput(master, measurements);
    TableLayout user = layoutUserTable(master, measurements);

    return new ExperimentOutputLayout(common, dataColumns, algoColumns, results, user);
  }