Пример #1
0
 public void ingestSummaryTeam(MyDatabase db) throws SQLException {
   System.out.println("Ingesting summary team info : " + _sumTeam.size());
   System.out.flush();
   CachedStatement stmt = db.prepare(INSERT_SUMMARY_TEAM);
   for (WarTeam WT : _sumTeam.values()) {
     stmt.setString(1, WT._teamID);
     stmt.setInt(2, WT._year);
     stmt.setInt(3, WT._pa);
     stmt.setInt(4, WT._ipOuts);
     stmt.setInt(5, WT._GS);
     stmt.setDouble(6, WT._war);
     stmt.setInt(7, WT._salary);
     stmt.executeUpdate();
   }
 }
Пример #2
0
  public void ingestTeamBatting(MyDatabase db, int year) throws Exception {
    System.out.print("Ingesting team batting from " + year + " : ");
    System.out.flush();
    StringBuilder SB = _fetcher.getPage("batting", year);

    Parser P = new Parser(SB);
    BBRefUtil.filter(P, "teams_values_batting");
    int start = P.getStart();
    int end = P.getEnd();
    int i = 0;
    ArrayList<String> columns = null;
    CachedStatement stmt = db.prepare(INSERT_TEAM_BATTING);
    while (true) {
      P.setRange(start, end);
      if ((columns = BBRefUtil.getColumns(P)) == null) {
        break;
      }
      start = P.getEnd();
      if (columns.size() < 15) {
        continue;
      }
      Teams T = BBRefUtil.matchTeamID(columns.get(0), _teams, year);
      stmt.setString(1, T.teamID());
      stmt.setInt(2, year);
      // compute summary info
      WarTeam WT = _sumTeam.get(T.teamID() + year);
      if (WT == null) {
        _sumTeam.put(T.teamID() + year, WT = new WarTeam(T.teamID(), year));
      }
      WT._pa += Integer.parseInt(columns.get(1));
      WT._war += Double.parseDouble(columns.get(10));
      WT._salary += BBRefUtil.parseCurrency(columns.get(14));
      for (int j = 1; j != 10; ++j) {
        stmt.setInt(j + 2, Integer.parseInt(columns.get(j))); // PA thru RAR;
      }
      stmt.setDouble(12, Double.parseDouble(columns.get(10))); // WAR
      stmt.setInt(13, Integer.parseInt(columns.get(11))); // oRAR
      stmt.setDouble(14, parseDouble(columns.get(12))); // oWAR
      stmt.setDouble(15, parseDouble(columns.get(13))); // dWAR
      stmt.setInt(16, BBRefUtil.parseCurrency(columns.get(14))); // salary
      stmt.executeUpdate();
      ++i;
    }
    System.out.println(i + " found");
  }
Пример #3
0
 public void ingestPitchers(MyDatabase db, int year) throws Exception {
   System.out.print("Ingesting pitchers from " + year + " : ");
   System.out.flush();
   StringBuilder SB = _fetcher.getPage("pitching", year);
   Parser P = new Parser(SB);
   BBRefUtil.filter(P, "players_value_pitching");
   int start = P.getStart();
   int end = P.getEnd();
   int i = 0;
   ArrayList<String> columns = null;
   CachedStatement stmt = db.prepare(INSERT_PITCHER);
   while (true) {
     P.setRange(start, end);
     if ((columns = BBRefUtil.getColumns(P)) == null) {
       break;
     }
     start = P.getEnd();
     if (columns.size() < 13) {
       continue;
     }
     Master M = BBRefUtil.matchPlayerID(columns.get(1), _master);
     double war = parseDouble(columns.get(11));
     int ipOuts = getIPOuts(columns.get(4));
     WarSummary WS = _sumPitch.get(M.playerID());
     if (WS == null) {
       _sumPitch.put(M.playerID(), WS = new WarSummary());
     }
     WS.add(ipOuts, war);
     // find team
     Teams T = BBRefUtil.matchTeamID(columns.get(3), _teams, year);
     stmt.setString(1, M.playerID());
     stmt.setInt(2, year);
     stmt.setString(3, M.bbrefID());
     stmt.setInt(4, parseInt(columns.get(2))); // age
     stmt.setString(5, T.teamID());
     stmt.setInt(6, ipOuts); // IP
     stmt.setInt(7, Integer.parseInt(columns.get(5))); // GS
     stmt.setInt(8, Integer.parseInt(columns.get(6))); // R
     stmt.setInt(9, Integer.parseInt(columns.get(7))); // Rrep
     stmt.setInt(10, Integer.parseInt(columns.get(8))); // Rdef
     stmt.setDouble(11, parseDouble(columns.get(9))); // aLi
     stmt.setInt(12, Integer.parseInt(columns.get(10))); // RAR
     stmt.setDouble(13, war); // rWAR
     stmt.setInt(14, BBRefUtil.parseCurrency(columns.get(12))); // salary
     stmt.setString(15, columns.get(13)); // acquired
     stmt.executeUpdate();
     ++i;
   }
   System.out.println(i + " found");
 }
