Ejemplo n.º 1
0
  private void levelsCsv(Tournament tournament) {
    File levelsCSV = new File(names[2]);

    if (levelsCSV.isFile() && levelsCSV.canRead()) {
      levelsCSV.delete();
    }

    try {
      levelsCSV.createNewFile();

      FileWriter fw = new FileWriter(levelsCSV.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      for (Level level : tournament.getLevelMap().values()) {
        bw.write("levelId;" + level.getLevelId() + separator);
        bw.write("levelName;" + level.getLevelName() + separator);
        bw.write("levelNr;" + level.getLevelNr() + separator);
        bw.write("nofWinners;" + level.getNofWinners() + separator);
        bw.write("startTime;" + Utils.dateToStringFull(level.getStartTime()) + separator);
        bw.write(separator);
        for (Round round : level.getRoundMap().values()) {
          Map<Broker, double[]> resultMap = round.determineWinner();
          singleRound(bw, ";", round, resultMap);
          bw.write(separator);
        }
      }

      bw.close();

      copyFile(levelsCSV, names[3]);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  private void tournamentCsv(Tournament tournament) {
    File tournamentCSV = new File(names[0]);

    if (tournamentCSV.isFile() && tournamentCSV.canRead()) {
      tournamentCSV.delete();
    }

    // Create new CSVs
    try {
      tournamentCSV.createNewFile();

      FileWriter fw = new FileWriter(tournamentCSV.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      bw.write("tournamentId;" + tournament.getTournamentId() + separator);
      bw.write("tournamentName;" + tournament.getTournamentName() + separator);
      bw.write("status;" + tournament.getState() + separator);
      bw.write("pomId;" + tournament.getPomId() + separator);
      bw.write("MaxAgents;" + tournament.getMaxAgents() + separator);

      bw.write(separator);

      bw.write("levelId;levelName;levelNr;nofRounds;nofWinners;startTime" + separator);
      for (Level level : tournament.getLevelMap().values()) {
        bw.write(
            String.format(
                "%s;%s;%s;%s;%s;%s%s",
                level.getLevelId(),
                level.getLevelName(),
                level.getLevelNr(),
                level.getNofRounds(),
                level.getNofWinners(),
                Utils.dateToStringFull(level.getStartTime()),
                separator));
      }

      bw.close();

      copyFile(tournamentCSV, names[1]);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 3
0
  private void singleRound(
      BufferedWriter bw, String prefix, Round round, Map<Broker, double[]> resultMap)
      throws IOException {
    bw.write(prefix + "roundId;" + round.getRoundId() + separator);
    bw.write(prefix + "roundName;" + round.getRoundName() + separator);
    bw.write(prefix + "status;" + round.getState() + separator);

    bw.write(prefix + "StartTime;" + Utils.dateToStringFull(round.getStartTime()) + separator);
    bw.write(prefix + "Date from;" + Utils.dateToStringFull(round.getDateFrom()) + separator);
    bw.write(prefix + "Date to;" + Utils.dateToStringFull(round.getDateTo()) + separator);

    bw.write(prefix + "MaxBrokers;" + round.getMaxBrokers() + separator);
    bw.write(prefix + "Registered Brokers;" + round.getBrokerMap().size() + separator);
    //    bw.write(prefix + "MaxAgents;" + round.getMaxAgents() + separator);

    bw.write(prefix + "size1;" + round.getSize1() + separator);
    bw.write(prefix + "multiplier1;" + round.getMultiplier1() + separator);
    bw.write(prefix + "size2;" + round.getSize2() + separator);
    bw.write(prefix + "multiplier2;" + round.getMultiplier2() + separator);
    bw.write(prefix + "size3;" + round.getSize3() + separator);
    bw.write(prefix + "multiplier3;" + round.getMultiplier3() + separator);

    bw.write(prefix + "pomId;" + round.getPomId() + separator);
    bw.write(prefix + "Locations;" + round.getLocations() + separator);

    double[] avgsAndSDs = round.getAvgsAndSDsArray(resultMap);
    if (resultMap == null || resultMap.size() == 0 || avgsAndSDs == null) {
      return;
    }

    bw.write(separator);

    bw.write(prefix + "Average type 1;" + avgsAndSDs[0] + separator);
    bw.write(prefix + "Average type 2;" + avgsAndSDs[1] + separator);
    bw.write(prefix + "Average type 3;" + avgsAndSDs[2] + separator);

    bw.write(prefix + "Standard deviation type 1;" + avgsAndSDs[3] + separator);
    bw.write(prefix + "Standard deviation type 2;" + avgsAndSDs[4] + separator);
    bw.write(prefix + "Standard deviation type 3;" + avgsAndSDs[5] + separator);
    bw.write(separator);

    bw.write(
        prefix
            + "brokerId;brokerName;Size 1;Size 2;Size 3;"
            + "Total (not normalized);Size 1;Size 2;Size3;Total (normalized)"
            + separator);

    for (Map.Entry<Broker, double[]> entry : resultMap.entrySet()) {
      double[] results = entry.getValue();
      bw.write(
          String.format(
              "%s%s;%s;%f;%f;%f;%f;%f;%f;%f;%f%s",
              prefix,
              entry.getKey().getBrokerId(),
              entry.getKey().getBrokerName(),
              results[0],
              results[1],
              results[2],
              results[3],
              results[10],
              results[11],
              results[12],
              results[13],
              separator));
    }
  }