Пример #1
0
        private void UpdatePlayerListView(IEnumerable <IPlayer> players)
        {
            this.lvAnalysis.BeginUpdate();
            this.lvAnalysis.Items.Clear();

            foreach (IPlayer player in players)
            {
                ListViewItem item = new ListViewItem(player.Name);
                foreach (IStatExtractor extractor in LeagueConstants.For(this.league.FantasyLeague).ScoringStatExtractors.Union(LeagueConstants.For(this.league.FantasyLeague).SupportingStatExtractors))
                {
                    IStatValue value = extractor.Extract(player);
                    if (value != null)
                    {
                        item.SubItems.Add(value.Value.ToString());
                    }
                    else
                    {
                        item.SubItems.Add(string.Empty);
                    }
                }
                this.lvAnalysis.Items.Add(item);
            }

            this.lvAnalysis.EndUpdate();
        }
Пример #2
0
        public static void UpdateStatsPlayerList(League league, ListView lv, Func <IPlayer, bool> playerPassesFilter)
        {
            LeagueConstants lc = LeagueConstants.For(league.FantasyLeague);

            lv.BeginUpdate();
            foreach (IPlayer player in league.AllPlayers)
            {
                if (playerPassesFilter(player))
                {
                    ListViewItem item = new ListViewItem(player.Name);
                    item.SubItems.Add(player.Status);
                    foreach (IStatExtractor extractor in lc.ScoringStatExtractors)
                    {
                        IStatValue value = extractor.Extract(player);
                        if (value != null)
                        {
                            item.SubItems.Add(value.Value.ToString());
                        }
                        else
                        {
                            item.SubItems.Add(string.Empty);
                        }
                    }
                    lv.Items.Add(item);
                }
            }
            lv.EndUpdate();
        }
Пример #3
0
        private string GetPlayerAnalysisTable(IPlayer player, IEnumerable <IPlayer> players, string tableTitle)
        {
            PercentilePlayerGroupAnalyzer analyzer = new PercentilePlayerGroupAnalyzer();
            LeagueConstants lc = LeagueConstants.For(this.league.FantasyLeague);
            IEnumerable <IStatExtractor> extractors = player is Batter?lc.BattingSupportingStatExtractors.Union(lc.BattingScoringStatExtractors) : lc.PitchingSupportingStatExtractors.Union(lc.PitchingScoringStatExtractors);

            StringBuilder sb = new StringBuilder();

            sb.Append("<TABLE BORDER=1><TR><TD>Stat Name</TD><TD>Player's Stat Value</TD><TD>Max Value</TD><TD>Min Value</TD><TD>Graph</TD><TD>Player Percentile</TD></TR>");
            int percentileSum = 0;
            int count         = 0;

            foreach (IStatExtractor extractor in extractors)
            {
                PlayerGroupAnalysis analysis = analyzer.Analyze(this.Text, extractor, players, player, p => p == player ? Brushes.Yellow : !string.IsNullOrEmpty(p.FantasyTeam) ? Brushes.Blue : Brushes.Violet);
                byte[] img;
                using (MemoryStream stm = new MemoryStream())
                {
                    analysis.Graph.Save(stm, System.Drawing.Imaging.ImageFormat.Jpeg);
                    img = stm.ToArray();
                }
                sb.AppendLine($"<TR><TD>{analysis.Stat}</TD><TD>{analysis.PlayerStatValue}</TD><TD>{analysis.MaxStatValue}</TD><TD>{analysis.MinStatValue}</TD><TD><img src=\"data:image/jpg;base64,{Convert.ToBase64String(img)}\"/></TD><TD>{analysis.PlayerPercentile}</TD></TR>");
                percentileSum += analysis.PlayerPercentile;
                count++;
            }
            sb.AppendLine("</TABLE>");

            return(string.Format("<H1>{0} (Average Percentile: {1})</H1>{2}", tableTitle, percentileSum / count, sb.ToString()));
        }
 public PlayerGroupCenter(string groupDescription, LeagueConstants constants, IEnumerable <IPlayer> allPlayers)
 {
     InitializeComponent();
     this.Text       = groupDescription;
     this.constants  = constants;
     this.allPlayers = new List <IPlayer>(allPlayers);
     this.allPlayers.Sort((x, y) => x.Name.CompareTo(y.Name));
     this.tbWordWheel.Text = string.Empty;
     this.lbPlayers.Items.Clear();
     this.lbPlayers.Items.AddRange(this.allPlayers.ToArray());
     this.currentPlayer = null;
     this.UpdateWebView();
 }
