コード例 #1
0
ファイル: NFLStatsUpdate.cs プロジェクト: lancesaurusrex/FFSP
        private NFLStatsUpdate(IHubConnectionContext<dynamic> clients) {

            Clients = clients;

            _playersStats.Clear();
            //try an isLive bool, pull currentweek schedule
            using (var db = new FF()) {
                var currentWeekSchedule = db.NFLGame.Where(g => Convert.ToInt16(g.Week) == currentWeekServ && g.Year == currentYear);
                
                //Compare	DateTime t1,DateTime t2, Less than zero t1 is earlier than t2.Zero t1 is the same as t2.Greater than zero t1 is later than t2.
                foreach (var game in currentWeekSchedule) {
                    var UTCNFLgametime = TimeZoneInfo.ConvertTimeToUtc(game.DateEST);
                    if ((DateTime.Compare(DateTime.UtcNow, UTCNFLgametime)) < 0) { }   //game earlier than local time
                    else { }    //game later
                }

                livePlayerList = db.NFLPlayer.ToList();
            }

            foreach (NFLPlayer n in livePlayerList) {
                //Creating a new StatsYearWeek to track Stats with and connect with NFLPlayer
                StatsYearWeek s = new StatsYearWeek();
                SetSYWToZero(s);
                //Remember im doing this live not for stupid class demo, so ill need to make statid off of player
                s.PlayerID = n.id;
                s.Year = currentYear;     //passed in from where?
                s.Week = currentWeekServ;     //passed in from where?
                s.currentPts = 0;
                string statID = (s.Year.ToString() + s.Week.ToString() + s.PlayerID).ToString();   //YearWeekPlayerID is StatID
                s.id = Convert.ToInt32(statID);

                liveStatsList.Add(s);   //list  
                _playersStats.TryAdd(s.id, s);  //dict
            }

            livePlayerList.Clear();     //empty list

            //make a list of players that got updated and send to updatePlayer?
            //livePlayerList.ForEach(player => _players.TryAdd(player.id, player));

            r = new ReadJSONDatafromNFL("2015101200_gtd.json", "2015101200");
            r2 = new ReadJSONDatafromNFL("2015101108_gtd.json", "2015101108");
            /*****
             * NOTE- For stupid demo I have to null/comment out stats in ReadJSON
             *****/
            r.QuickParseAfterLive();
            r2.QuickParseAfterLive();
            //if timer needed
            //_timer = new Timer(UpdatePlayerStats, null, _updateInterval, _updateInterval);
        }
コード例 #2
0
        public ActionResult Scoreboard(int TeamID) {
            if (CurrentWeek > 13)
                CurrentWeek = 13;
            else {
                using (var dbsetting = new FF()) {
                    var g = dbsetting.Settings.Find(1);
                    CurrentWeek = g.CurrentWeek;
                }
            }

            //FillWeekScoreboard(int TeamID, int? numWeek)    
            var currentWeek = FillWeekScoreboard(TeamID, CurrentWeek);
            //signalr asp.net tutorial
            if (currentWeek == null)
                throw new NullReferenceException("currentWeek is null, which means games arent in the db for that week");

            return View(currentWeek);  //compiler stop bitching
        }
コード例 #3
0
ファイル: NFLStatsUpdate.cs プロジェクト: lancesaurusrex/FFSP
        //uses PlayersIDS to get List NFLPlayer objects
        //in-Ienum<int> PlayersID out-List<StatsYearWeek>
        public List<StatsYearWeek> GetAllStatsFromPlayersID(IEnumerable<int> PlayersID) {
            List<StatsYearWeek> PlayersOnTeamCol = new List<StatsYearWeek>();

            using (var FFContext = new FF()) {

                foreach (var playerID in PlayersID) {
                    StatsYearWeek st = new StatsYearWeek();
                    //changed to StatsYearWeek, key changed, need to update to new key
                    //old key- PlayerID, new key- Year+week+playerid

                    int SYWID = ConvertPlayerIDToSYWID(playerID);   //ID conversion

                    if (_playersStats.TryGetValue(SYWID, out st))  //from stats dict created in init
                        PlayersOnTeamCol.Add(st);
                    else
                        throw new Exception("PlayeronTeam in DB, not found pulling from statsdict created in init");
                }
            }

            return PlayersOnTeamCol;
        }
コード例 #4
0
ファイル: NFLStatsUpdate.cs プロジェクト: lancesaurusrex/FFSP
        //Uses TeamController function to getallplayersIDonteam with teamID
        //In-TeamID using FFTEAMNFLPLAYER Out-ints of NFLPlayersID on teamID
        public List<int> GetAllPlayersIDOnTeam(int TeamID) {
            List<int> FindPlayersOnTeam;
            using (var FFContext = new FF()) {

                //pulling from NFLPlayerTeam DB, which are not NFLPlayer.
                var temp = (from p in FFContext.FFTeamNFLPlayer where p.TeamID == TeamID select p.PlayerID);
                FindPlayersOnTeam = temp.ToList();
            }
            return FindPlayersOnTeam;
        }
