Beispiel #1
0
        static void RootPercentiles()
        {
            const string file = "C:\\Users\\jon_r\\OneDrive\\Documents\\FantasyData.json";

            DM.Root root = DM.Root.Load(file);

            StringBuilder sb = new StringBuilder();

            sb.Append("<HTML><BODY><H1>Analysis of 2020 Projections, Gary Sanchez Selected Among Catchers</H1><TABLE BORDER=1><TR><TD>Stat Name</TD><TD>Player Count</TD><TD>Max Value</TD><TD>Min Value</TD><TD>Graph</TD><TD>Player Percentile</TD></TR>");
            DM.DataProcessing.CountingStatExtractor extractor = new DM.DataProcessing.CountingStatExtractor(true, DM.Constants.StatID.B_HomeRuns);
            DM.Algorithms.PlayerGroupStatAnalysis   analysis  = new DM.Algorithms.PlayerGroupStatAnalysis(root.Players.Keys, GetPlayersAtPosition(root, DM.Constants.StatSource.ESPNProjections, DM.Position.C), FindPlayer(root, "gary sanchez"), extractor, root, DM.Constants.StatSource.ESPNProjections);

            byte[] img;
            using (MemoryStream stm = new MemoryStream())
            {
                analysis.Graph.Save(stm, System.Drawing.Imaging.ImageFormat.Jpeg);
                img = stm.ToArray();
            }

            sb.AppendLine($"<TR><TD>{FantasySports.DataModels.Constants.StatIDToString(extractor.StatID)}</TD><TD>{analysis.DataPoints}</TD><TD>{analysis.MaxStatValue}</TD><TD>{analysis.MinStatValue}</TD><TD><img src=\"data:image/jpg;base64,{Convert.ToBase64String(img)}\"/></TD><TD>TBD</TD></TR>");

            sb.AppendLine("</TABLE></BODY></HTML>");
            System.IO.File.WriteAllText("analysis.html", sb.ToString());
            System.Diagnostics.Process.Start("analysis.html");
        }
Beispiel #2
0
        static int FindPlayer(DM.Root root, string name)
        {
            foreach (int playerId in root.Players.Keys)
            {
                if (root.Players[playerId].Name.ToLowerInvariant() == name.ToLowerInvariant())
                {
                    return(playerId);
                }
            }

            return(-1);
        }
Beispiel #3
0
 static IEnumerable <int> GetPlayersAtPosition(DM.Root root, DM.Constants.StatSource source, DM.Position position)
 {
     foreach (int playerId in root.Players.Keys)
     {
         DM.IPlayerData data;
         if (root.Players[playerId].PlayerData.TryGetValue(source, out data))
         {
             if (data.Positions.Contains(position))
             {
                 yield return(playerId);
             }
         }
     }
 }
Beispiel #4
0
        static void SetESPN2020ProjectionsInRoot()
        {
            const string file = "C:\\Users\\jon_r\\OneDrive\\Documents\\FantasyData.json";

            DM.Root root = null;
            if (File.Exists(file))
            {
                root = DM.Root.Load(file);
            }
            else
            {
                root = DM.Root.Create();
            }

            ESPNProjections.ESPNPlayerData.LoadProjectionsIntoRoot(root);
            root.Save(file);
        }
Beispiel #5
0
        static void YahooStuff()
        {
            InitializeAuthManager().Wait();

            const string file = "C:\\Users\\jon_r\\OneDrive\\Documents\\FantasyData.json";

            DM.Root root = DM.Root.Load(file);

            YahooLeague league = YahooLeague.Create(YConstants.Leagues.Rounders2019).Result;

            Console.WriteLine("{0}", league.Name);

            Console.WriteLine("Stats:");
            foreach (DM.Constants.StatID stat in league.ScoringStats)
            {
                Console.WriteLine(" {0} ({1})", DM.Constants.StatIDToString(stat), stat);
            }
            Console.WriteLine();

            Console.WriteLine("Positions:");
            foreach (DM.Position position in league.PositionCounts.Keys)
            {
                Console.WriteLine("{0} {1}", league.PositionCounts[position], DM.Positions.ToShortString(position));
            }

            /*
             * Console.WriteLine("Teams:");
             * foreach (Team team in league.Teams)
             * {
             *  Console.WriteLine(" {0} ({1}) - {2} ({3})", team.Name, team.Key, team.ManagerName, team.ManagerEmail);
             *  foreach (string playerKey in team.PlayerKeys)
             *  {
             *      Player player = league.Players[playerKey];
             *      Console.WriteLine("   {0}", player.Name);
             *      foreach (int statId in player.Stats.Keys)
             *      {
             *          StatDefinition stat = league.Stats[statId];
             *          Console.WriteLine("      {0}: {1}", stat.Name, player.Stats[statId]);
             *      }
             *  }
             * }
             *
             * foreach (StatDefinition stat in league.Stats.Values)
             * {
             *  List<Player> players = new List<Player>();
             *  foreach (Player player in league.Players.Values)
             *  {
             *      if (player.IsBatter == (stat.PositionType == "B"))
             *      {
             *          players.Add(player);
             *      }
             *  }
             *
             *  players.Sort((a, b) => a.StatValues[stat.Id].CompareTo(b.StatValues[stat.Id]));
             *  Console.WriteLine(stat.Name);
             *
             *  int count = 0;
             *  foreach (Player player in players)
             *  {
             *      Console.WriteLine("  {0}: {1}", player.Name, player.Stats[stat.Id]);
             *      if (count++ == 15)
             *      {
             *          break;
             *      }
             *  }
             *  Console.WriteLine();
             * }
             *
             * Console.WriteLine("Standings:");
             * foreach (Standings standings in league.TeamStandings.OrderBy(s => s.Rank))
             * {
             *  Team team = league.Teams.FirstOrDefault(t => t.Key == standings.TeamKey);
             *  float total = 0;
             *  float current;
             *  foreach (string pointValue in standings.Points.Values)
             *  {
             *      if (float.TryParse(pointValue, out current))
             *      {
             *          total += current;
             *      }
             *  }
             *
             *  Console.WriteLine("{0}: {1} with {2} points", standings.Rank, team.Name, total);
             * }
             */
        }