/// Given a dictionary of player ids to players builds a fantasy team starting from start date to end date.
        /// PlayersById can be an empty Dictionary or one to be updated.
        public static FantasyTeam BuildFantasyTeam(Dictionary <string, Player> PlayersById, Dictionary <string, Player> StatsByPosition, int startDate, int endDate)
        {
            // for range of days combines players active stats
            for (int day = startDate; day <= endDate; day++)
            {
                Player[] array = GetPlayersFromDay(day);

                int index = 0;
                // Update active stats for each player in that day
                foreach (Player player in array)
                {
                    if (player != null)
                    {
                        StatsByPosition = UpdateStatsByPosition(StatsByPosition, index++, player);
                        PlayersById     = UpdatePlayersById(PlayersById, player);
                    }
                }
            }

            // Creates fantasy team and sets last day updated
            FantasyTeam team = new FantasyTeam("", PlayersById.Values.ToList());

            team.StatsByPosition = StatsByPosition;
            team.LastDayUpdated  = DayOfSeason;
            return(team);
        }
Example #2
0
 /// Prints the active stats, inactive stats, and stats by position to the console.
 public static void PrintStatsToConsole(FantasyTeam team)
 {
     Console.WriteLine("ACTIVE STATS");
     team.PrintStats(true);
     Console.WriteLine("INACTIVE STATS");
     team.PrintStats(false);
     Console.WriteLine("STATS BY POSITION");
     team.printStatsByPosition();
 }
        /// Updates fantasy team provided starting at the last day updated until current day of the season.
        public static FantasyTeam UpdateTeam(FantasyTeam team)
        {
            Dictionary <string, Player> PlayersById = new Dictionary <string, Player>();

            foreach (Player player in team.GetAllPlayers())
            {
                PlayersById.Add(player.Id, player);
            }

            return(BuildFantasyTeam(PlayersById, team.StatsByPosition, team.LastDayUpdated + 1, DayOfSeason));
        }
Example #4
0
        // static string date = DateTime.Today.ToString();

        public static void Main(string[] args)
        {
            string path = "./HTMLFiles/";

            if (args.Length > 0)
            {
                path = args[0];
            }

            // creates fantasy team.
            FantasyTeam team = HtmlParser.BuildFantasyTeam(path);

            // sort batters and pitchers.
            team.Batters  = team.SortPlayersByCategory(team.Batters, "AB", true);
            team.Pitchers = team.SortPlayersByCategory(team.Pitchers, "IP", true);

            SpreadsheetGenerator.ExportToGoogleDocsSpreadsheet(path, team);
            Console.WriteLine("Succesfully updated https://docs.google.com/spreadsheets/d/1DB3CNvXUxtK8S7ZZwKHaQ177CV1XqFAOeTK5TdhJqUs/edit#gid=0");
            // PrintStatsToConsole(team);
        }
        /// Inserts the fantasy team into the correct google docs sheet
        public static void ExportToGoogleDocsSpreadsheet(string path, FantasyTeam team)
        {
            // Authorizes google sheets api service
            var service = GoogleSheetsAPIAuthorization();

            int row = 1;
            // Writes batters active stats
            List <IList <object> > data = new List <IList <object> >();

            data.Add(new List <object>()
            {
                "LAST UPDATED: " + date
            });
            data.Add(new List <object>()
            {
                "ACTIVE BATTERS"
            });
            data.AddRange(team.GetStatsAsListOfLists(team.Batters, true, true));
            data.AddRange(team.GetTotalAsListOfLists(team.Batters, true, true));

            data.Add(new List <object>()
            {
                ""
            });
            data.Add(new List <object>()
            {
                "ACTIVE PITCHERS"
            });
            data.AddRange(team.GetStatsAsListOfLists(team.Pitchers, true, false));
            data.AddRange(team.GetTotalAsListOfLists(team.Pitchers, true, false));

            data.Add(new List <object>()
            {
                ""
            });
            data.Add(new List <object>()
            {
                "INACTIVE BATTERS"
            });
            data.AddRange(team.GetStatsAsListOfLists(team.Batters, false, true));
            data.AddRange(team.GetTotalAsListOfLists(team.Batters, false, true));

            data.Add(new List <object>()
            {
                ""
            });
            data.Add(new List <object>()
            {
                "INACTIVE PITCHERS"
            });
            data.AddRange(team.GetStatsAsListOfLists(team.Pitchers, false, false));
            data.AddRange(team.GetTotalAsListOfLists(team.Pitchers, false, false));

            data.Add(new List <object>()
            {
                ""
            });
            data.Add(new List <object>()
            {
                "STATS BY POSTION"
            });
            data.AddRange(team.GetStatsByPositionAsListOfLists());
            data.AddRange(team.GetTotalAsListOfLists(team.Batters, true, true));

            InsertData(service, SpreadSheetNameByPath[path], row, data);
        }