public List <Dictionary <int, int> > calculate(Func <int, String, int, int, int, int, int> createRowFunc) { Dictionary <int, int> balanceLefties = new Dictionary <int, int>(); Dictionary <int, int> balanceRighties = new Dictionary <int, int>(); String[] types = { "9L", "8L", "7L", "6L", "5L", "4L", "3L", "2L", "1L", "E", "1R", "2R", "3R", "4R", "5R", "6R", "7R", "8R", "9R" }; int rowCount = 1; int totalStarterIP = teamReportFile.getTotalStarterIP(targetTeam); // int totalPitcherIP = teamReportFile.getTotalPitcherIP(); foreach (String type in types) { int ip_for_lefties = 0; int ip_for_righties = 0; List <Player> players = teamReportFile.getBalanceData()[type]; foreach (Player player in players) { if (player.GS > 1 && !player.Team.Abrv.Equals(targetTeam.Abrv)) { if (player.Throws.Equals("L")) { ip_for_lefties += player.IP; } else if (player.Throws.Equals("R")) { ip_for_righties += player.IP; } } } // THIS BUILDS THE ESTIMATED BATTER AT BATS PER TYPE TABLE int valueLAB = CalculateColumnUtil.calculateColumn(ip_for_lefties, totalStarterIP); int valueRAB = CalculateColumnUtil.calculateColumn(ip_for_righties, totalStarterIP); if (createRowFunc != null) { createRowFunc(rowCount, type, ip_for_lefties, valueLAB, ip_for_righties, valueRAB); } balanceLefties.Add(rowCount - 1, valueLAB); balanceRighties.Add(rowCount - 1, valueRAB); rowCount++; } List <Dictionary <int, int> > returnValue = new List <Dictionary <int, int> >(); returnValue.Add(balanceLefties); returnValue.Add(balanceRighties); return(returnValue); }
public List <Dictionary <int, int> > calculate(Func <int, String, int, int, int, int, int> createRowFunc) { if (inDivision == 0 || outDivision == 0) { throw new Exception("Error, in and Out Division needs to be defined"); } // Initial local variables double teamsInDivision = 0, teamsOutDivision = 0, gamesInDivision = 0, gamesOutDivision = 0, totalGames = 0; // Count the number of Games in and out of division foreach (Team opponentTeam in teamReportFile.getTeams()) { if (!targetTeam.Abrv.Equals(opponentTeam.Abrv)) { if (targetTeam.Division.Equals(opponentTeam.Division)) { gamesInDivision += inDivision; totalGames += inDivision; teamsInDivision++; } else { gamesOutDivision += outDivision; totalGames += outDivision; teamsOutDivision++; } } } // Percentage of Games In and Out of division. double pctGamesInDivisionPerTeam = inDivision / totalGames; double pctGamesOutDivisionPerTeam = outDivision / totalGames; double overallPctInDivision = pctGamesInDivisionPerTeam * teamsInDivision; double overallPctOutDivision = pctGamesOutDivisionPerTeam * teamsOutDivision; Dictionary <String, int> total_LeftybalanceData_in = new Dictionary <String, int>(); Dictionary <String, int> total_RightybalanceData_in = new Dictionary <String, int>(); Dictionary <String, int> total_LeftybalanceData_out = new Dictionary <String, int>(); Dictionary <String, int> total_RightybalanceData_out = new Dictionary <String, int>(); double totalLeftIP_in = 0; double totalRightIP_in = 0; double totalLeftIP_out = 0; double totalRightIP_out = 0; foreach (Team opponentTeam in teamReportFile.getTeams()) { if (!opponentTeam.Abrv.Equals(targetTeam.Abrv)) { bool opponentInDivision = opponentTeam.Division.Equals(targetTeam.Division); List <Player> opponentPitchers = teamReportFile.getTeamPitchers(opponentTeam.Abrv); if (opponentInDivision) { totalLeftIP_in += addTeamsBalanceDataToTotal(total_LeftybalanceData_in, teamReportFile.getTeamBalanceCount("L", opponentPitchers)); totalRightIP_in += addTeamsBalanceDataToTotal(total_RightybalanceData_in, teamReportFile.getTeamBalanceCount("R", opponentPitchers)); } else { totalLeftIP_out += addTeamsBalanceDataToTotal(total_LeftybalanceData_out, teamReportFile.getTeamBalanceCount("L", opponentPitchers)); totalRightIP_out += addTeamsBalanceDataToTotal(total_RightybalanceData_out, teamReportFile.getTeamBalanceCount("R", opponentPitchers)); } } } Dictionary <String, int> est_LeftybalanceData_in = new Dictionary <String, int>(); Dictionary <String, int> est_RightybalanceData_in = new Dictionary <String, int>(); Dictionary <String, int> est_LeftybalanceData_out = new Dictionary <String, int>(); Dictionary <String, int> est_RightybalanceData_out = new Dictionary <String, int>(); // int adjustedTotalLeftStarterIP = Convert.ToInt32(totalLeftIP_in); // int adjustedTotalRightStarterIP = Convert.ToInt32(totalRightIP_in )*; int totalStarterIP = (int)((totalLeftIP_in * overallPctInDivision) + (totalRightIP_in * overallPctInDivision) + (totalLeftIP_out * overallPctOutDivision) + (totalRightIP_out * overallPctOutDivision)); foreach (String type in types) { est_LeftybalanceData_in[type] = CalculateColumnUtil.calculateColumn(total_LeftybalanceData_in[type], overallPctInDivision, totalStarterIP); est_RightybalanceData_in[type] = CalculateColumnUtil.calculateColumn(total_RightybalanceData_in[type], overallPctInDivision, totalStarterIP); est_LeftybalanceData_out[type] = CalculateColumnUtil.calculateColumn(total_LeftybalanceData_out[type], overallPctOutDivision, totalStarterIP); est_RightybalanceData_out[type] = CalculateColumnUtil.calculateColumn(total_RightybalanceData_out[type], overallPctOutDivision, totalStarterIP); } Dictionary <int, int> balanceLefties = new Dictionary <int, int>(); Dictionary <int, int> balanceRighties = new Dictionary <int, int>(); int rowCount = 1; foreach (String type in types) { int ip_for_lefties = est_LeftybalanceData_in[type] + est_LeftybalanceData_out[type]; int ip_for_righties = est_RightybalanceData_in[type] + est_RightybalanceData_out[type]; if (createRowFunc != null) { createRowFunc(rowCount, type, (int)(total_LeftybalanceData_in[type] + total_LeftybalanceData_out[type]), ip_for_lefties, (int)(total_RightybalanceData_in[type] + total_RightybalanceData_out[type]), ip_for_righties); } balanceLefties.Add(rowCount - 1, ip_for_lefties); balanceRighties.Add(rowCount - 1, ip_for_righties); rowCount++; } List <Dictionary <int, int> > returnValue = new List <Dictionary <int, int> >(); returnValue.Add(balanceLefties); returnValue.Add(balanceRighties); return(returnValue); }