private String getInputFor(ParameterType t, BulkParameterFactory f) {
   if (t.getType().isEnum()) {
     final StringBuilder ret = new StringBuilder();
     ret.append("<select name=\"").append(t.name()).append("\">");
     for (final Object o : t.getType().getEnumConstants()) {
       if (o.equals(f.getParam(t))) {
         ret.append("<option selected=\"selected\">");
       } else {
         ret.append("<option>");
       }
       ret.append(o.toString()).append("</option>");
     }
     ret.append("</select>");
     return ret.toString();
   } else if (t.getType().equals(Double.class)) {
     return "<input name=\""
         + t.name()
         + "\" value=\""
         + f.getParam(t)
         + "\" type=\"number\" step=\"any\" />";
   } else if (t.getType().equals(Integer.class)) {
     return "<input name=\""
         + t.name()
         + "\" value=\""
         + f.getParam(t)
         + "\" type=\"number\" step=\"1\" />";
   } else {
     return "Invalid type: " + t.getType();
   }
 }
  private BulkParameterFactory createRunDirectoryIfMissing(int requestId, int runNbr)
      throws IOException {
    assert runNbr > 0;

    BulkParameterFactory f = this.loadParameters(requestId);
    final ExperimentRunSettings s = this.loadSettings(requestId);
    for (int i = 1; i < runNbr; i++) {
      f = f.copyWithChangedSeed();
    }

    final File runDirectory = this.getRunDir(requestId, runNbr);
    synchronized (this) {
      if (!runDirectory.exists()) {
        runDirectory.mkdir();

        final int daysForStartup = (int) s.get(ExperimentRunParameters.WORKING_DAYS_FOR_STARTUP);
        final int daysForMeasurement =
            (int) s.get(ExperimentRunParameters.WORKING_DAYS_FOR_MEASUREMENT);

        DataGenerator.runExperiment(
            f, ReviewMode.NO_REVIEW, runDirectory, "run", daysForStartup, daysForMeasurement);
        DataGenerator.runExperiment(
            f, ReviewMode.PRE_COMMIT, runDirectory, "run", daysForStartup, daysForMeasurement);
        DataGenerator.runExperiment(
            f, ReviewMode.POST_COMMIT, runDirectory, "run", daysForStartup, daysForMeasurement);
      }
    }

    return f;
  }
 private BulkParameterFactory getParameters(PrintWriter w, HttpServletRequest request) {
   BulkParameterFactory f = BulkParameterFactory.forCommercial();
   for (final ParameterType t : ParameterType.values()) {
     final String param = request.getParameter(t.name());
     if (param != null && !param.isEmpty()) {
       try {
         f = f.copyWithChangedParam(t, t.parse(param));
       } catch (final RuntimeException e) {
         this.printParseError(w, t.toString(), e);
       }
     }
   }
   return f;
 }
  private BulkParameterFactory loadParameters(int requestId) throws IOException {
    final File requestDir = this.getRequestDir(requestId);
    final File paramsFile = new File(requestDir, PARAMS_PROPERTIES);
    try (FileInputStream in = new FileInputStream(paramsFile)) {
      final Properties properties = new Properties();
      properties.load(in);

      BulkParameterFactory ret = BulkParameterFactory.forCommercial();
      for (final String name : properties.stringPropertyNames()) {
        final ParameterType type = ParameterType.valueOf(name);
        ret = ret.copyWithChangedParam(type, type.parse(properties.getProperty(name)));
      }
      return ret;
    }
  }
 private Properties parametersToProperties(BulkParameterFactory f) {
   final Properties ret = new Properties();
   for (final ParameterType type : ParameterType.values()) {
     ret.setProperty(type.name(), f.getParam(type).toString());
   }
   return ret;
 }
  private void handleDetailsPage(
      HttpServletRequest request, HttpServletResponse response, int requestId, int runNbr)
      throws IOException {

    final BulkParameterFactory f = this.createRunDirectoryIfMissing(requestId, runNbr);

    response.setContentType("text/html;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    final PrintWriter w = response.getWriter();
    w.println("<h2>Details for run " + runNbr + "</h2>");
    w.println("<h3>Parameters</h3>");
    for (final ParameterType type : ParameterType.values()) {
      w.println(type + ": " + f.getParam(type) + "<br/>");
    }
    w.println("Seed: " + f.getSeed());

    w.println("<h3>Pre commit review</h3>");
    w.println(
        "<img src=\"ExperimentPRE_COMMIT_runplotBoard.png\" /><img src=\"ExperimentPRE_COMMIT_runplotResults.png\" /><br/>");
    w.println(
        "<iframe width=\"800\" height=\"400\" src=\"ExperimentPRE_COMMIT_run_report.html\">Report</iframe><br/>");
    w.println("<a href=\"ExperimentPRE_COMMIT_run_trace.html\">Trace</a><br/>");
    w.println("<a href=\"ExperimentPRE_COMMIT_run_error.html\">Error log</a><br/>");
    w.println("<a href=\"ExperimentPRE_COMMIT_run_debug.html\">Debug</a><br/>");

    w.println("<h3>Post commit review</h3>");
    w.println(
        "<img src=\"ExperimentPOST_COMMIT_runplotBoard.png\" /><img src=\"ExperimentPOST_COMMIT_runplotResults.png\" /><br/>");
    w.println(
        "<iframe width=\"800\" height=\"400\" src=\"ExperimentPOST_COMMIT_run_report.html\">Report</iframe><br/>");
    w.println("<a href=\"ExperimentPOST_COMMIT_run_trace.html\">Trace</a><br/>");
    w.println("<a href=\"ExperimentPOST_COMMIT_run_error.html\">Error log</a><br/>");
    w.println("<a href=\"ExperimentPOST_COMMIT_run_debug.html\">Debug</a><br/>");

    w.println("<h3>No review</h3>");
    w.println(
        "<img src=\"ExperimentNO_REVIEW_runplotBoard.png\" /><img src=\"ExperimentNO_REVIEW_runplotResults.png\" /><br/>");
    w.println(
        "<iframe width=\"800\" height=\"400\" src=\"ExperimentNO_REVIEW_run_report.html\">Report</iframe><br/>");
    w.println("<a href=\"ExperimentNO_REVIEW_run_trace.html\">Trace</a><br/>");
    w.println("<a href=\"ExperimentNO_REVIEW_run_error.html\">Error log</a><br/>");
    w.println("<a href=\"ExperimentNO_REVIEW_run_debug.html\">Debug</a><br/>");
  }