public bool usageReportItem(Player player, int counter, bool inMinors) { string bgColor = getBackgroundColor(player.Actual, player.TargetUsage, player.Replay, player.IsHitter); if (bgColor.Length == 0) //Skip line if player does not fall within boundry { return(false); } if (counter == 1) { this.emptyUsageRow(); } lines.Add("<table style='margin-left:50px;' border=0 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:none'><tr>"); addTableCell(counter, "#5B9BD5", "#F8CBAD", 30, false); addTableCell(player.Name, bgColor, "#000000", 100, false); addTableCell(TeamUtils.prettyTeamName(player.Team.Abrv), bgColor, "#000000", 60, false); addTableCell(player.IsHitter?"B":"P", bgColor, "#000000", 60); addTableCell(player.Actual, bgColor, "#000000", 75); addTableCell(player.Replay, bgColor, "#000000", 75); addTableCell(player.TargetUsage, bgColor, "#000000", 75); if (inMinors) { addTableCell(player.TargetUsage - player.Replay, bgColor, "#000000", 30); } else { addTableCell((player.TargetUsage - player.Replay) + " (M)", bgColor, "#000000", 30); } lines.Add("</tr></table>"); return(true); }
public void collectData(string teamName, string line, int leagueNameLength) { if (line.StartsWith("--AVERAGE")) { m_bWorkingOnHitters = true; } else if (line.StartsWith("----ERA")) { m_bWorkingOnHitters = false; } else if (line.StartsWith("NAME") || line.Trim().Length == 0) { return; } else { int idx = line.IndexOf("[4]"); String playerName = line.Substring(0, idx).Trim(); if (playerName.Length > 0) { Player player = new Player(); player.IsHitter = m_bWorkingOnHitters; player.Name = playerName; String data = line.Substring(idx + 4).Trim(); Regex regex; if (data.Contains("---") && !m_bWorkingOnHitters) { regex = new Regex(REGEX_USAGE_PITCHER_NOT_USED); } else { regex = m_bWorkingOnHitters ? new Regex(REGEX_USAGE_HITTER) : new Regex(REGEX_USAGE_PITCHER); } Match teamMatch = regex.Match(line); if (teamMatch.Success) { /* * Hitters < 120 actual at bats are allowed at 150% (ie ab * 1.5) * Hitters > 120 actual at bats are actual at bats + 60 (ie ab + 60) * Hitters > 600 actual at bats are allowed at 110% (ie ab * 1.1) * * Pitchers < 60 is 150% of actual (59 * 1.5) = +29 * Pitchers > 118 innings is innings + 30 * Pitchers > 199 is 115% of actual (199 * 1.15) = +29 */ if (m_bWorkingOnHitters) { player.Actual = Convert.ToInt32(teamMatch.Groups[1].Value.Trim()); if (player.Actual < 25) { return; } player.Replay = Convert.ToInt32(teamMatch.Groups[2].Value.Trim()); player.TargetUsage = getPlayerTargetUsage(player.Actual); } else { player.Actual = Convert.ToInt32(teamMatch.Groups[1].Value.Trim()); if (player.Actual < 25) { return; } player.Replay = Convert.ToInt32(teamMatch.Groups[2].Value.Trim()); player.TargetUsage = getPitcherTargetUsage(player.Actual); } Team team = Report.DATABASE.getTeam(TeamUtils.prettyTeamName(teamName)); if (team == null) { team = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TeamId), "XX", leagueNameLength); team.Abrv = teamName; } player.Team = team; } listOfPlayers.Add(player); } } }
private void organizeDataTeam(List <string> lines) { Regex regex = new Regex(@"^([0-9]+) (.{1,18})"); Regex regexPitcherLine = new Regex(@"^(.{1,22}) [0-9]+ +[0-9]+ +[0-9]+ +([A-Z]+) +([RL]) {1,6}([0-9 ])"); Regex regexPitcherBalLine = new Regex(@"^(.{1,17})[0-9]+ +([0-9ERL]+) +[0-9]+ +[0-9]+ +[0-9.]+ +([0-9]+) +([0-9]+) +([0-9]+) +[0-9]+ +[0-9]+ +([0-9]+) +([0-9]+)"); Regex regexBatterLine = new Regex(@"^(.{1,17}) +[0-9]+ +[0-9] +[0-9]+ +([A-Z]+) +([0-9ERL]+) +([0-9]+)"); Regex regexBatterBalanceLine = new Regex(@"^(.{1,16}) +[0-9]+ +([NW])\/([NW]) +([LRS])"); Team currentTeam; bool inPitcherBalanceSection = false; bool inPitcherSection = false; bool inBatterSection = false; bool inBatterBalanceSection = false; bool inDefenseSection = false; int pitcherIndex = 0; int batterIndex = 0; Team team = null; List <Player> pitchers = new List <Player>(); List <Player> batters = new List <Player>(); pitcherDataByTeam = new Dictionary <Team, List <Player> >(); batterDataByTeam = new Dictionary <Team, List <Player> >(); foreach (String line in lines) { Match match = regex.Match(line); if (match.Success) { String thisTeam = isTeamNameLineOfReport(line); if (thisTeam != null) { inPitcherBalanceSection = false; inPitcherSection = false; if (team != null) { Console.Out.WriteLine("Finished reading " + team); pitcherDataByTeam.Add(team, pitchers); batterDataByTeam.Add(team, batters); team = null; } pitchers = new List <Player>(); batters = new List <Player>(); pitcherIndex = 0; batterIndex = 0; team = new Team(RecordIndex.getNextId(RecordIndex.INDEX.TeamId), "", 0); teams.Add(team); team.Name = thisTeam; team.Abrv = TeamUtils.prettyTeamName(thisTeam); if (team.Abrv.Equals("UNK")) { System.Console.WriteLine("Abreviation mapping for team " + team.Name + " not found."); // MessageBox.Show("Abreviation mapping for team " + team.Name + " not found."); } currentTeam = team; } } if (!inBatterSection) { inBatterSection = line.Contains("CODES YEAR TEAM BAL AB DO TR HR BAVG BB K'S RBI OB%"); } if (!inBatterBalanceSection) { inBatterBalanceSection = line.Contains("LEFT% POWER BAT STEAL BUNT H&R RUN"); if (inBatterBalanceSection) { inBatterSection = false; } } if (!inPitcherBalanceSection) { inPitcherBalanceSection = line.Contains("LEFT% BAL WON LOST ERA"); if (inPitcherBalanceSection) { inPitcherSection = false; } } if (!inPitcherSection) { inPitcherSection = line.Contains("CODES YEAR TEAM THROWS START RELIEF"); if (inPitcherSection) { inDefenseSection = false; } } if (!inDefenseSection) { inDefenseSection = line.Contains("Catcher 1b 2b 3b ss lf cf rf ARM"); if (inDefenseSection) { batterIndex = 0; inBatterBalanceSection = false; } } if (inBatterSection) { Match matchB = regexBatterLine.Match(line); if (matchB.Success) { if (matchB.Groups.Count != 5) { throw new Exception("Expecting Yeam, Team and Text"); } Player player = new Player(); player.Name = matchB.Groups[1].Value.Trim(); // if (team.Abrv.Length == 0) // team.Abrv = matchB.Groups[2].Value.Trim(); player.IsHitter = true; player.Bal = matchB.Groups[3].Value.Trim(); float value = 0f; float.TryParse(matchB.Groups[4].Value.Trim(), out value); player.Actual = (int)(value * _config.getABMultiplier()); player.Id = lookupPlayerId(player, team); // player.Id = RecordIndex.getNextId(RecordIndex.INDEX.PlayerId); batters.Add(player); // Console.Out.WriteLine(" inBatterSection "); } } else if (inBatterBalanceSection) { Match matchBB = regexBatterBalanceLine.Match(line); if (matchBB.Success) { if (matchBB.Groups.Count != 5) { throw new Exception("Expecting Yeam, Team and Text"); } Player player = batters[batterIndex]; String name = matchBB.Groups[1].Value.Trim(); // Some reports cut the name off at 16 charaters, then cuts off the last name. if (player.Name.Length > 16) { int firstSpaceIndex = player.Name.IndexOf(' ') + 1; int lastNameLength = player.Name.Length - firstSpaceIndex; name = name.Substring(0, lastNameLength); } if (!player.Name.EndsWith(name)) { Console.Out.WriteLine("ERROR: Batter Name not as expected " + player.Name + " != " + name); continue; } player.PowerL = matchBB.Groups[2].Value.Trim(); player.PowerR = matchBB.Groups[3].Value.Trim(); player.Throws = matchBB.Groups[4].Value.Trim(); player.Id = lookupPlayerId(player, team); batterIndex++; // Console.Out.WriteLine(" inBatterBalanceSection "); } } else if (inPitcherSection) { Match matchP = regexPitcherLine.Match(line); if (matchP.Success) { if (matchP.Groups.Count != 5) { throw new Exception("Expecting Yeam, Team and Text"); } Player player = new Player(); player.Name = matchP.Groups[1].Value.Trim(); if (team.Abrv.Length == 0) { team.Abrv = matchP.Groups[2].Value.Trim(); } player.Team = team; player.IsHitter = false; player.Throws = matchP.Groups[3].Value.Trim(); String spRating = matchP.Groups[4].Value.Trim(); if (spRating.Length > 0) { player.Games = Int32.Parse(spRating); } player.Id = lookupPlayerId(player, team); pitchers.Add(player); // Console.Out.WriteLine(" inPitcherSection "); } } else if (inPitcherBalanceSection) { Match matchPB = regexPitcherBalLine.Match(line); if (matchPB.Success) { Player player = pitchers[pitcherIndex]; String name = matchPB.Groups[1].Value.Trim(); if (!player.Name.EndsWith(name)) { Console.Out.WriteLine("ERROR: Pitcher Name not as expected " + player.Name + " != " + name); continue; } player.Bal = matchPB.Groups[2].Value.Trim(); player.IP = Int32.Parse(matchPB.Groups[3].Value.Trim()); player.Hits = Int32.Parse(matchPB.Groups[4].Value.Trim()); player.BB = Int32.Parse(matchPB.Groups[5].Value.Trim()); player.GS = Int32.Parse(matchPB.Groups[6].Value.Trim()); player.SAVE = Int32.Parse(matchPB.Groups[7].Value.Trim()); pitcherIndex++; } } else if (inDefenseSection) { if (!line.StartsWith("Catcher")) { String name = line.Substring(0, 16).Trim(); String catcher = line.Substring(17, 13).Trim(); if (catcher.Length > 0) { // strip off passball and throwing error stats catcher = catcher.Substring(0, catcher.IndexOf('t')); } String first = line.Substring(30, 4).Trim(); String second = line.Substring(35, 4).Trim(); String third = line.Substring(40, 4).Trim(); String sstop = line.Substring(45, 4).Trim(); String left = line.Substring(50, 4).Trim(); String center = line.Substring(55, 4).Trim(); String right = line.Substring(60, 4).Trim(); String ofArm = line.Substring(65, 4).Trim(); Player player = batters[batterIndex]; if (!player.Name.EndsWith(name)) { // Sometimes the game strips off the last 1-3 characters in the report, so this checks for that. if (!player.Name.EndsWith(name.Substring(0, name.Length - 1)) && !player.Name.EndsWith(name.Substring(0, name.Length - 2)) && !player.Name.EndsWith(name.Substring(0, name.Length - 3))) { Console.Out.WriteLine("ERROR: Defense Player Name not as expected " + player.Name + " != " + name); continue; } } Defense def = new Defense(RecordIndex.getNextId(RecordIndex.INDEX.DefenseId), catcher, first, second, third, sstop, left, center, right, ofArm); player.Def = def; batterIndex++; } } } pitcherDataByTeam.Add(team, pitchers); batterDataByTeam.Add(team, batters); }