Пример #5
0
        public TargetCenter(League league)
        {
            InitializeComponent();
            this.league = league;
            LeagueConstants lc = LeagueConstants.For(league.FantasyLeague);

            foreach (Team team in this.league.Teams)
            {
                this.cbTeams.Items.Add(team.Name);
            }

            UIUtilities.PrepRosterAnalysisPlayerList(this.league, this.lvPlayers);
        }
Пример #6
0
        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();
        }
Пример #7
0
        public static void PrepRosterAnalysisPlayerList(League league, ListView lv)
        {
            LeagueConstants lc = LeagueConstants.For(league.FantasyLeague);

            lv.ColumnClick += OnColumnClicked;

            lv.BeginUpdate();
            int columnWidth = lv.Width / (lc.ScoringStatExtractors.Count + 2);

            lv.Columns.Add("Player Name", columnWidth);
            lv.Columns.Add("Stat Delta");
            foreach (IStatExtractor extractor in lc.ScoringStatExtractors)
            {
                ColumnHeader column = new ColumnHeader();
                column.Text  = extractor.StatName;
                column.Width = columnWidth;
                lv.Columns.Add(column);
            }
            lv.EndUpdate();
        }
Пример #8
0
        public StatCenter(League league, Func <IPlayer, string> extractTeam)
        {
            InitializeComponent();

            this.league = league;
            LeagueConstants lc    = LeagueConstants.For(league.FantasyLeague);
            List <IRoster>  teams = RosterAnalysis.AssignPlayersToTeams(league, extractTeam);

            RosterAnalysis.AssignStatsAndPoints(teams, lc.ScoringStatExtractors);

            this.lvStats.BeginUpdate();
            this.lvPoints.BeginUpdate();

            int columnWidth = this.lvPoints.Width / (lc.ScoringStatExtractors.Count + 2);

            this.AddColumns(this.lvStats, lc.ScoringStatExtractors, columnWidth);
            this.AddColumns(this.lvPoints, lc.ScoringStatExtractors, columnWidth);
            this.lvPoints.Columns.Add("Total Points", columnWidth);

            foreach (IRoster team in teams)
            {
                float        totalPoints = 0;
                ListViewItem statsItem   = new ListViewItem(team.TeamName);
                ListViewItem pointsItem  = new ListViewItem(team.TeamName);
                statsItem.Tag  = team;
                pointsItem.Tag = team;
                foreach (IStatExtractor extractor in lc.ScoringStatExtractors)
                {
                    statsItem.SubItems.Add(team.Stats.ContainsKey(extractor.StatName) ? team.Stats[extractor.StatName].ToString() : "N/A");
                    pointsItem.SubItems.Add(team.Points.ContainsKey(extractor.StatName) ? team.Points[extractor.StatName].ToString() : "N/A");
                    totalPoints += team.Points[extractor.StatName];
                }
                pointsItem.SubItems.Add(totalPoints.ToString());
                this.lvStats.Items.Add(statsItem);
                this.lvPoints.Items.Add(pointsItem);
            }

            this.lvStats.EndUpdate();
            this.lvPoints.EndUpdate();
        }
Пример #9
0
        public static void PrepPointsPlayerList(League league, ListView lv)
        {
            LeagueConstants lc = LeagueConstants.For(league.FantasyLeague);

            lv.ColumnClick += OnColumnClicked;

            lv.BeginUpdate();
            int columnWidth = lv.Width / (lc.ScoringStatExtractors.Count + 2);

            lv.Columns.Add("Team Name", columnWidth);
            lv.Columns.Add("Total Points", columnWidth);
            foreach (IStatExtractor extractor in lc.ScoringStatExtractors)
            {
                ColumnHeader column = new ColumnHeader();
                column.Text  = extractor.StatName;
                column.Width = columnWidth;
                if (!extractor.MoreIsBetter)
                {
                    column.Tag = "asc";
                }
                lv.Columns.Add(column);
            }
        }