Пример #4
0
  public void ingestTeamPitching(MyDatabase db, int year) throws Exception {
    System.out.print("Ingesting team pitching from " + year + " : ");
    System.out.flush();
    StringBuilder SB = _fetcher.getPage("pitching", year);

    Parser P = new Parser(SB);
    BBRefUtil.filter(P, "teams_value_pitching");
    int start = P.getStart();
    int end = P.getEnd();
    int i = 0;
    ArrayList<String> columns = null;
    CachedStatement stmt = db.prepare(INSERT_TEAM_PITCHING);
    while (true) {
      P.setRange(start, end);
      if ((columns = BBRefUtil.getColumns(P)) == null) {
        break;
      }
      start = P.getEnd();
      if (columns.size() < 10) {
        continue;
      }
      Teams T = BBRefUtil.matchTeamID(columns.get(0), _teams, year);
      stmt.setString(1, T.teamID());
      stmt.setInt(2, year);
      int ipOuts = getIPOuts(columns.get(1));
      // compute summary info
      WarTeam WT = _sumTeam.get(T.teamID() + year);
      if (WT == null) {
        _sumTeam.put(T.teamID() + year, WT = new WarTeam(T.teamID(), year));
      }
      WT._ipOuts += ipOuts;
      WT._GS += Integer.parseInt(columns.get(2));
      WT._war += Double.parseDouble(columns.get(8));
      WT._salary += BBRefUtil.parseCurrency(columns.get(9));
      stmt.setInt(3, ipOuts);
      stmt.setInt(4, Integer.parseInt(columns.get(2))); // GS
      stmt.setInt(5, Integer.parseInt(columns.get(3))); // R
      stmt.setInt(6, Integer.parseInt(columns.get(4))); // Rrep
      stmt.setInt(7, Integer.parseInt(columns.get(5))); // Rdef
      stmt.setDouble(8, parseDouble(columns.get(6))); // aLi
      stmt.setInt(9, Integer.parseInt(columns.get(7))); // Rdef
      stmt.setDouble(10, parseDouble(columns.get(8))); // rWAR
      stmt.setInt(11, BBRefUtil.parseCurrency(columns.get(9))); // salary
      stmt.executeUpdate();
      ++i;
    }
    System.out.println(i + " found");
  }
Пример #5
0
  public void ingestBatters(MyDatabase db, int year) throws Exception {
    System.out.print("Ingesting batters from " + year + " : ");
    System.out.flush();
    StringBuilder SB = _fetcher.getPage("batting", year);

    Parser P = new Parser(SB);
    BBRefUtil.filter(P, "players_value_batting");
    int start = P.getStart();
    int end = P.getEnd();
    int i = 0;
    ArrayList<String> columns = null;
    CachedStatement stmt = db.prepare(INSERT_BATTER);
    while (true) {
      P.setRange(start, end);
      if ((columns = BBRefUtil.getColumns(P)) == null) {
        break;
      }
      start = P.getEnd();
      if (columns.size() < 20) {
        continue;
      }
      Master M = BBRefUtil.matchPlayerID(columns.get(1), _master);
      stmt.setString(1, M.playerID());
      // find team
      Teams T = BBRefUtil.matchTeamID(columns.get(3), _teams, year);
      // compute summary info
      int pa = Integer.parseInt(columns.get(4));
      double war = parseDouble(columns.get(13));
      WarSummary WS = _sumBat.get(M.playerID());
      if (WS == null) {
        _sumBat.put(M.playerID(), WS = new WarSummary());
      }
      WS.add(pa, war);
      // compute isPitcher
      String possumm = columns.get(19);
      boolean isPitcher = false;
      for (int i_ch = 0, e_ch = possumm.length(); i_ch != e_ch; ++i_ch) {
        char ch = possumm.charAt(i_ch);
        if (ch == '1') {
          isPitcher = true;
          break;
        }
        if (NON_PITCHERS.indexOf(ch) != -1) {
          break;
        }
      } // flag as non-pitcher, unless it's sure they're a pitcher
      stmt.setInt(2, year);
      stmt.setString(3, M.bbrefID());
      stmt.setInt(4, parseInt(columns.get(2))); // age
      stmt.setString(5, T.teamID());
      stmt.setInt(6, pa);
      for (int j = 7; j != 15; ++j) {
        stmt.setInt(j, Integer.parseInt(columns.get(j - 2))); // PA thru RAR; happens to line up
      }
      stmt.setDouble(15, war); // rWAR
      stmt.setInt(16, Integer.parseInt(columns.get(14))); // oRAR
      stmt.setDouble(17, parseDouble(columns.get(15))); // oWAR
      stmt.setDouble(18, parseDouble(columns.get(16))); // dWAR
      stmt.setInt(19, BBRefUtil.parseCurrency(columns.get(17))); // salary
      stmt.setString(20, columns.get(18)); // acquired
      stmt.setString(21, possumm); // possumm
      stmt.setInt(22, isPitcher ? 1 : 0); // isPitcher
      stmt.executeUpdate();
      ++i;
    }
    System.out.println(i + " found");
  }