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())); }
private void UpdateWebView() { PercentilePlayerGroupAnalyzer analyzer = new PercentilePlayerGroupAnalyzer(); string title = "Analysis of " + this.Text; IEnumerable <IStatExtractor> extractors = this.constants.ScoringStatExtractors; if (this.currentPlayer != null) { title += " on player " + this.currentPlayer.Name; if (this.currentPlayer is Batter) { extractors = this.constants.BattingScoringStatExtractors; } else { extractors = this.constants.PitchingScoringStatExtractors; } } StringBuilder sb = new StringBuilder(); sb.Append("<HTML><BODY><H1>"); sb.Append(title); sb.Append("</H1><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>"); foreach (IStatExtractor extractor in extractors) { PlayerGroupAnalysis analysis = analyzer.Analyze(this.Text, extractor, this.allPlayers, this.currentPlayer); 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>"); } sb.AppendLine("</TABLE></BODY></HTML>"); this.wbOut.DocumentText = sb.ToString(); }