コード例 #5
0
ファイル: NFLStatsUpdate.cs プロジェクト: lancesaurusrex/FFSP
        //could do this is GetAllPlayersonTeam but want to split up due to home/away (2teams) easier to debug
        public int GetAwayTeamIDFromGameID(int GameID) {

            FFGame currentGame;
            using (var FFContext = new FF()) {

                currentGame = FFContext.FFGameDB.Find(GameID);
            }
            return (int)currentGame.VisTeamID;
        }
コード例 #6
0
ファイル: NFLStatsUpdate.cs プロジェクト: lancesaurusrex/FFSP
        public void EndWeek() {
            using (var db = new FF()) {
                var game = db.FFGameDB.Find(gameID);
                FFLeague League = db.FFLeagueDB.Find(game.FFLeagueID);
                //RunLive updates score in ffgamedb

                var allGamesInCurrWeek = db.FFGameDB.Where(x => x.Week == currentWeekServ).ToList();

                foreach (FFGame g in allGamesInCurrWeek) {
                    int homeID;
                    int awayID;
                    FFTeam HomeTeam;
                    FFTeam VisTeam;
                    //pull teams if null
                    if (g.HomeTeam != null) {
                        homeID = (int)g.HomeTeamID;
                        HomeTeam = db.FFTeamDB.Find(g.HomeTeamID);
                        if (g.HScore == null) {
                            g.HScore = 0;
                        }
                    }
                    else
                        throw new Exception("FFGame Hometeam null");

                    if (g.VisTeam != null) {
                        awayID = (int)g.VisTeamID;
                        VisTeam = db.FFTeamDB.Find(g.VisTeamID);
                        if (g.VScore == null) {
                            g.VScore = 0;
                        }
                    }
                    else
                        throw new Exception("FFGame Visteam null");

                    //these shouldn't work
                    foreach (NFLPlayer p in g.HomeTeam.Players) {
                        g.HScore += p.currentPts;
                    }

                    foreach (NFLPlayer p in g.VisTeam.Players) {
                        g.VScore += p.currentPts;
                    }

                    db.Entry(HomeTeam).State = System.Data.Entity.EntityState.Unchanged;
                    db.Entry(VisTeam).State = System.Data.Entity.EntityState.Unchanged;

                    //win/loss
                    if (g.HScore > g.VScore) {
                        //HomeTeam Won
                        g.HomeTeam.Win += 1;
                        g.VisTeam.Lose += 1;
                    }
                    else if (g.VScore > g.HScore) {
                        //VisTeam Won
                        g.HomeTeam.Lose += 1;
                        g.VisTeam.Win += 1;
                    }
                    else {
                        //Tie
                        g.HomeTeam.Tie += 1;
                        g.VisTeam.Tie += 1;
                    }

                    g.HomeTeam.FPTotal += (decimal)g.HScore;
                    g.VisTeam.FPTotal += (decimal)g.VScore;
                    //delete temp proj, add currentWeek to db and update


                    db.SaveChanges();
                }
                var sett = db.Settings.Find(1);
                db.Entry(sett).State = System.Data.Entity.EntityState.Unchanged;
                sett.CurrentWeek++;
                currentWeekServ = sett.CurrentWeek;

                db.SaveChanges();
                //Check this dont think need it
                //Clients.All.OnDisconnected(true);
            }
        }
コード例 #7
0
ファイル: NFLStatsUpdate.cs プロジェクト: lancesaurusrex/FFSP
        private void tempsavetodb() {
            using (var db = new FF()) {

                var game = db.FFGameDB.Find(gameID);
                db.Entry(game).State = System.Data.Entity.EntityState.Unchanged;
                decimal total = new decimal();
                foreach (var h in _homePlayers)
                    total += h.Value.currentPts;

                game.HScore = total;
                total = 0;
                foreach (var a in _awayPlayers)
                    total += a.Value.currentPts;

                game.VScore = total;

                foreach (var n in _playersStats)
                    db.NFLPlayerStats.Add(n.Value);

                db.SaveChanges();
            }
        }
