public CSV(Tournament t, Round r) {
    properties = TournamentProperties.getProperties();
    separator = ";" + System.getProperty("line.separator");
    logLocation = properties.getProperty("logLocation");
    baseUrl = properties.getProperty("actionIndex.logUrl", "download?game=%d");
    baseUrl = baseUrl.substring(0, baseUrl.lastIndexOf("game"));

    if (t != null) {
      String name = "%stournament.%s.csv";
      String levels = "%srounds.%s.csv";
      names =
          new String[] {
            String.format(name, logLocation, t.getTournamentName().replaceAll(" ", "_")),
            String.format(name, logLocation, t.getTournamentId()),
            String.format(levels, logLocation, t.getTournamentName().replaceAll(" ", "_")),
            String.format(levels, logLocation, t.getTournamentId())
          };
    } else if (r != null) {
      String name = "%sround.%s.csv";
      String games = "%sgames.%s.csv";
      names =
          new String[] {
            String.format(name, logLocation, r.getRoundName().replaceAll(" ", "_")),
            String.format(name, logLocation, r.getRoundId()),
            String.format(games, logLocation, r.getRoundName().replaceAll(" ", "_")),
            String.format(games, logLocation, r.getRoundId())
          };
    }
  }
Esempio n. 2
0
  void onOpenFileClicked() {
    if (!maybeSave()) {
      return;
    }

    try {
      JFileChooser fc = new JFileChooser();
      FileNameExtensionFilter filter1 =
          new FileNameExtensionFilter(strings.getString("filetype." + EXTENSION), EXTENSION);
      fc.setFileFilter(filter1);

      int rv = fc.showOpenDialog(this);
      if (rv == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        Tournament t = new Tournament();
        t.loadFile(file);

        setTournament(file, t);
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE);
    }
  }
  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();
    }
  }
Esempio n. 4
0
  /** @return true if file was saved, false if user canceled */
  boolean onSaveFileClicked() {
    if (currentFile == null) {
      return onSaveAsFileClicked();
    }

    try {
      tournament.saveFile(currentFile);
      return true;
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE);
    }
    return false;
  }
Esempio n. 5
0
  boolean maybeSave() {
    if (tournament.isDirty()) {

      int rv =
          JOptionPane.showConfirmDialog(
              this,
              strings.getString("main.save_query"),
              PRODUCT_NAME,
              JOptionPane.YES_NO_CANCEL_OPTION,
              JOptionPane.WARNING_MESSAGE);
      if (rv == JOptionPane.CANCEL_OPTION) return false;

      if (rv == JOptionPane.YES_OPTION) {
        return onSaveFileClicked();
      }
    }
    return true;
  }
  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();
    }
  }
Esempio n. 7
0
 void doSave(File file) throws IOException {
   currentFile = file;
   tournament.saveFile(file);
 }