public static void UpdateRosterAnalysisPlayerList(League league, string myTeam, ListView lv, Func <IPlayer, bool> playerPassesFilter) { LeagueConstants lc = LeagueConstants.For(league.FantasyLeague); List <IRoster> baselineTeams = RosterAnalysis.AssignPlayersToTeams(league, p => p.FantasyTeam); RosterAnalysis.AssignStatsAndPoints(baselineTeams, lc.ScoringStatExtractors); IRoster baselineTeam = baselineTeams.Find(t => t.TeamName == myTeam); if (baselineTeam == null) { return; } lv.BeginUpdate(); lv.Items.Clear(); League l = league.Clone(); foreach (IPlayer p in l.AllPlayers) { if (!string.IsNullOrEmpty(p.FantasyTeam) || !playerPassesFilter(p)) { continue; } p.FantasyTeam = baselineTeam.TeamName; List <IRoster> teams = RosterAnalysis.AssignPlayersToTeams(l, pb => pb.FantasyTeam); RosterAnalysis.AssignStatsAndPoints(teams, lc.ScoringStatExtractors); IRoster team = teams.Find(t => t.TeamName == baselineTeam.TeamName); ListViewItem item = new ListViewItem(p.Name); item.Tag = p; item.SubItems.Add(string.Empty); // total delta float totalDelta = 0f; foreach (IStatExtractor extractor in lc.ScoringStatExtractors) { float delta = team.Points[extractor.StatName] - baselineTeam.Points[extractor.StatName]; totalDelta += delta; item.SubItems.Add(delta.ToString()); } item.SubItems[1].Text = totalDelta.ToString(); lv.Items.Add(item); p.FantasyTeam = string.Empty; } lv.EndUpdate(); }
public static string GetTopNFreeAgentPickups(League league, IReadOnlyList <IStatExtractor> extractors, string teamName) { List <IRoster> baselineTeams = RosterAnalysis.AssignPlayersToTeams(league, p => p.FantasyTeam); RosterAnalysis.AssignStatsAndPoints(baselineTeams, extractors); IRoster baselineTeam = baselineTeams.Find(t => t.TeamName == teamName); if (baselineTeam == null) { return(string.Empty); } StringBuilder result = new StringBuilder("<HTML><BODY><TABLE BORDER='1'><TR><TD>Player To Add</TD><TD>Player To Drop</TD><TD>Total Delta</TD>"); foreach (IStatExtractor extractor in extractors) { result.AppendFormat("<TD>{0}</TD>", extractor.StatName); } result.Append("</TR>"); League l = league.Clone(); List <Tuple <float, string> > lines = new List <Tuple <float, string> >(); foreach (IPlayer p in l.AllPlayers) { if (!string.IsNullOrEmpty(p.FantasyTeam)) { continue; } p.FantasyTeam = baselineTeam.TeamName; HashSet <Position> newPlayerPositions = new HashSet <Position>(p.Positions.Where(position => Positions.DisplayPositions.Contains(position))); if (newPlayerPositions.Count > 1) { newPlayerPositions.Remove(Position.Util); } foreach (IPlayer teamPlayerToSwap in baselineTeam.Players.Where(tpts => tpts.Positions.Intersect(newPlayerPositions).Count() > 0)) { List <IRoster> teams = RosterAnalysis.AssignPlayersToTeams(l, pb => pb.ESPNId == teamPlayerToSwap.ESPNId ? string.Empty : pb.FantasyTeam); RosterAnalysis.AssignStatsAndPoints(teams, extractors); IRoster team = teams.Find(t => t.TeamName == baselineTeam.TeamName); float totalDelta = 0f; StringBuilder sb = new StringBuilder(); foreach (IStatExtractor extractor in extractors) { float delta = team.Points[extractor.StatName] - baselineTeam.Points[extractor.StatName]; sb.AppendFormat("<TD>{0}</TD>", delta); totalDelta += delta; } if (totalDelta > 0) { string line = string.Format("<TR><TD>{0}</TD><TD>{1}</TD><TD>{2}</TD>{3}</TR>", p.Name, teamPlayerToSwap.Name, totalDelta, sb.ToString()); lines.Add(new Tuple <float, string>(totalDelta, line)); } } p.FantasyTeam = string.Empty; } lines.Sort((a, b) => b.Item1.CompareTo(a.Item1)); foreach (Tuple <float, string> line in lines) { result.AppendLine(line.Item2); } result.Append("</TABLE></BODY></HTML>"); return(result.ToString()); }