コード例 #8
0
    public void DeserializePlayerStats(JObject homeStats, string homeTeam, JObject awayStats, string awayTeam) {

        //This is the names of the two different properties in the JSON 
        JObject homePassing = (JObject)homeStats["passing"];
        JObject awayPassing = (JObject)awayStats["passing"];
        //Need something of all stats subcategories strings 
        //List<string> StatsChildren = new List<string>(new string[] { "passing", "rushing", "receiving", "fumbles", "kicking" });
        Dictionary<string, string> StatsChildren = new Dictionary<string, string> {
            {"passing", "PassingStats"},
            {"rushing", "RushingStats"},
            {"receiving", "ReceivingStats"},
            {"fumbles", "FumbleStats"},
            {"kicking", "KickingStats"}
         };
        //playerIDKeys.AddRange(awayPassing.Properties().Select(p => p.Name).ToList());
        Dictionary<string, JObject> JObjectHomeAway = new Dictionary<string, JObject>();
        JObjectHomeAway.Add("homeStats", homeStats);
        JObjectHomeAway.Add("awayStats", awayStats);
        List<string> playerIDStringKeys = new List<string>();
        List<NFLPlayer> PlayerList = new List<NFLPlayer>();     //List of made NFL Players

        using (var db = new FF()) {
            //goes by passing, rushing, rec, etc. goes by home/away player
            foreach (KeyValuePair<string, string> child in StatsChildren) {
                foreach (KeyValuePair<string, JObject> objName in JObjectHomeAway) {

                    JObject statsJObj = objName.Value;   //passed in from dict, is either the homeStats or awayStats jObject
                    string objPropertyName = objName.Key;
                    JObject getIDs = (JObject)statsJObj[child.Key];

                    playerIDStringKeys.AddRange(getIDs.Properties().Select(p => p.Name).ToList());
                    
                    foreach (string playerID in playerIDStringKeys) {
                        /*PsC - Create list of players
                          Get PlayerID of player about to be added
                         Compare to List of players
                         If Found*/
                        NFLPlayer NFLFoundPlayer = null;                       

                            string s = RemoveSpecialCharacters(playerID);   //converts string to int, need int for the key, need string to search JOBject
                            int playerIDInt = Convert.ToInt32(s);

                        //going through the list of already made players and pulling the player if the id's match
                        //if found add stats according to child (pass,rec, rush, etc)
                        //if not found, create player and copy material
                        if (PlayerList.Count() != 0) {
                            NFLFoundPlayer = PlayerList.Find(x => x.id == playerIDInt);
                        }


                        //Player not found if null, so create and fill in player info
                        if (NFLFoundPlayer == null) {
                            NFLFoundPlayer = new NFLPlayer();

                            NFLFoundPlayer.id = playerIDInt;    //PlayerID in int format
                            NFLFoundPlayer.id_nflformat = playerID;     //PlayerID in NFL string format
                            //Using homeStats and awayStats as property names., jObj is home or awayStats jObject                  
                            NFLFoundPlayer.name = statsJObj[child.Key][playerID]["name"].ToString();

                            if (objPropertyName == "homeStats") {
                                NFLFoundPlayer.team = homeTeam;
                            }
                            else if (objPropertyName == "awayStats") {
                                NFLFoundPlayer.team = awayTeam;
                            }
                            else {
                                NFLFoundPlayer.team = "XXX";
                            }

                        }
                        else { }

                        //Finds the correct type of stats with the playerId and puts it into a JOnject
                        var statsPullJSON = statsJObj[child.Key][playerID];

                        //takes pulled stats and adds them to the FoundPlayer
                        //if (child.Key == "passing") {
                        //    NFLFoundPlayer.PassingStats = null;//(PassingGameStats)statsPullJSON.ToObject(typeof(PassingGameStats));
                        //}
                        //else if (child.Key == "rushing") {
                        //    NFLFoundPlayer.RushingStats = null;// (RushingGameStats)statsPullJSON.ToObject(typeof(RushingGameStats));
                        //}
                        //else if (child.Key == "receiving") {
                        //    NFLFoundPlayer.ReceivingStats = null;//  (ReceivingGameStats)statsPullJSON.ToObject(typeof(ReceivingGameStats));
                        //}
                        //else if (child.Key == "fumbles") {
                        //    NFLFoundPlayer.FumbleStats = null;// (FumbleGameStats)statsPullJSON.ToObject(typeof(FumbleGameStats));
                        //}
                        //else if (child.Key == "kicking") {
                        //    NFLFoundPlayer.KickingStats = null;// (KickingGameStats)statsPullJSON.ToObject(typeof(KickingGameStats));
                        //}
                        //else { //throw exception
                        //}

                        //add in NFLPlayer to Playerlist and DB,  sep function?    
                        var dbaddorupdate = PlayerList.Find(x => x.id == NFLFoundPlayer.id);
                        if (dbaddorupdate == null)
                        {
                            PlayerList.Add(NFLFoundPlayer);
                        }
                        //checking to see if found in db if not add 
                        //Fix this sometime not sure of better way
                        var dbcheck = db.NFLPlayer.Find(NFLFoundPlayer.id);

                        if (dbcheck == null) 
                            db.NFLPlayer.Add(NFLFoundPlayer);
                        else 
                            db.Entry(NFLFoundPlayer).State = EntityState.Modified;
                            
                        db.SaveChanges();
                        //empty keys for next iteration
                    }
                    playerIDStringKeys.Clear();
                }
            }            
        }
    }