示例#1
0
 private List<DataEntry> getMatchesFromYear(String country, String division, int year) {
   List<DataEntry> retval = new LinkedList<DataEntry>();
   List<DataEntry> tmp = Model.dataset.get(this.getDataKey(country, division));
   for (DataEntry tse : tmp) {
     if (year == Integer.valueOf((String) tse.getExtra("season_start_year")))
       retval.add(tse.clone());
   }
   return retval;
 }
示例#2
0
 private List<DataEntry> getTrainingSet(String country, String division) {
   country = country.toLowerCase();
   List<DataEntry> retval = new LinkedList<DataEntry>();
   List<DataEntry> tmp = dataset.get(this.getDataKey(country, division));
   for (DataEntry tse : tmp) {
     retval.add(tse.clone());
   }
   return retval;
 }
示例#3
0
 private List<DataEntry> getTrainingSet(String country, String division, int maxyear) {
   List<DataEntry> retval = new LinkedList<DataEntry>();
   List<DataEntry> clone = dataset.get(this.getDataKey(country, division));
   for (DataEntry tse : clone) {
     if (maxyear >= Integer.valueOf((String) tse.getExtra("season_start_year")))
       retval.add(tse.clone());
   }
   return retval;
 }
示例#4
0
 private void printDatasetToWekaFormat(Map<String, LinkedList<DataEntry>> data, boolean recurse)
     throws IOException {
   if (recurse) {
     for (String country : data.keySet()) {
       Map<String, LinkedList<DataEntry>> ndata = new TreeMap<String, LinkedList<DataEntry>>();
       ndata.put(country, data.get(country));
       printDatasetToWekaFormat(ndata, false);
     }
   } else {
     String key = "";
     for (String s : data.keySet()) key = s;
     String[] split = key.split("_");
     List<DataEntry> trainingset = this.getTrainingSet(split[0], split[1], 2012);
     List<DataEntry> matchset = this.getMatchesFromYear(split[0], split[1], 2012);
     trainingset.addAll(matchset); // Add the match set
     Writer writer =
         new BufferedWriter(
             new OutputStreamWriter(
                 new FileOutputStream(Setup.outputpath + key + ".arff"), "utf-8"));
     writer.write("@relation " + key + "\r\n");
     writer.write("@attribute 'rating home' real\r\n");
     writer.write("@attribute 'rating away' real\r\n");
     writer.write("@attribute 'current run hjemme' real\r\n");
     writer.write("@attribute 'current run ude' real\r\n");
     writer.write("@attribute 'run hjemme' real\r\n");
     writer.write("@attribute 'run ude' real\r\n");
     writer.write("@attribute 'class' {Hjemme, Uafgjort, Ude}\r\n");
     writer.write("@data\r\n");
     // And loop
     for (DataEntry tse : trainingset) {
       writer.write(
           tse.getX()[0]
               + ","
               + tse.getX()[1]
               + ","
               + tse.getX()[2]
               + ","
               + tse.getX()[3]
               + ","
               + tse.getX()[4]
               + ","
               + tse.getX()[5]
               + ","
               + tse.getY()
               + "\r\n");
     }
     writer.close();
   }
 }
示例#5
0
  public synchronized void load() throws SQLException {
    // And calculate
    Connection connection = getDb();
    Statement stmt = connection.createStatement();
    ResultSet scoreSet = stmt.executeQuery("SELECT hold,division,land from klubber");
    while (scoreSet.next()) {
      // Fetch info
      String land = scoreSet.getString("land");
      String hold = scoreSet.getString("hold");
      int division = scoreSet.getInt("division");
      double rating = Setup.pointStart / (Math.pow(Setup.divisionsforskel, division));
      Team team = new Team(hold, land, division, rating, Setup.matchesToStore);
      teams.addTeam(team);
    }
    stmt.close();
    // Load the matches
    stmt = connection.createStatement();
    String matchesSQL = "SELECT * FROM kampe order by dato asc";
    ResultSet r = stmt.executeQuery(matchesSQL);
    while (r.next()) {
      try {
        // Fetch info
        String country = r.getString("land");
        Team away = teams.get(country, r.getString("udehold"));
        int division = r.getInt("division");
        int goalsAway = r.getInt("udemaal");
        int goalsHome = r.getInt("hjemmemaal");
        String seasonStartYear = r.getString("season_start_year");
        Team home = teams.get(country, r.getString("hjemmehold"));
        int round = r.getInt("runde");
        Kamp match = new Kamp(home, away, goalsHome, goalsAway, round, seasonStartYear);
        // Find result
        Udfald y = null;
        if (goalsHome > goalsAway) y = Udfald.HJEMME;
        else if (goalsHome == goalsAway) y = Udfald.UAFGJORT;
        else y = Udfald.UDE;
        double[] features = getKamp(home, away, country);
        DataEntry matchInfo = new DataEntry(features, y);
        matchInfo.addExtra("season_start_year", seasonStartYear);
        String key = getDataKey(country, division + "");
        synchronized (this) {
          LinkedList<DataEntry> matchData = dataset.get(key);
          if (matchData == null) {
            matchData = new LinkedList<DataEntry>();
            dataset.put(key, matchData);
          }
          // If enough matches and so on, update
          if (home.totalplayed >= Setup.TRAINING_ROUNDS
              && away.totalplayed >= Setup.TRAINING_ROUNDS // Total played at least
              && round >= Setup.antalRunder // Total played in start of each season
          ) {
            matchData.add(matchInfo);
          }
        }

        // And update a lot of information
        // Skal altid ske. Til træning af klubbernes point
        teams.opdaterPoint(home, away, goalsHome, goalsAway, division);

        // The rest
        home.addLatestHomeMatch(match);
        home.addLatestMatch(match);
        away.addLatestAwayMatch(match);
        away.addLatestMatch(match);
        home.addInternal(match);
        away.addInternal(match);
        home.totalplayed++;
        away.totalplayed++;
      } catch (Exception e) {
        Log.e(e);
      }
    }
    r.close();
    stmt.close();

    // Filter out noise if needed
    if (Setup.FILTER_DATA) {
      for (String key : dataset.keySet()) {
        LinkedList<DataEntry> matches = dataset.get(key);
        Setup.FILTER_HANDLER.applyFilters(matches);
      }
    }
    // Prepare normalizer
    for (String key : dataset.keySet()) {
      Normalizer normalizer = new Normalizer(dataset.get(key), Normalizer.Method.NORMALIZATION);
      normalizers.put(key, normalizer);
      if (Setup.NORMALIZE_DATA) normalizer.apply(dataset.get(key));
    }
  }