// function to fill a user's team
        public List <GeneralPlayer> FillTeam(NFLv3StatsClient client)
        {
            List <GeneralPlayer> playersTeam = new List <GeneralPlayer>();
            GeneralPlayer        player      = new GeneralPlayer();

            // going to set a default team to size 7: 1 QB 2 RB 2 WR 1 TE 1 K not including ST/Def
            for (var i = 0; i < 7; i++)
            {
                do
                {
                    player      = new GeneralPlayer(); // Resets player fields so they do not repeat if null ie found some null bye weeks
                    player.name = GetPlayersName();
                    GetPlayerInfo(player, client);
                    if (player.playerID == 0)
                    {
                        Console.WriteLine("It appears that player does not exist or their name is spelled incorrectly.");
                        Console.WriteLine("Please try again.");
                    }
                } while (player.playerID == 0); // if a playerID is not 0 then a player with that name exists

                if (player.position == "QB")
                {
                    playersTeam.Add(new Quarterback(player.name, player.playerID, player.team, player.position, player.number, player.byeWeek));
                }
                if (player.position == "RB" || player.position == "WR" || player.position == "TE")
                {
                    playersTeam.Add(new WRRBTE(player.name, player.playerID, player.team, player.position, player.number, player.byeWeek));
                }
                if (player.position == "K")
                {
                    playersTeam.Add(new Kicker(player.name, player.playerID, player.team, player.position, player.number, player.byeWeek));
                }
            }
            return(playersTeam);
        }
Example #2
0
        //Returns a list of all games in the current NFL season - DataType = Score
        public List <Score> GetUpcomingSchedule()
        {
            NFLv3StatsClient client = new NFLv3StatsClient(SportsDataioKey);
            int?currentSeason       = client.GetCurrentSeason();

            return(client.GetScores(currentSeason.ToString()));
        }
        public void GetKickerStats(Kicker k, NFLv3StatsClient client, int week)
        {
            var tmpPlayer = client.GetPlayerGameStatsByPlayerID("2018", week, k.playerID);

            if (tmpPlayer != null)
            {
                k.epAtt  = (int)tmpPlayer.ExtraPointsAttempted;
                k.epMade = (int)tmpPlayer.ExtraPointsMade;
                k.fgAtt  = (int)tmpPlayer.FieldGoalsAttempted;
                k.fgMade = (int)tmpPlayer.FieldGoalsMade;
            }
            else
            {
                k = new Kicker();
            }
        }
        static void Main(string[] args)
        {
            // Connect to client and get data
            var client  = new NFLv3StatsClient("api_key_goes_here");
            var players = client.GetPlayers();

            // Write data to console
            foreach (var player in players)
            {
                Console.WriteLine($"{player.PlayerID} - {player.Name} - {player.Team}");
            }

            Console.WriteLine();
            Console.WriteLine("Press enter to continue...");
            Console.ReadLine();
        }
        public void GetWRRBTEStats(WRRBTE b, NFLv3StatsClient client, int week)
        {
            var tmpPlayer = client.GetPlayerGameStatsByPlayerID("2018", week, b.playerID);

            if (tmpPlayer != null)
            {
                b.fumbles = (int)tmpPlayer.Fumbles;
                b.rushAtt = (int)tmpPlayer.RushingAttempts;
                b.rushYds = (double)tmpPlayer.RushingYards;
                b.rushTDs = (int)tmpPlayer.RushingTouchdowns;
                b.rec     = (int)tmpPlayer.Receptions;
                b.recYds  = (double)tmpPlayer.ReceivingYards;
                b.recTDs  = (int)tmpPlayer.ReceivingTouchdowns;
            }
            else
            {
                b = new WRRBTE();
            }
        }
        // seperates the list into lists of player types and then gets their stats
        public void GetStats(List <GeneralPlayer> list, NFLv3StatsClient client, int week)
        {
            var quarters = list.OfType <Quarterback>();
            var wrrbtes  = list.OfType <WRRBTE>();
            var kicker   = list.OfType <Kicker>();

            foreach (var q in quarters)
            {
                q.GetQBStats(q, client, week);
            }

            foreach (var wr in wrrbtes)
            {
                wr.GetWRRBTEStats(wr, client, week);
            }

            foreach (var k in kicker)
            {
                k.GetKickerStats(k, client, week);
            }
        }
        public void GetQBStats(Quarterback q, NFLv3StatsClient client, int week)
        {
            var currSeason = "2018";
            var tmpPlayer  = client.GetPlayerGameStatsByPlayerID(currSeason, week, q.playerID);

            if (tmpPlayer != null)
            {
                q.fumbles = (int)tmpPlayer.Fumbles;
                q.passAtt = (int)tmpPlayer.PassingAttempts;
                q.passCmp = (int)tmpPlayer.PassingCompletions;
                q.passYds = (double)tmpPlayer.PassingYards;
                q.passTDs = (int)tmpPlayer.PassingTouchdowns;
                q.interc  = (int)tmpPlayer.Interceptions;
                q.sacks   = (int)tmpPlayer.Sacks;
                q.rushYds = (double)tmpPlayer.RushingYards;
                q.rushTDs = (int)tmpPlayer.RushingTouchdowns;
            }
            else
            {   // if the player did not play that week for a reason other than a bye wekk their stats will be zero'd
                // this was necessary because the API does not maintain weekly records for inactive players
                q = new Quarterback();
            }
        }
        // function to get the playerID
        public void GetPlayerInfo(GeneralPlayer f, NFLv3StatsClient client)
        {
            // utilizes the SDK's class to pull data. could not come up with another way
            Predicate <Player> playerFinder = (Player p) => { return(p.Name == f.name); };

            var tmpPlayer = client.GetPlayers().Find(playerFinder);

            if (tmpPlayer != null)
            {
                f.playerID = tmpPlayer.PlayerID;
                f.team     = tmpPlayer.Team;
                f.position = tmpPlayer.Position;
                f.number   = (int)tmpPlayer.Number;
                if (tmpPlayer.ByeWeek != null)
                {
                    f.byeWeek = (int)tmpPlayer.ByeWeek;
                }
            }
            else
            {
                Console.WriteLine("Error!");
            }
        }
