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"); }
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"); }
/** * Returns the team color of the given team. The team color is either sent by the game controller * or given by the GameController configuration. * * @param teamNumber number of the team * @return the team color * @see TeamInfo#teamColor */ public int getTeamColor(final int teamNumber) { Integer color = teamColors.get(teamNumber); if (color == null) { String[] colorStrings = null; try { if (teamNumber == 98 || teamNumber == 99) { Rules.league = Rules.LEAGUES[1]; } else { Rules.league = Rules.LEAGUES[0]; } colorStrings = Teams.getColors(teamNumber); } catch (final NullPointerException | ArrayIndexOutOfBoundsException e) { } if (colorStrings == null || colorStrings.length < 1) { if (teamNumber == teamNumbers[TEAM_RIGHT]) { return GameControlData.TEAM_RED; } else { return GameControlData.TEAM_BLUE; } } else if (colorStrings[0].equals("blue")) { return GameControlData.TEAM_BLUE; } else if (colorStrings[0].equals("red")) { return GameControlData.TEAM_RED; } else if (colorStrings[0].equals("yellow")) { return GameControlData.TEAM_YELLOW; } else { return GameControlData.TEAM_BLACK; } } return color; }
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"); }
/** * Returns the team name of the given team. * * @param teamNumber number of the team * @param withNumber whether the team number should be in the returned string * @param withPrefix whether the pre- or suffix "Team" should be included * @return the team name */ public String getTeamName( final Integer teamNumber, final boolean withNumber, final boolean withPrefix) { if (teamNumber == 98 || teamNumber == 99) { Rules.league = Rules.LEAGUES[1]; } else { Rules.league = Rules.LEAGUES[0]; } final String[] teamNames = Teams.getNames(withNumber); if (teamNumber != null) { if (teamNumber < teamNames.length && teamNames[teamNumber] != null) { return ((withPrefix ? "Team " : "") + teamNames[teamNumber]); } else { return ("Unknown" + (withPrefix ? " Team" : "") + (withNumber ? " (" + teamNumber + ")" : "")); } } else { return "Unknown" + (withPrefix ? " Team" : ""); } }
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"); }