Пример #10
0
        public static void UpdatePointsPlayerList(League league, ListView lv, Func <IPlayer, bool> playerPassesFilter)
        {
            List <IRoster> teams = new List <IRoster>();

            foreach (IPlayer player in league.AllPlayers)
            {
                if (string.IsNullOrEmpty(player.FantasyTeam) && playerPassesFilter(player))
                {
                    Roster r = new Roster(player.Name);
                    r.AllPlayers.Add(player);
                    teams.Add(r);
                }
            }

            LeagueConstants lc = LeagueConstants.For(league.FantasyLeague);

            RosterAnalysis.AssignStatsAndPoints(teams, lc.ScoringStatExtractors);

            lv.BeginUpdate();
            lv.Items.Clear();
            foreach (IRoster team in teams)
            {
                float        totalPoints = 0;
                ListViewItem item        = new ListViewItem(team.TeamName);
                item.Tag = team;
                item.SubItems.Add(string.Empty); // total points
                foreach (IStatExtractor extractor in lc.ScoringStatExtractors)
                {
                    item.SubItems.Add(team.Points[extractor.StatName].ToString());
                    totalPoints += team.Points[extractor.StatName];
                }
                item.SubItems[1].Text = totalPoints.ToString();
                lv.Items.Add(item);
            }
            lv.EndUpdate();
        }
Пример #11
0
        public AnalysisCenter(League league, Team team)
        {
            InitializeComponent();

            this.league       = league;
            this.team         = team;
            this.lblTeam.Text = string.Format("{0}: {1}, {2,12:C2}", team.Name, team.Owner, team.Budget);

            LeagueConstants lc = LeagueConstants.For(league.FantasyLeague);

            this.stats = new List <Stat>();
            this.stats.Add(new Stat("Runs", new CountingStatAnalyzer("Runs", lc.RosterableBatterCountPerTeam * lc.TeamCount, league.Batters, b => ((Batter)b).ProjectedR, b => string.IsNullOrEmpty(b.FantasyTeam) ? 0 : ((Batter)b).ProjectedR)));
            this.stats.Add(new Stat("Home Runs", new CountingStatAnalyzer("Home Runs", lc.RosterableBatterCountPerTeam * lc.TeamCount, league.Batters, b => ((Batter)b).ProjectedHR, b => string.IsNullOrEmpty(b.FantasyTeam) ? 0 : ((Batter)b).ProjectedHR)));
            this.stats.Add(new Stat("RBIs", new CountingStatAnalyzer("RBIs", lc.RosterableBatterCountPerTeam * lc.TeamCount, league.Batters, b => ((Batter)b).ProjectedRBI, b => string.IsNullOrEmpty(b.FantasyTeam) ? 0 : ((Batter)b).ProjectedRBI)));
            this.stats.Add(new Stat("Steals", new CountingStatAnalyzer("Steals", lc.RosterableBatterCountPerTeam * lc.TeamCount, league.Batters, b => ((Batter)b).ProjectedSB, b => string.IsNullOrEmpty(b.FantasyTeam) ? 0 : ((Batter)b).ProjectedSB)));
            this.stats.Add(new Stat("OPS", new RatioStatAnalyzer("OPS", lc.RosterableBatterCountPerTeam * lc.TeamCount, true, league.Batters, b => ((Batter)b).ProjectedBB + ((Batter)b).ProjectedH, b => ((Batter)b).ProjectedAB)));
            this.stats.Add(new Stat("Wins", new CountingStatAnalyzer("Wins", lc.RosterablePitcherCountPerTeam * lc.TeamCount, league.Pitchers, p => ((Pitcher)p).ProjectedW, p => string.IsNullOrEmpty(p.FantasyTeam) ? 0 : ((Pitcher)p).ProjectedW)));
            this.stats.Add(new Stat("Saves", new CountingStatAnalyzer("Saves", lc.RosterablePitcherCountPerTeam * lc.TeamCount, league.Pitchers, p => ((Pitcher)p).ProjectedSV, p => string.IsNullOrEmpty(p.FantasyTeam) ? 0 : ((Pitcher)p).ProjectedSV)));
            this.stats.Add(new Stat("Strikeouts", new CountingStatAnalyzer("Strikeouts", lc.RosterablePitcherCountPerTeam * lc.TeamCount, league.Pitchers, p => ((Pitcher)p).ProjectedK, p => string.IsNullOrEmpty(p.FantasyTeam) ? 0 : ((Pitcher)p).ProjectedK)));
            this.stats.Add(new Stat("ERA", new RatioStatAnalyzer("ERA", lc.RosterablePitcherCountPerTeam * lc.TeamCount, false, league.Pitchers, p => ((Pitcher)p).ProjectedER * 27, p => ((Pitcher)p).ProjectedOutsRecorded)));
            this.stats.Add(new Stat("WHIP", new RatioStatAnalyzer("WHIP", lc.RosterablePitcherCountPerTeam * lc.TeamCount, false, league.Pitchers, p => (((Pitcher)p).ProjectedWalks + ((Pitcher)p).ProjectedHits) * 3, p => ((Pitcher)p).ProjectedOutsRecorded)));

            Dictionary <IPlayer, PlayerAggregate> playerAnalysis = new Dictionary <IPlayer, PlayerAggregate>();

            foreach (Stat stat in this.stats)
            {
                foreach (PlayerAnalysis analysis in stat.Analyzer.Analyze())
                {
                    PlayerAggregate agg;
                    if (!playerAnalysis.TryGetValue(analysis.Player, out agg))
                    {
                        agg = new PlayerAggregate(analysis.Player);
                        playerAnalysis[analysis.Player] = agg;
                    }
                    agg.Analyses.Add(analysis);
                }
            }

            float budgetPerStat = team.Budget / this.stats.Count;

            this.allAggregates = new List <PlayerAggregate>();
            foreach (PlayerAggregate agg in playerAnalysis.Values)
            {
                agg.Summarize(budgetPerStat, this.stats);
                this.allAggregates.Add(agg);
            }

            this.allAggregates.Sort((x, y) => y.ProjectedValue.CompareTo(x.ProjectedValue));
            this.filteredAggregates = new List <PlayerAggregate>();
            this.UpdatePlayerFilter();
            this.WordWheelPlayers();
            this.UpdateWB();

            this.lvAnalysis.BeginUpdate();
            int columnWidth = this.lvAnalysis.Width / (lc.ScoringStatExtractors.Count + lc.SupportingStatExtractors.Count + 1);

            this.lvAnalysis.Columns.Add("Player Name", columnWidth);
            foreach (IStatExtractor extractor in lc.ScoringStatExtractors.Union(lc.SupportingStatExtractors))
            {
                ColumnHeader column = new ColumnHeader();
                column.Text  = extractor.StatName;
                column.Width = columnWidth;
                if (!extractor.MoreIsBetter)
                {
                    column.Tag = "asc";
                }

                this.lvAnalysis.Columns.Add(column);
            }
            this.lvAnalysis.EndUpdate();

            this.UpdatePlayerListView(league.AllPlayers);
        }