Example #9
0
 public NFLService()
 {
     _client = new NFLv3StatsClient(SportDataKey);
 }
Example #10
0
        static void Main(string[] args)
        {
            // Connect to client and get data
            // Please grab your own free apikey SportsData.io
            NFLv3StatsClient client = new NFLv3StatsClient("apikey");
            //var projections = client.GetTeamGameStats("2018", 7).OrderByDescending(p => p.PasserRating).Take(20).ToList();

            var  week  = 0;
            bool onBye = false;

            string               teamName = "";
            GeneralPlayer        play     = new GeneralPlayer();
            List <GeneralPlayer> teamList = new List <GeneralPlayer>();

            var userChoice = 1;

            while (userChoice != 6)
            {
                userChoice = Menu.DisplayMenu();
                switch (userChoice)
                {
                case 1:
                    Console.WriteLine("Create Team");
                    var team = new List <GeneralPlayer>();
                    team     = play.FillTeam(client);
                    teamList = team;
                    break;

                case 2:
                    if (teamList.Count() == 0)
                    {
                        Console.WriteLine("Please create or access a saved team first!\n");
                        break;
                    }
                    Database.SaveTeam(teamList);
                    Console.WriteLine("Team Saved\n");
                    break;

                case 3:
                    if (teamList.Count() == 0)
                    {
                        Console.WriteLine("Please create or access a saved team first!\n");
                        break;
                    }
                    week  = play.GetStatWeek();
                    onBye = play.CheckByes(teamList, week);
                    if (onBye)
                    {
                        break;
                    }              // exits this case because a new team needs to be selected
                    play.GetStats(teamList, client, week);
                    play.PrintStats(teamList);
                    break;

                case 4:
                    teamName = Database.ListTeams();
                    teamList = Database.GetSavedTeam(teamName);
                    break;

                case 5:
                    if (teamList.Count() == 0)
                    {
                        Console.WriteLine("Please create or access a saved team first!\n");
                        break;
                    }
                    var ppr = FantasyPoints.GetPPR();
                    FantasyPoints.CalcFantasyPoints(teamList, ppr);
                    FantasyPoints.PrintFantasyPoints(teamList);
                    break;
                }
            }
        }
Example #11
0
        //Returns current week, Current season, week start, and week end
        public List <Timeframe> GetSeasonDates()
        {
            NFLv3StatsClient client = new NFLv3StatsClient(SportsDataioKey);

            return(client.GetTimeframes("upcoming"));
        }