/**
   * sets begin and end time of experiment, create cmds command "createSimTimeBounds" and starts
   * experiment
   *
   * @param exp
   * @param begin
   * @param end
   * @param timezone
   * @param initSpeed
   */
  public void experimentStart(Experiment exp, double initSpeed) {

    this.experiment = exp;
    if (this.experiment == null) throw new SimulationException("Experiment-Parameter is null");
    if (this.experimentEnd != null) this.experiment.stop(this.experimentEnd);

    Command c;
    try {
      c = Command.getCommandInit("createSimTimeBounds", this.getAnimationTimeInit());
      c.addParameter("Begin", Long.toString(this.getAnimationTimeInit()));
      if (exp.getStopTime() != null)
        c.addParameter("End", Long.toString(this.getAnimationTime(exp.getStopTime())));
      c.addParameter("TimeZone", this.timezone.getID());
      c.addParameter("Speed", Double.toString(initSpeed));
      c.setRemark("erzeugt in CmdGeneration.experimentStart");
      this.checkAndLog(c);
      this.write(c);
    } catch (CommandException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    this.initPhase = false;
    System.out.println("cmdGen: begin of Experiment");
    this.experiment.start(this.experimentBegin);
    System.out.println("cmdGen: End of Experiment");
  }
  public static void main(String[] args) throws Exception {
    Experiment.setCoroutineModel(CoroutineModel.FIBERS);
    final Server server = new Server(args.length > 0 ? Integer.parseInt(args[0]) : 8080);
    server.setHandler(new ServerMain());

    server.start();
    server.join();
  }
  @Override
  public void lifeCycle() throws SuspendExecution {
    final Experiment exp = this.getModel().getExperiment();
    final File fileResults = new File(exp.getOutputPath(), exp.getName() + "plotResults.csv");
    final File fileBoard = new File(exp.getOutputPath(), exp.getName() + "plotBoard.csv");
    try (CsvWriter wResults = new CsvWriter(new FileWriter(fileResults));
        CsvWriter wBoard = new CsvWriter(new FileWriter(fileBoard))) {
      wResults.addNumericAttribute(TIME);
      wResults.addNumericAttribute(STARTED_STORIES);
      wResults.addNumericAttribute(FINISHED_STORIES);
      wResults.addNumericAttribute(ISSUES_FOUND_BY_CUSTOMER);

      wBoard.addNumericAttribute(TIME);
      wBoard.addNumericAttribute(OPEN_STORY_TASKS);
      wBoard.addNumericAttribute(OPEN_ISSUEFIX_TASKS);
      wBoard.addNumericAttribute(TASKS_READY_FOR_REVIEW);
      wBoard.addNumericAttribute(TASKS_WITH_REVIEW_REMARKS);

      while (true) {
        final Map<String, Object> dataResults = new HashMap<>();
        dataResults.put(TIME, this.presentTime().getTimeAsDouble(TimeUnit.HOURS));
        dataResults.put(STARTED_STORIES, this.getModel().getStartedStoryCount());
        dataResults.put(FINISHED_STORIES, this.getModel().getFinishedStoryCount());
        dataResults.put(ISSUES_FOUND_BY_CUSTOMER, this.getModel().getIssueCountFoundByCustomers());
        wResults.writeTuple(dataResults);
        wResults.flush();

        final Map<String, Object> dataBoard = new HashMap<>();
        dataBoard.put(TIME, this.presentTime().getTimeAsDouble(TimeUnit.HOURS));
        dataBoard.put(OPEN_STORY_TASKS, this.getBoard().countOpenStoryTasks());
        dataBoard.put(OPEN_ISSUEFIX_TASKS, this.getBoard().countOpenIssuefixTasks());
        dataBoard.put(TASKS_READY_FOR_REVIEW, this.getBoard().countTasksReadyForReview());
        dataBoard.put(TASKS_WITH_REVIEW_REMARKS, this.getBoard().countTasksWithReviewRemarks());
        wBoard.writeTuple(dataBoard);
        wBoard.flush();

        this.hold(new TimeSpan(16, TimeUnit.HOURS));
      }
    } catch (final IOException e) {
      throw new RuntimeException(e);
    }
  }
 /**
  * the experiment name should be EXPERIMENT.SCENARIO in the jbpm simulation enviroment. Isolate
  * the scenario here, to be less verbose in reports.
  */
 private String getScenarioName(Experiment experiment) {
   if (experiment.getName() != null && experiment.getName().indexOf(".") > -1)
     return experiment.getName().substring(experiment.getName().indexOf(".") + 1);
   else return experiment.getName();
 }