Exemplo n.º 1
0
  /**
   * Sample program params for a class 52 with some specified modules Report3 -c:52
   * -f:u:/formality/Greenfield2010/CyczReport3-GeoProbGraph.csv
   * -m:237,246,247,250,252,259,261,265,268
   *
   * @param args
   */
  public static void main(String[] args) {
    Report3 r = new Report3();
    try {
      SimpleJSAP jsap =
          new SimpleJSAP(
              "Report3",
              "Report 3",
              new Parameter[] {
                new QualifiedSwitch(
                    "beginUserId",
                    JSAP.INTEGER_PARSER,
                    JSAP.NO_DEFAULT,
                    JSAP.NOT_REQUIRED,
                    'b',
                    "buid",
                    "Takes a begin Id.  Must be combined with -e --euid"),
                new QualifiedSwitch(
                    "endUserId",
                    JSAP.INTEGER_PARSER,
                    JSAP.NO_DEFAULT,
                    JSAP.NOT_REQUIRED,
                    'e',
                    "euid",
                    "Takes a end Id (must be combined with -b --buid"),
                new QualifiedSwitch(
                    "classId",
                    JSAP.INTEGER_PARSER,
                    JSAP.NO_DEFAULT,
                    JSAP.NOT_REQUIRED,
                    'c',
                    "classId",
                    "Takes the course id."),
                new QualifiedSwitch(
                    "outfile",
                    FileStringParser.getParser(),
                    JSAP.NO_DEFAULT,
                    JSAP.REQUIRED,
                    'f',
                    "file",
                    "The output file (full path) to a comma separated value file."),
                new QualifiedSwitch(
                        "modules",
                        JSAP.INTEGER_PARSER,
                        JSAP.NO_DEFAULT,
                        JSAP.NOT_REQUIRED,
                        'm',
                        "modules",
                        "Module IDs to report on")
                    .setList(true)
                    .setListSeparator(',')
              });
      JSAPResult config = jsap.parse(args);
      if (jsap.messagePrinted()) System.exit(1);

      File f = config.getFile("outfile");
      FileWriter fw = new FileWriter(f);
      Connection conn = null;
      conn = r.getConnection();
      StringBuffer sb = new StringBuffer();
      int beginId = 0, endId = 0, courseId;
      List<List<String>> rows = null;
      int[] modules = config.getIntArray("modules");
      r.modIds = modules;
      if (config.getBoolean("beginUserId") && config.getBoolean("endUserId")) {
        beginId = config.getInt("beginUserId");
        endId = config.getInt("endUserId");
        rows = r.writeUsers(beginId, endId, conn);
      } else if (config.getBoolean("classId")) {
        courseId = config.getInt("classId");
        r.courseName = r.getCourseName(conn, courseId);
        rows = r.writeCourse(courseId, conn);
      }
      r.toCSV(rows, sb);
      System.out.println(sb.toString());
      fw.write(sb.toString());
      fw.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws JSAPException, IOException, RatingException {
    CommandLineInterface commandLineInterface = new CommandLineInterface();

    JSAPResult jsap = commandLineInterface.parse(args);
    if (!jsap.success()) {
      throw new JSAPException("Command line parsing failed.");
    }

    //////////////////////////////////////////////////////
    //             now configure everything             //
    //////////////////////////////////////////////////////
    Configuration configuration = new Configuration();

    /* configure debug level */
    String debugLevel = jsap.getString(OPTION_DEBUG_LEVEL).toUpperCase();
    Level level = Level.parse(debugLevel);
    configuration.setDebugLevel(level);

    /* configure input dir */
    MatchSetReader matchSetReader =
        new FileMatchSetReader(jsap.getFile(OPTION_INPUT_DIR), configuration);
    configuration.setMatchReader(matchSetReader);

    /* configure output dir */
    Configuration.setOutputDir(jsap.getFile(OPTION_OUTPUT_DIR));

    /* configure previous ratings file */
    configuration.setPreviousRatings(jsap.getFile(OPTION_PREVIOUS_RATINGS));

    /* configure rating algorithms */
    if (jsap.contains(OPTION_DYNAMIC_LINEAR_REGRESSION)) {
      int maxMatchSets = jsap.getInt(OPTION_DYNAMIC_LINEAR_REGRESSION);
      configuration.addRatingSystem(new DynamicLinearRegressionStrategy(maxMatchSets));
    }
    if (jsap.contains(OPTION_CONSTANT_LINEAR_REGRESSION)) {
      double learningRate = jsap.getDouble(OPTION_CONSTANT_LINEAR_REGRESSION);
      configuration.addRatingSystem(new ConstantLinearRegressionStrategy(learningRate));
    }
    if (jsap.getBoolean(OPTION_DIRECT_SCORES)) {
      configuration.addRatingSystem(new DirectScoresStrategy());
    }
    /* ****************** ADD NEW RATING SYSTEMS HERE ****************** */

    /* make ignore list */
    Set<Player> ignorePlayers =
        new IgnorePlayerSet(jsap.getFile(OPTION_INPUT_DIR), configuration.getPlayerSet());

    /* configure output methods */
    for (RatingSystemType type : configuration.getEnabledRatingSystems()) {
      if (jsap.getBoolean(OPTION_CSV_OUTPUT)) {
        configuration.addCSVOutputBuilder(type, ignorePlayers);
      }
      if (jsap.getBoolean(OPTION_GNUPLOT_OUTPUT)) {
        configuration.addGnuplotOutputBuilder(type, ignorePlayers);
      }
      if (jsap.getBoolean(OPTION_HTML_OUTPUT)) {
        configuration.addHtmlOutputBuilder(type, ignorePlayers);
      }
      /* ****************** ADD NEW OUTPUT METHODS HERE ****************** */
    }

    configuration.run();
  }