Пример #12
0
        private void OnGetTopFreeAgentSwaps(object sender, EventArgs e)
        {
            PromptFromList prompt = new PromptFromList("Select Team", this.league.Teams.Select(t => t.Name));

            if (prompt.ShowDialog() == DialogResult.OK)
            {
                string html = FantasyAlgorithms.RosterAnalysis.GetTopNFreeAgentPickups(this.league.Clone(), LeagueConstants.For(this.league.FantasyLeague).ScoringStatExtractors, prompt.SelectedItem);
                this.wbOut.DocumentText = html;
            }
        }
Пример #13
0
 private void OnLaunchPlayerGroupAnalysisCenter(object sender, EventArgs e)
 {
     new PlayerGroupCenter("All players", LeagueConstants.For(this.league.FantasyLeague), this.league.AllPlayers).Show();
 }
Пример #14
0
        public TeamStatCenter(League league, TeamAnalysis team)
        {
            InitializeComponent();
            this.Text = string.Format("Team Stat Center: {0}", team.Team.Name);

            LeagueConstants lc = LeagueConstants.For(league.FantasyLeague);

            this.lv.BeginUpdate();
            int columnWidth = lv.Width / (lc.ScoringStatExtractors.Count + 2);

            lv.Columns.Add("Player Name", columnWidth);
            lv.Columns.Add("Player Status", columnWidth);
            foreach (IStatExtractor extractor in lc.ScoringStatExtractors)
            {
                ColumnHeader column = new ColumnHeader();
                column.Text  = extractor.StatName;
                column.Width = columnWidth;
                lv.Columns.Add(column);
            }

            Dictionary <string, int> statToPlayerCount = new Dictionary <string, int>();

            foreach (IPlayer player in team.Players)
            {
                ListViewItem item = new ListViewItem(player.Name);
                item.SubItems.Add(player.Status);
                foreach (IStatExtractor extractor in lc.ScoringStatExtractors)
                {
                    IStatValue value = extractor.Extract(player);
                    if (value != null)
                    {
                        item.SubItems.Add(value.Value.ToString());
                        if (!statToPlayerCount.ContainsKey(extractor.StatName))
                        {
                            statToPlayerCount[extractor.StatName] = 1;
                        }
                        else
                        {
                            statToPlayerCount[extractor.StatName]++;
                        }
                    }
                    else
                    {
                        item.SubItems.Add(string.Empty);
                    }
                }
                this.lv.Items.Add(item);
            }

            ListViewItem total   = new ListViewItem("Totals");
            ListViewItem average = new ListViewItem("Average");

            total.SubItems.Add(string.Empty);   // player status
            average.SubItems.Add(string.Empty); // player status
            foreach (IStatExtractor extractor in lc.ScoringStatExtractors)
            {
                float value;
                if (team.Stats.TryGetValue(extractor.StatName, out value))
                {
                    total.SubItems.Add(value.ToString());
                    int count;
                    if (statToPlayerCount.TryGetValue(extractor.StatName, out count))
                    {
                        average.SubItems.Add((value / (float)count).ToString());
                    }
                    else
                    {
                        average.SubItems.Add(string.Empty);
                    }
                }
                else
                {
                    total.SubItems.Add(string.Empty);
                    average.SubItems.Add(string.Empty);
                }
            }
            this.lv.Items.Add(total);
            this.lv.Items.Add(average);
            this.lv.EndUpdate();
        }
Пример #15
0
        public AllPlayersStatCenter(League league)
        {
            InitializeComponent();

            LeagueConstants lc = LeagueConstants.For(league.FantasyLeague);

            this.lv.BeginUpdate();
            int columnWidth = lv.Width / (lc.ScoringStatExtractors.Count + lc.SupportingStatExtractors.Count + 4);

            lv.Columns.Add("Player Name", columnWidth);
            lv.Columns.Add("Fantasy Team", columnWidth);
            foreach (IStatExtractor extractor in lc.ScoringStatExtractors.Union(lc.SupportingStatExtractors))
            {
                ColumnHeader column = new ColumnHeader();
                column.Text  = extractor.StatName;
                column.Width = columnWidth;
                if (!extractor.MoreIsBetter)
                {
                    column.Tag = "asc";
                }
                lv.Columns.Add(column);
            }
            lv.Columns.Add("Average Percentile (Batter)", columnWidth);
            lv.Columns.Add("Average Percentile (Pitcher)", columnWidth);

            Dictionary <string, int>      statToPlayerCount = new Dictionary <string, int>();
            PercentilePlayerGroupAnalyzer analyzer          = new PercentilePlayerGroupAnalyzer();

            foreach (IPlayer player in league.AllPlayers)
            {
                ListViewItem item = new ListViewItem(player.Name);
                item.SubItems.Add(player.FantasyTeam);
                int percentile = 0;
                int statcount  = 0;
                foreach (IStatExtractor extractor in lc.ScoringStatExtractors.Union(lc.SupportingStatExtractors))
                {
                    IStatValue value = extractor.Extract(player);
                    if (value != null)
                    {
                        IEnumerable <IPlayer> players = league.Batters;
                        if (!player.IsBatter)
                        {
                            players = league.Pitchers;
                        }
                        percentile += analyzer.GetPercentile(extractor, players, player);
                        statcount++;
                        item.SubItems.Add(value.Value.ToString());
                        if (!statToPlayerCount.ContainsKey(extractor.StatName))
                        {
                            statToPlayerCount[extractor.StatName] = 1;
                        }
                        else
                        {
                            statToPlayerCount[extractor.StatName]++;
                        }
                    }
                    else
                    {
                        item.SubItems.Add(string.Empty);
                    }
                }

                if (player.IsBatter)
                {
                    item.SubItems.Add((percentile / statcount).ToString());
                    item.SubItems.Add(string.Empty);
                }
                else
                {
                    item.SubItems.Add(string.Empty);
                    item.SubItems.Add((percentile / statcount).ToString());
                }
                this.lv.Items.Add(item);
            }

            this.lv.EndUpdate();
        }