public static void MarkPlayerStatsFinal(Games game, NPGGFFLDataContext context)
 {
     if (game.IsFinal == 1)
     {
         context.ExecuteCommand("update playerstats set isfinal = 1 where gameid = {0} and isfinal = 0", (new string[] { game.GameId.ToString() }));
     }
 }
示例#2
0
        private static void LoadRostersNewWeek()
        {
            try
            {
                NPGGFFLDataContext context = new NPGGFFLDataContext(ConfigurationManager.ConnectionStrings["NPGGFFLConnectionString"].ConnectionString);
                var TriggerDate = DateTime.Now.AddDays(-7);
                var lastSeasonWeek = context.SeasonWeeks.Where(sw => sw.StartDtm <= TriggerDate && sw.EndDtm >= TriggerDate).First();
                var currentSeasonWeek = context.SeasonWeeks.Where(sw => sw.StartDtm <= DateTime.Now && sw.EndDtm >= DateTime.Now).First();
                foreach (var o in context.Owners)
                {
                    var teamLastWeek = context.OwnerTeams.Where(ot => ot.SeasonWeekId == lastSeasonWeek.SeasonWeekId && ot.OwnerId == o.OwnerId);
                    var teamThisWeek = context.OwnerTeams.Where(ot => ot.SeasonWeekId == currentSeasonWeek.SeasonWeekId && ot.OwnerId == o.OwnerId);

                    if (teamThisWeek.Count() == 0)
                    {
                        foreach (var tlw in teamLastWeek)
                        {
                            OwnerTeams ownerTeam = new OwnerTeams { OwnerId = o.OwnerId, SeasonWeekId = currentSeasonWeek.SeasonWeekId, PlayerId = tlw.PlayerId, IsLocked = false, TeamId = tlw.TeamId };
                            context.OwnerTeams.InsertOnSubmit(ownerTeam);
                        }
                        context.SubmitChanges();
                    }
                }

            }
            catch (Exception)
            {
                throw;
            }
        }
示例#3
0
        public static List<Games> GetGames(NPGGFFLDataContext context, int year, int seasonType, int weekNum)
        {
            var games = new List<Games>();
            Regex gameRX = new Regex("gameId=[0-9]+");
            var url = string.Format("{0}/{1}", GAME_URL, string.Format("_/year/{0}/seasontype/{1}/week/{2}", year.ToString(), seasonType.ToString(), weekNum.ToString()));
            var html = HelperMethods.LoadHtmlFromUrl(url);
            var gameIds = gameRX.Matches(html);

            foreach (Match gId in gameIds)
            {
                var gameId = System.Convert.ToInt32(gId.Value.Replace("gameId=", string.Empty));

                if (!games.Select(g => g.GameId).Contains(gameId))
                {
                    try
                    {
                        var teamsForGame = GetTeamsByGame(gameId);

                        var homeTeam = context.Teams.Where(t => t.Abbreviation.ToUpper().Equals(teamsForGame["home"])).FirstOrDefault();
                        var awayTeam = context.Teams.Where(t => t.Abbreviation.ToUpper().Equals(teamsForGame["away"])).FirstOrDefault();

                        Games game = new Games();
                        game.GameId = gameId;
                        game.HomeTeamId = homeTeam.TeamId;
                        game.AwayTeamId = awayTeam.TeamId;
                        game.GameDtm = GetGameDate(gameId);
                        games.Add(game);
                    }
                    catch { }
                }
            }

            return games.Distinct().ToList();
        }
示例#4
0
        private static void LockCurrentWeek()
        {
            try
            {
                NPGGFFLDataContext context = new NPGGFFLDataContext(ConfigurationManager.ConnectionStrings["NPGGFFLConnectionString"].ConnectionString);
                var TriggerDate = DateTime.Now;
                var currentSeasonWeek = context.SeasonWeeks.Where(sw => sw.StartDtm <= TriggerDate && sw.EndDtm >= TriggerDate).First();
                //var currentSeasonWeek = context.SeasonWeeks.Where(sw => sw.SeasonYear == 2015 && sw.SeasonTypeId == 2 && sw.WeekNum == 4).First();
                foreach (var ot in context.OwnerTeams.Where(ot => ot.SeasonWeekId == currentSeasonWeek.SeasonWeekId && ot.IsLocked == false))
                {
                    ot.IsLocked = true;
                }
                var gamesThisWeek = context.Games.Where(g => g.SeasonWeekId == currentSeasonWeek.SeasonWeekId && g.IsLocked == false);
                foreach (var g in gamesThisWeek)
                {
                    //var playersInGame = context.Players.Where(p => p.TeamId == g.HomeTeamId || p.TeamId == g.AwayTeamId);
                    //foreach (var player in playersInGame)
                    //{
                    //    var ownerTeamPlayers = context.OwnerTeams.Where(ot => ot.PlayerId == player.PlayerId && ot.SeasonWeekId == currentSeasonWeek.SeasonWeekId);
                    //    foreach (var otp in ownerTeamPlayers)
                    //    {
                    //        otp.IsLocked = true;
                    //    }
                    //}
                    g.IsLocked = true;
                }

                context.SubmitChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#5
0
        public static void GetDefensiveTDs(NPGGFFLDataContext context, Games game)
        {
            var foxSeasonType = (game.SeasonWeeks.SeasonTypeId == 1 ? 3 : (game.SeasonWeeks.SeasonTypeId == 2 ? 1 : 2));    //preseason = 3, reg season = 1, postseason = 2
            var foxScheduleUrl = string.Format("{0}?season={1}&seasonType={2}&week={3}", new string[] { SCHEDULE_URL, game.SeasonWeeks.SeasonYear.ToString(), foxSeasonType.ToString(), game.SeasonWeeks.WeekNum.ToString() });
            var foxLeagueUrl = string.Format("{0}?season={1}", new string[] { LEAGUE_URL, game.SeasonWeeks.SeasonYear.ToString() });

            var leagueJson = JObject.Parse(HelperMethods.GetJsonFromUrl(foxLeagueUrl));
            var scheduleJson = JArray.Parse(HelperMethods.GetJsonFromUrl(foxScheduleUrl));

            var awayTeam = GetFoxTeam(leagueJson, game.AwayTeam.FoxAbbreviation.ToUpper());
            var homeTeam = GetFoxTeam(leagueJson, game.HomeTeam.FoxAbbreviation.ToUpper());
            var gameUrl = string.Format("{0}{1}&type=3", HOST, GetFoxBoxscoreUrl(scheduleJson, awayTeam, homeTeam));

            var html = HelperMethods.LoadHtmlFromUrl(gameUrl);
            var dom = new CQ(html, HtmlParsingMode.Document);

            var dTDs = dom["div[class*='wisfb_bsTeamStats']"].Find("tr[class*='wisfb_bstsTotal wisfb_bstsGroupTop']:contains('DEF TDs')");
            if (dTDs.Length > 0)
            {
                var awayDefensiveTDs = Convert.ToInt32(dTDs.Find("td[class*='wisfb_bstsStat']")[0].Cq().Html());
                var homeDefensiveTDs = Convert.ToInt32(dTDs.Find("td[class*='wisfb_bstsStat']")[1].Cq().Html());

                context.PlayerStats.Where(ps => ps.GameId == game.GameId && ps.PlayerId == game.AwayTeamId).First().DefensiveTDs = awayDefensiveTDs;
                context.PlayerStats.Where(ps => ps.GameId == game.GameId && ps.PlayerId == game.HomeTeamId).First().DefensiveTDs = homeDefensiveTDs;
                context.SubmitChanges();
            }
        }
 public static void LockPlayersAndStartStats(Games game, NPGGFFLDataContext context)
 {
     if (!game.IsStarted)
     {
         var startDtm = DateTime.Now;
         var seasonWeek = context.SeasonWeeks.Where(sw => sw.StartDtm <= game.GameDtm && sw.EndDtm >= game.GameDtm).First();
         context.ExecuteCommand("update games set IsLocked = 1, IsStarted = 1 where SeasonWeekId = {0} and GameId = {1}", (new string[] { seasonWeek.SeasonWeekId.ToString(), game.GameId.ToString() }));
         context.ExecuteCommand("update OwnerTeams set IsLocked = 1 where islocked = 0 and seasonweekid = {0} and exists (select 1 from players p where p.playerid = playerid and exists (select 1 from games g where g.seasonweekid = {1} and g.GameId = {2} and (g.HomeTeamId = p.teamid or g.AwayTeamId = p.TeamId)))", (new string[] { seasonWeek.SeasonWeekId.ToString(), seasonWeek.SeasonWeekId.ToString(), game.GameId.ToString() }));
         context.ExecuteCommand("insert into playerstats (playerid, gameid) select p.playerid, g.gameid from players p, games g WHERE (g.hometeamid = p.teamid or g.awayteamid = p.teamid) and g.seasonweekid = {0} and g.GameId = {1} and not exists (select 1 from playerstats ps where ps.playerid = p.playerid and ps.gameid = g.gameid)", (new string[] { seasonWeek.SeasonWeekId.ToString(), game.GameId.ToString() }));
         Console.WriteLine("Lock Players & Start Stats took " + (DateTime.Now - startDtm).TotalSeconds);
     }
 }
示例#7
0
 private static void LoadLineups()
 {
     NPGGFFLDataContext context = new NPGGFFLDataContext(ConfigurationManager.ConnectionStrings["NPGGFFLConnectionString"].ConnectionString);
     try
     {
         var TriggerDate = DateTime.Now;
         LineupLoader.LoadLineups(context, TriggerDate);
     }
     catch (Exception)
     {
         throw;
     }
 }
 public static PlayerStats InsertPlayerStatsByPlayerIdGameId(NPGGFFLDataContext context, int playerId, int gameId)
 {
     var playerStatsExist = context.PlayerStats.Where(ps => ps.PlayerId == playerId && ps.GameId == gameId).FirstOrDefault();
     if (playerStatsExist == null)
     {
         context.ExecuteCommand("insert into playerstats (playerid, gameid) values ({0}, {1})", (new string[] { playerId.ToString(), gameId.ToString() }));
         return context.PlayerStats.Where(ps => ps.PlayerId == playerId && ps.GameId == gameId).FirstOrDefault();
     }
     else
     {
         return playerStatsExist;
     }
 }
示例#9
0
 public static void UpdateStatsByGame(Games game, NPGGFFLDataContext context)
 {
     try
     {
         Console.WriteLine(string.Format("{0}: {1} vs. {2}", "Getting Stats for game", game.HomeTeam.Name, game.AwayTeam.Name));
         var scoreStripJson = JObject.Parse(HelperMethods.GetJsonFromUrl(string.Format(SS_URL, HelperMethods.CacheBuster())));
         var eid = scoreStripJson["gms"].Where(g => g["vnn"].Value<string>().ToUpper().Equals(game.AwayTeam.Name.ToUpper())).FirstOrDefault()["eid"].Value<string>();
         var gameCenterJson = JObject.Parse(HelperMethods.GetJsonFromUrl(string.Format(GAMECENTER_URL, eid, HelperMethods.CacheBuster())));
         if (gameCenterJson.Count != 0)
         {
             GeneralScraperMethods.LockPlayersAndStartStats(game, context);
             UpdateStats(game, context, eid, gameCenterJson);
             GeneralScraperMethods.MarkPlayerStatsFinal(game, context);
         }
     }
     catch { }
 }
示例#10
0
        public static void GetPlayerTeams(NPGGFFLDataContext context)
        {
            var players = context.Players.Select(p => new {
                            PlayerName = p.Name,
                            PlayerId = p.PlayerId,
                            TeamId = p.TeamId,
                            LatestGameAwayTeamId = (p.PlayerStats.OrderByDescending(ps => ps.Games.SeasonWeekId).FirstOrDefault() == null ? 0 : p.PlayerStats.OrderByDescending(ps => ps.Games.SeasonWeekId).FirstOrDefault().Games.AwayTeamId),
                            LatestGameHomeTeamId = (p.PlayerStats.OrderByDescending(ps => ps.Games.SeasonWeekId).FirstOrDefault() == null ? 0 : p.PlayerStats.OrderByDescending(ps => ps.Games.SeasonWeekId).FirstOrDefault().Games.HomeTeamId),
                            Player = p
                        })
            .Where(p => p.LatestGameAwayTeamId != p.TeamId && p.LatestGameHomeTeamId != p.TeamId && p.LatestGameAwayTeamId != 0 && p.LatestGameHomeTeamId != 0)
            .Select(p => p.Player);

            foreach (var player in players)
            {
                var url = string.Format("{0}/{1}", PLAYER_URL, player.PlayerId.ToString());
                var html = HelperMethods.LoadHtmlFromUrl(url);
                CQ dom = new CQ(html, HtmlParsingMode.Document);
                var playerName = string.Empty;
                var position = string.Empty;
                var team = string.Empty;

                try
                {
                    //playerName = dom["div[class*='mod-content']"].Find("h1").Html().Trim();
                    //position = dom["div[class*='player-bio']"].Find("ul[class*='general-info']").Find("li[class*='first']").Html().Trim();
                    team = dom["ul[class*='general-info']"].Find("a[href*='/team/']").Attr("href").Split('/')[7].Trim();
                }
                catch { }

                var playerTeam = context.Teams.Where(t => t.Abbreviation.ToUpper().Equals(team.ToUpper())).FirstOrDefault();
                if (playerTeam != null)
                {
                    player.TeamId = playerTeam.TeamId;
                    context.SubmitChanges();
                }
                else
                {
                    player.TeamId = 35; //no team
                    context.SubmitChanges();
                }
            }
        }
示例#11
0
        private static Players InsertPlayerById(NPGGFFLDataContext context, string playerId, string playerName)
        {
            var playerExists = context.Players.Where(p => p.NFLPlayerId.Equals(playerId)).FirstOrDefault();
            if (playerExists == null)
            {
                var html = HelperMethods.LoadHtmlFromUrl(string.Format(PLAYER_PROFILE_URL, playerId));
                CQ dom = new CQ(html, HtmlParsingMode.Document);
                playerName = dom["span[class*='player-name']"].Html().Replace("&nbsp;", string.Empty).Trim().ToUpper();

                playerExists = context.Players.Where(p => p.Name.ToUpper().Trim().Equals(playerName)).FirstOrDefault();

                if (playerExists != null)
                {
                    playerExists.NFLPlayerId = playerId;
                    context.SubmitChanges();
                }

                return playerExists;
            }
            else
            {
                return playerExists;
            }
        }
示例#12
0
        public WinsLosses GetWinsLosses(NPGGFFLDataContext context, int teamId, int seasonWeekId)
        {
            var seasonWeek = context.SeasonWeeks.Where(sw => sw.SeasonWeekId == seasonWeekId).FirstOrDefault();

            var query = NPGGFFLApi.queries.WinsLossesQuery;
            query = query.Replace("{{:TeamFilter}}", string.Format("t.teamid = {0}", teamId.ToString() ));
            query = query.Replace("{{:SeasonWeekFilter}}", string.Format("and sw.SeasonYear = {0} and sw.SeasonTypeId = {1} and sw.WeekNum <= {2}", new string[] { seasonWeek.SeasonYear.ToString(), seasonWeek.SeasonTypeId.ToString(), seasonWeek.WeekNum.ToString() }));
            return context.ExecuteQuery<WinsLosses>(query).FirstOrDefault();
        }
示例#13
0
        public static bool SaveLineup(NPGGFFLDataContext context, string fromAddress, string body, int seasonWeekId)
        {
            try
            {
                var weekDate = DateTime.Now;
                //var seasonWeek = context.SeasonWeeks.Where(sw2 => weekDate >= sw2.StartDtm && weekDate <= sw2.EndDtm).First();
                var seasonWeek = context.SeasonWeeks.Where(sw2 => sw2.SeasonWeekId == seasonWeekId).First();
                var ownerExists = context.Owners.Where(o => o.EmailAddress.ToUpper().Contains(fromAddress)).FirstOrDefault();
                if (ownerExists == null)
                {
                    return false;
                }
                else
                {
                    var lineupText = body.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

                    List<NPGGFFL.Data.Players> lineup = new List<NPGGFFL.Data.Players>();
                    foreach (var line in lineupText)
                    {
                        if (!line.Trim().Equals(string.Empty))
                        {
                            Dictionary<int, int> playerMatches = new Dictionary<int, int>();
                            var words = line.Split(' ');
                            foreach (var word in words)
                            {
                                var playerFound = context.Players.Where(p => (p.Name.ToUpper().Contains(word.ToUpper()) || p.Alias.Contains(word.ToUpper())));
                                foreach (var player in playerFound)
                                {
                                    if (playerMatches.ContainsKey(player.PlayerId))
                                    {
                                        playerMatches[player.PlayerId]++;
                                    }
                                    else
                                    {
                                        playerMatches.Add(player.PlayerId, 1);
                                    }
                                }
                            }

                            if (playerMatches.Count() > 0)
                            {
                                var highestMatchCount = playerMatches.OrderByDescending(m => m.Value).First().Value;
                                if (playerMatches.Where(m => m.Value == highestMatchCount).Count() == 1)
                                {
                                    lineup.Add(context.Players.Where(p => p.PlayerId == playerMatches.Where(m => m.Value == highestMatchCount).First().Key).First());
                                }
                                else
                                {
                                    var distanceMatches = playerMatches.Where(m => m.Value == highestMatchCount).Select(m => new
                                    {
                                        PlayerId = m.Key,
                                        Distance = LevenshteinDistance.Compute((context.Players.Where(p => p.PlayerId == m.Key).First().Alias == null ? context.Players.Where(p => p.PlayerId == m.Key).First().Name : context.Players.Where(p => p.PlayerId == m.Key).First().Alias).ToUpper(), line.ToUpper())
                                    }).OrderBy(m => m.Distance);

                                    var bestMatch = distanceMatches.First();
                                    lineup.Add(context.Players.Where(p => p.PlayerId == bestMatch.PlayerId).First());
                                }
                            }
                        }
                    }

                    //load lineup
                    if (lineup.Count > 0)
                    {
                        var playerCount = context.OwnerTeams.Where(ot => ot.OwnerId == ownerExists.OwnerId && ot.SeasonWeekId == seasonWeek.SeasonWeekId).Count();
                        var unlockedPlayerCount = context.OwnerTeams.Where(ot => ot.OwnerId == ownerExists.OwnerId && ot.SeasonWeekId == seasonWeek.SeasonWeekId && ot.IsLocked == false).Count();

                        if (playerCount == 0 || unlockedPlayerCount > 0)
                        {
                            var ownerTieBreaker = context.OwnerTieBreakers.Where(otb => otb.OwnerId == ownerExists.OwnerId && otb.SeasonWeekId == seasonWeek.SeasonWeekId).FirstOrDefault();
                            if (ownerTieBreaker != null)
                            {
                                context.OwnerTieBreakers.DeleteOnSubmit(ownerTieBreaker);
                                context.SubmitChanges();
                            }
                            else
                            {
                                var vikingsTeam = context.Teams.Where(t => t.Abbreviation.Equals("min")).First();
                                var tieBreakerGame = context.Games.Where(g => g.SeasonWeekId == seasonWeek.SeasonWeekId && (g.HomeTeamId == vikingsTeam.TeamId || g.AwayTeamId == vikingsTeam.TeamId)).First();
                                NPGGFFL.Data.OwnerTieBreaker otb = new NPGGFFL.Data.OwnerTieBreaker {
                                    OwnerId = ownerExists.OwnerId,
                                    GameId = tieBreakerGame.GameId,
                                    SeasonWeekId = seasonWeek.SeasonWeekId,
                                    HomeScore = 1,
                                    AwayScore = 1,
                                    IsLocked = false
                                };

                                context.OwnerTieBreakers.InsertOnSubmit(otb);
                                context.SubmitChanges();
                            }

                            var ownerTeam = context.OwnerTeams.Where(ot => ot.OwnerId == ownerExists.OwnerId && ot.SeasonWeekId == seasonWeek.SeasonWeekId);
                            foreach (var ot in ownerTeam)
                            {
                                context.OwnerTeams.DeleteOnSubmit(ot);
                            }
                            context.SubmitChanges();

                            foreach (var player in lineup)
                            {
                                var ot = new NPGGFFL.Data.OwnerTeams
                                {
                                    OwnerId = ownerExists.OwnerId,
                                    PlayerId = player.PlayerId,
                                    SeasonWeekId = seasonWeek.SeasonWeekId,
                                    IsLocked = false
                                };
                                context.OwnerTeams.InsertOnSubmit(ot);
                            }
                            context.SubmitChanges();
                        }
                    }

                    return true;
                }
            }
            catch
            {
                return false;
            }
        }
示例#14
0
        public static void LoadLineups(NPGGFFLDataContext context, DateTime triggerDate)
        {
            Console.WriteLine("Getting service...");
            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = GetCredentials(),
                ApplicationName = ApplicationName,
            });

            var seasonWeek = context.SeasonWeeks.Where(sw => sw.StartDtm <= triggerDate && sw.EndDtm >= triggerDate).First();
            ModifyMessageRequest mods = new ModifyMessageRequest();
            mods.AddLabelIds = (new string[] { }).ToList();
            mods.RemoveLabelIds = (new string[] { "INBOX" }).ToList();

            ListLabelsResponse response = service.Users.Labels.List(UserId).Execute();
            foreach (Label label in response.Labels)
            {
                if (label.Name.ToUpper().Equals(string.Format("WEEK {0}", seasonWeek.WeekNum)))
                {
                    mods.AddLabelIds.Add(label.Id);
                    break;
                }
            }

            Console.WriteLine("Getting messages...");
            var msgs = ListMessages(service, UserId, "label:inbox");
            foreach (var msg in msgs)
            {
                Console.WriteLine("Getting message email and body...");
                var message = service.Users.Messages.Get(UserId, msg.Id).Execute();
                var partsBody = (message.Payload.Parts == null ? message.Payload.Body.Data : message.Payload.Parts.Where(p => p.MimeType.Equals("text/plain")).First().Body.Data);
                var plainTextBody = Encoding.UTF8.GetString(Convert.FromBase64String(partsBody));
                var fromAddress = string.Empty;
                var body = string.Empty;

                //check for forward
                if (plainTextBody.Contains("Forwarded"))
                {
                    var fromLine = plainTextBody.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None).Where(l => l.Contains("From:")).FirstOrDefault();
                    MailAddress email = new MailAddress(fromLine.Substring(fromLine.IndexOf("From:")+6));
                    fromAddress = email.Address.ToUpper();

                    bool afterEmailForwardSignature = false;
                    foreach (var line in plainTextBody.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None))
                    {
                        if (line.Contains("To:"))
                        {
                            afterEmailForwardSignature = true;
                        }

                        if (afterEmailForwardSignature)
                        {
                            body += line + "\r\n";
                        }
                    }

                }
                else
                {
                    MailAddress email = new MailAddress(message.Payload.Headers.Where(h => h.Name.Equals("From")).FirstOrDefault().Value);
                    fromAddress = email.Address.ToUpper();
                    body = plainTextBody;
                }

                //Console.WriteLine("Loading Lineup..");
                //if (SaveLineup(context, fromAddress, body, seasonWeek.SeasonWeekId))
                //{
                //    //Console.WriteLine("Trash Message...");
                //    //service.Users.Messages.Trash(UserId, message.Id).Execute();
                //}

                service.Users.Messages.Modify(mods, UserId, message.Id).Execute();
            }
            Console.WriteLine("Done...");
        }
示例#15
0
 public static IEnumerable<PlayerRanks> GetPlayerRankings(NPGGFFLDataContext context, int seasonYear, int seasonTypeId)
 {
     var query = NPGGFFLApi.queries.PlayerRankingsQuery;
     query = query.Replace("{{:PlayerPointsQuery}}", NPGGFFLApi.queries.PlayerPointsQuery);
     query = query.Replace("{{:GameFilter}}", string.Empty);
     query = query.Replace("{{:PlayerFilter}}", string.Empty);
     query = query.Replace("{{:SeasonWeekFilter}}", string.Format("pp.SeasonYear = {0} and pp.SeasonTypeId = {1}", seasonYear, seasonTypeId));
     return context.ExecuteQuery<PlayerRanks>(query);
 }
示例#16
0
 private static PlayerRankings InsertPlayerRankById(NPGGFFLDataContext context, int playerId)
 {
     var playerRankExists = context.PlayerRankings.Where(p => p.PlayerId == playerId).FirstOrDefault();
     if (playerRankExists == null)
     {
         PlayerRankings pr = new PlayerRankings { PlayerId = playerId };
         context.PlayerRankings.InsertOnSubmit(pr);
         context.SubmitChanges();
         return context.PlayerRankings.Where(p => p.PlayerId == playerId).FirstOrDefault();
     }
     else
     {
         return playerRankExists;
     }
 }
示例#17
0
 private static InjuryStatus InsertInjuryStatusByName(NPGGFFLDataContext context, string injuryStatusName)
 {
     var injuryStatusExists = context.InjuryStatus.Where(i => i.Name.ToUpper().Equals(injuryStatusName.ToUpper())).FirstOrDefault();
     if (injuryStatusExists == null)
     {
         InjuryStatus inj = new InjuryStatus
         {
             Name = injuryStatusName,
             Abbreviation = injuryStatusName.Substring(0,1)
         };
         context.InjuryStatus.InsertOnSubmit(inj);
         context.SubmitChanges();
         return context.InjuryStatus.Where(i => i.Name.ToUpper().Equals(injuryStatusName.ToUpper())).First();
     }
     else
     {
         return injuryStatusExists;
     }
 }
示例#18
0
 public static IEnumerable<PlayerPointsLine> GetAllPlayerPoints(NPGGFFLDataContext context)
 {
     var query = NPGGFFLApi.queries.PlayerPointsQuery;
     query = query.Replace("{{:GameFilter}}", string.Empty).Replace("{{:PlayerFilter}}", string.Empty);
     return context.ExecuteQuery<PlayerPointsLine>(query);
 }
示例#19
0
        private static Players InsertPlayerById(NPGGFFLDataContext context, int playerId, Games game)
        {
            var playerExists = context.Players.Where(p => p.PlayerId == playerId).FirstOrDefault();
            if (playerExists == null)
            {
                var url = string.Format("{0}/{1}", PLAYER_URL, playerId.ToString());
                var html = HelperMethods.LoadHtmlFromUrl(url);
                CQ dom = new CQ(html, HtmlParsingMode.Document);
                var playerName = string.Empty;
                var position = string.Empty;
                var team = string.Empty;

                try
                {
                    playerName = dom["div[class*='mod-split-menu']"].First().Find("a[class*='btn-split-btn']").First().Html().Trim();
                    position = dom["div[class*='player-bio']"].Find("ul[class*='general-info']").Find("li").First().Html().Split(' ')[1].Trim();
                    team = dom["ul[class*='general-info']"].Find("a[href*='/team/']").Attr("href").Split('/')[7].Trim();
                }
                catch { }

                Players player = new Players();
                player.PlayerId = playerId;
                player.Name = playerName;

                var playerTeam = context.Teams.Where(t => t.Abbreviation.ToUpper().Equals(team.ToUpper())).FirstOrDefault();
                if (playerTeam != null)
                {
                    player.TeamId = playerTeam.TeamId;
                }
                else
                {
                    player.TeamId = 35; //no team
                }

                player.PositionId = InsertPositionByName(context, position).PositionId;
                context.Players.InsertOnSubmit(player);
                context.SubmitChanges();
                return context.Players.Where(p => p.PlayerId == playerId).FirstOrDefault();
            }
            else if (playerExists.TeamId != game.HomeTeamId && playerExists.TeamId != game.AwayTeamId)
            {
                var url = string.Format("{0}/{1}", PLAYER_URL, playerId.ToString());
                var html = HelperMethods.LoadHtmlFromUrl(url);
                CQ dom = new CQ(html, HtmlParsingMode.Document);
                var playerName = string.Empty;
                var position = string.Empty;
                var team = string.Empty;

                try
                {
                    playerName = dom["div[class*='mod-split-menu']"].First().Find("a[class*='btn-split-btn']").First().Html().Trim();
                    position = dom["div[class*='player-bio']"].Find("ul[class*='general-info']").Find("li").First().Html().Split(' ')[1].Trim();
                    team = dom["ul[class*='general-info']"].Find("a[href*='/team/']").Attr("href").Split('/')[7].Trim();
                }
                catch { }

                var playerTeam = context.Teams.Where(t => t.Abbreviation.ToUpper().Equals(team.ToUpper())).FirstOrDefault();
                if (playerTeam != null)
                {
                    playerExists.TeamId = playerTeam.TeamId;
                }
                else
                {
                    playerExists.TeamId = 35; //no team
                }

                context.SubmitChanges();
                return playerExists;
            }
            else
            {
                return playerExists;
            }
        }
示例#20
0
 private static void LockPlayersForOwners(NPGGFFLDataContext context, IEnumerable<Players> playersInGame, int seasonWeekId)
 {
     foreach (var player in playersInGame)
     {
         var ownerTeamPlayers = context.OwnerTeams.Where(ot => ot.PlayerId == player.PlayerId && ot.SeasonWeekId == seasonWeekId);
         foreach (var otp in ownerTeamPlayers)
         {
             otp.IsLocked = true;
         }
         context.SubmitChanges();
     }
 }
示例#21
0
 private static Position InsertPositionByName(NPGGFFLDataContext context, string positionName)
 {
     var positionExists = context.Positions.Where(p => p.Name.ToUpper().Equals(positionName.ToUpper())).FirstOrDefault();
     if (positionExists == null)
     {
         Position position = new Position();
         position.Name = positionName;
         context.Positions.InsertOnSubmit(position);
         context.SubmitChanges();
         return context.Positions.Where(p => p.Name.ToUpper().Equals(positionName.ToUpper())).FirstOrDefault();
     }
     else
     {
         return positionExists;
     }
 }
示例#22
0
        private static void UpdateStats(Games game, NPGGFFLDataContext context, string eid, JObject gameCenterJson)
        {
            #region Update Game Stats
            var gameStatus = gameCenterJson[eid]["qtr"].Value<string>();
            if (gameStatus.Equals("Final"))
            {
                game.GameTimeRemaining = "Final";
                game.IsFinal = 1;
            }
            else
            {
                var gameTimeRemaining = gameCenterJson[eid]["clock"].Value<string>();
                game.GameTimeRemaining = gameTimeRemaining;
            }
            #region Update Team Stats
            var awayScore = gameCenterJson[eid]["away"]["score"]["T"].Value<int>(); ;
            context.PlayerStats.Where(ps => ps.GameId == game.GameId && ps.PlayerId == game.HomeTeamId).First().PointsAllowed = awayScore;
            game.AwayPointsScored = awayScore;

            var homeScore = gameCenterJson[eid]["home"]["score"]["T"].Value<int>();
            context.PlayerStats.Where(ps => ps.GameId == game.GameId && ps.PlayerId == game.AwayTeamId).First().PointsAllowed = homeScore;
            game.HomePointsScored = homeScore;
            context.SubmitChanges();

            #endregion

            #endregion

            #region Get Home Stats
            var hpassing = gameCenterJson[eid]["home"]["stats"]["passing"];
            var hrushing = gameCenterJson[eid]["home"]["stats"]["rushing"];
            var hreceiving = gameCenterJson[eid]["home"]["stats"]["receiving"];
            var hfumbles = gameCenterJson[eid]["home"]["stats"]["fumbles"];
            var hkicking = gameCenterJson[eid]["home"]["stats"]["kicking"];
            //var hpunting = gameCenterJson[eid]["home"]["stats"]["punting"];
            //var hkickret = gameCenterJson[eid]["home"]["stats"]["kickret"];
            //var hpuntret = gameCenterJson[eid]["home"]["stats"]["puntret"];
            //var hdefense = gameCenterJson[eid]["home"]["stats"]["defense"];
            //var hteam = gameCenterJson[eid]["home"]["stats"]["team"];
            ProcessPlayerStats(context, hpassing, "passing", game.GameId);
            ProcessPlayerStats(context, hrushing, "rushing", game.GameId);
            ProcessPlayerStats(context, hreceiving, "receiving", game.GameId);
            ProcessPlayerStats(context, hfumbles, "fumbles", game.GameId);
            ProcessPlayerStats(context, hkicking, "kicking", game.GameId);
            //ProcessPlayerStats(context, hpunting, "punting", game.GameId);
            //ProcessPlayerStats(context, hkickret, "kickret", game.GameId);
            //ProcessPlayerStats(context, hpuntret, "puntret", game.GameId);
            //ProcessPlayerStats(context, hdefense, "defense", game.GameId);
            //ProcessPlayerStats(context, hteam);
            #endregion

            #region Get Away Stats
            var apassing = gameCenterJson[eid]["away"]["stats"]["passing"];
            var arushing = gameCenterJson[eid]["away"]["stats"]["rushing"];
            var areceiving = gameCenterJson[eid]["away"]["stats"]["receiving"];
            var afumbles = gameCenterJson[eid]["away"]["stats"]["fumbles"];
            var akicking = gameCenterJson[eid]["away"]["stats"]["kicking"];
            //var apunting = gameCenterJson[eid]["away"]["stats"]["punting"];
            //var akickret = gameCenterJson[eid]["away"]["stats"]["kickret"];
            //var apuntret = gameCenterJson[eid]["away"]["stats"]["puntret"];
            //var adefense = gameCenterJson[eid]["away"]["stats"]["defense"];
            //var ateam = gameCenterJson[eid]["away"]["stats"]["team"];
            ProcessPlayerStats(context, apassing, "passing", game.GameId);
            ProcessPlayerStats(context, arushing, "rushing", game.GameId);
            ProcessPlayerStats(context, areceiving, "receiving", game.GameId);
            ProcessPlayerStats(context, afumbles, "fumbles", game.GameId);
            ProcessPlayerStats(context, akicking, "kicking", game.GameId);
            //ProcessPlayerStats(context, apunting, "punting", game.GameId);
            //ProcessPlayerStats(context, akickret, "kickret", game.GameId);
            //ProcessPlayerStats(context, apuntret, "puntret", game.GameId);
            //ProcessPlayerStats(context, adefense, "defense", game.GameId);
            //ProcessPlayerStats(context, ateam);
            #endregion
        }
示例#23
0
        private static void FindSafeties(NPGGFFLDataContext context, int gameId)
        {
            Dictionary<int, int> teamSafetyStats = new Dictionary<int, int>();
            var url = string.Format("{0}{1}", PLAYBYPLAY_URL, string.Format("?gameId={0}", gameId.ToString()));
            //var url = string.Format("{0}{1}", DRIVESUMMARY_URL, string.Format("?gameId={0}", gameId.ToString()));
            var html = HelperMethods.LoadHtmlFromUrl(url);
            CQ dom = new CQ(html, HtmlParsingMode.Document);

            var summaryTables = dom["div[class*='accordion-header']"].Has("span[class*='headline']:contains('Safety')");
            //var summaryTables = dom["table[class*='mod-data']"].Has("td:contains('Safety')");

            foreach (var st in summaryTables)
            {
                var teamName = st.Cq().Find("img[class*='team-logo']").Attr("src").Split('/')[9].Trim().Replace(".png&h=100&w=100", string.Empty);
                //var teamName = st.Cq().Find("a").Attr("name");
                //var numSafeties = st.Cq().Find("td:contains('Safety')");
                var gameExists = context.Games.Where(g => g.GameId == gameId).FirstOrDefault();
                if (gameExists != null)
                {
                    var findTeamSafetied = context.Teams.Where(t => t.Abbreviation.ToUpper().Contains(teamName.ToUpper())).FirstOrDefault();
                    if (findTeamSafetied != null)
                    {
                        var teamScoredSafety = (gameExists.HomeTeamId == findTeamSafetied.TeamId ? gameExists.AwayTeamId : gameExists.HomeTeamId);
                        if (!teamSafetyStats.ContainsKey(teamScoredSafety))
                        {
                            teamSafetyStats.Add(teamScoredSafety, 1);
                        }
                        else
                        {
                            teamSafetyStats[teamScoredSafety]++;
                        }
                    }
                }
            }

            foreach (var tss in teamSafetyStats)
            {
                var playerTeamStats = context.PlayerStats.Where(ts => ts.PlayerId == tss.Key && ts.GameId == gameId).FirstOrDefault();
                if (playerTeamStats != null)
                {
                    playerTeamStats.Safeties = tss.Value;
                    context.SubmitChanges();
                }
            }
        }
示例#24
0
 public static IEnumerable<PlayerPointsLine> GetPlayerPoints(NPGGFFLDataContext context, int gameId)
 {
     var query = NPGGFFLApi.queries.PlayerPointsQuery;
     query = query.Replace("{{:GameFilter}}", string.Format("and g.gameid = {0}", gameId)).Replace("{{:PlayerFilter}}", string.Empty);
     return context.ExecuteQuery<PlayerPointsLine>(query);
 }
示例#25
0
        private static void ProcessPlayerStats(NPGGFFLDataContext context, JToken stats, string type, int gameId)
        {
            foreach (var stat in stats.Children())
            {
                var playerId = ((JProperty)stat).Name;
                var playerRecord = stat.Children().First();
                var playerName = playerRecord["name"].Value<string>();
                var player = InsertPlayerById(context, playerId, playerName);
                if (player != null)
                {
                    var ps = GeneralScraperMethods.InsertPlayerStatsByPlayerIdGameId(context, player.PlayerId, gameId);

                    #region Parse Stats
                    var passingCompletions = ps.PassingCompletions.ToString();
                    var passingAttempts = ps.PassingAttempts.ToString();
                    var passingYards = ps.PassingYards.ToString();
                    var passingTDS = ps.PassingTDs.ToString();
                    var passingINTS = ps.PassingINTs.ToString();
                    var passingSacksTaken = ps.SacksTaken.ToString();
                    var passingSackYardsLost = ps.SackYardsLost.ToString();
                    var rushingCarries = ps.RushingCarries.ToString();
                    var rushingYards = ps.RushingYards.ToString();
                    var rushingTDs = ps.RushingTDs.ToString();
                    var receivingReceptions = ps.ReceivingReceptions.ToString();
                    var receivingYards = ps.ReceivingYards.ToString();
                    var receivingTDs = ps.ReceivingTDs.ToString();
                    var receivingTargets = ps.ReceivingTargets.ToString();
                    var fumbles = ps.Fumbles.ToString();
                    var fumblesLost = ps.FumblesLost.ToString();
                    var fumblesReceovered = ps.FumblesRecovered.ToString();
                    var totalTackles = ps.TotalTackles.ToString();
                    var soloTackles = ps.SoloTackles.ToString();
                    var sacks = ps.Sacks.ToString();
                    var tacklesForLoss = ps.TacklesForLoss.ToString();
                    var passesDefended = ps.PassesDefended.ToString();
                    var qbHits = ps.QBHits.ToString();
                    var defensiveTDs = ps.DefensiveTDs.ToString();
                    var kickReturns = ps.KickReturns.ToString();
                    var kickReturnYards = ps.KickReturnYards.ToString();
                    var kickReturnTDs = ps.KickReturnTDs.ToString();
                    var puntReturns = ps.PuntReturns.ToString();
                    var puntReturnYards = ps.PuntReturnYards.ToString();
                    var puntReturnTDs = ps.PuntReturnTDs.ToString();
                    var fieldGoalsMade = ps.FieldGoalsMade.ToString();
                    var fieldGoalsAttempted = ps.FieldGoalAttempts.ToString();
                    var extraPointsMade = ps.ExtraPointsMade.ToString();
                    var extraPointsAttempted = ps.ExtraPointAttempts.ToString();
                    var kickingPointsScored = ps.KickingPointsScored.ToString();
                    var punts = ps.Punts.ToString();
                    var puntYards = ps.PuntYards.ToString();
                    var twoPointConversions = ps.TwoPointConversions.ToString();

                    switch (type)
                    {
                        case "passing":
                            passingCompletions = playerRecord["cmp"].Value<string>();
                            passingAttempts = playerRecord["att"].Value<string>();
                            passingYards = playerRecord["yds"].Value<string>();
                            passingTDS = playerRecord["tds"].Value<string>();
                            passingINTS = playerRecord["ints"].Value<string>();
                            twoPointConversions = playerRecord["twoptm"].Value<string>();
                            break;
                        case "rushing":
                            rushingCarries = playerRecord["att"].Value<string>();
                            rushingYards = playerRecord["yds"].Value<string>();
                            rushingTDs = playerRecord["tds"].Value<string>();
                            twoPointConversions = playerRecord["twoptm"].Value<string>();
                            break;
                        case "receiving":
                            receivingReceptions = playerRecord["rec"].Value<string>();
                            receivingYards = playerRecord["yds"].Value<string>();
                            receivingTDs = playerRecord["tds"].Value<string>();
                            twoPointConversions = playerRecord["twoptm"].Value<string>();
                            break;
                        case "fumbles":
                            fumbles = playerRecord["tot"].Value<string>();
                            fumblesLost = playerRecord["lost"].Value<string>();
                            fumblesReceovered = playerRecord["trcv"].Value<string>();
                            break;
                        case "kicking":
                            fieldGoalsMade = playerRecord["fgm"].Value<string>();
                            fieldGoalsAttempted = playerRecord["fga"].Value<string>();
                            extraPointsMade = playerRecord["xpmade"].Value<string>();
                            extraPointsAttempted = playerRecord["xpa"].Value<string>();
                            kickingPointsScored = (playerRecord["totpfg"].Value<int>() + playerRecord["xptot"].Value<int>()).ToString();
                            break;
                        case "punting":
                            punts = playerRecord["pts"].Value<string>();
                            puntYards = playerRecord["yds"].Value<string>();
                            break;
                        case "kickret":
                            kickReturns = playerRecord["ret"].Value<string>();
                            kickReturnTDs = playerRecord["tds"].Value<string>();
                            break;
                        case "puntret":
                            puntReturns = playerRecord["ret"].Value<string>();
                            puntReturnTDs = playerRecord["tds"].Value<string>();
                            break;
                        case "defense":
                            totalTackles = playerRecord["tkl"].Value<string>();
                            sacks = playerRecord["sk"].Value<string>();
                            break;
                        default:
                            break;
                    }

                    if (!ps.TwoPointConversions.ToString().Equals(twoPointConversions))
                    {
                        ps.TwoPointConversions = Convert.ToInt32(twoPointConversions);
                        context.SubmitChanges();
                    }
                    #endregion

                    GeneralScraperMethods.UpdatePlayerStats(context, ps, passingCompletions, passingAttempts, passingYards, passingTDS, passingINTS, passingSacksTaken, passingSackYardsLost, rushingCarries, rushingYards, rushingTDs, receivingReceptions, receivingYards, receivingTDs, receivingTargets, fumbles, fumblesLost, fumblesReceovered, totalTackles, soloTackles, sacks, tacklesForLoss, passesDefended, qbHits, defensiveTDs, kickReturns, kickReturnYards, kickReturnTDs, puntReturns, puntReturnYards, puntReturnTDs, fieldGoalsMade, fieldGoalsAttempted, extraPointsMade, extraPointsAttempted, kickingPointsScored, punts, puntYards);
                }

            }
        }
示例#26
0
 public static PlayerPointsLine GetPlayerPointsSeasonWeek(NPGGFFLDataContext context, int playerId, int seasonWeekId)
 {
     PlayersController controller = new PlayersController();
     var gameThisWeek = controller.GetPlayerGameThisWeek(playerId, seasonWeekId);
     if (gameThisWeek != null)
     {
         var playerPointsSeasonWeek = GetPlayerPoints(context, playerId, gameThisWeek.GameId);
         return playerPointsSeasonWeek;
     }
     else
     {
         return null;
     }
 }
示例#27
0
 public static IEnumerable<DefensivePlayerRanks> GetDefensiveRanks(NPGGFFLDataContext context, int seasonYear, int seasonTypeId)
 {
     var query = NPGGFFLApi.queries.DefensiveRanksQuery;
     query = query.Replace("{{:PlayerPointsQuery}}", NPGGFFLApi.queries.PlayerPointsQuery);
     query = query.Replace("{{:GameFilter}}", string.Empty);
     query = query.Replace("{{:PlayerFilter}}", string.Empty);
     query = query.Replace("{{:SeasonWeekFilter}}", string.Format("and dpp.SeasonYear = {0} and dpp.SeasonTypeId = {1}", seasonYear, seasonTypeId));
     query = query.Replace("{{:PlayerPositionFilter}}", "and dpp.PositionName = 'DST' and pop.PositionName <> 'DST'");
     return context.ExecuteQuery<DefensivePlayerRanks>(query);
 }
示例#28
0
        private static PlayerInjuryHistory InsertPlayerInjuryHistory(NPGGFFLDataContext context, int playerId, int injuryStatusId, string description, DateTime reportDtm)
        {
            var pihExists = context.PlayerInjuryHistories.Where(pih => pih.PlayerId == playerId && pih.ReportDtm == reportDtm && pih.InjuryStatusId == injuryStatusId).FirstOrDefault();
            if (pihExists == null)
            {
                PlayerInjuryHistory pih = new PlayerInjuryHistory
                {
                    PlayerId = playerId,
                    InjuryStatusId = injuryStatusId,
                    Description = description,
                    ReportDtm = reportDtm
                };

                context.PlayerInjuryHistories.InsertOnSubmit(pih);
                context.SubmitChanges();
                return context.PlayerInjuryHistories.Where(pih2 => pih2.PlayerId == playerId && pih2.ReportDtm == reportDtm && pih2.InjuryStatusId == injuryStatusId).First();
            }
            else
            {
                return pihExists;
            }
        }
示例#29
0
        public static void UpdatePlayerStats(NPGGFFLDataContext context, PlayerStats playerStats, string passingCompletions, string passingAttempts, string passingYards, string passingTDS, string passingINTS, string passingSacksTaken, string passingSackYardsLost, string rushingCarries, string rushingYards, string rushingTDs, string receivingReceptions, string receivingYards, string receivingTDs, string receivingTargets, string fumbles, string fumblesLost, string fumblesReceovered, string totalTackles, string soloTackles, string sacks, string tacklesForLoss, string passesDefended, string qbHits, string defensiveTDs, string kickReturns, string kickReturnYards, string kickReturnTDs, string puntReturns, string puntReturnYards, string puntReturnTDs, string fieldGoalsMade, string fieldGoalsAttempted, string extraPointsMade, string extraPointsAttempted, string kickingPointsScored, string punts, string puntYards)
        {
            bool needToUpdate = false;

            try
            {
                if (
                        !playerStats.PassingCompletions.ToString().Equals(passingCompletions)
                        || !playerStats.PassingAttempts.ToString().Equals(passingAttempts)
                        || !playerStats.PassingYards.ToString().Equals(passingYards)
                        || !playerStats.PassingTDs.ToString().Equals(passingTDS)
                        || !playerStats.PassingINTs.ToString().Equals(passingINTS)
                        || !playerStats.SacksTaken.ToString().Equals(passingSacksTaken)
                        || !playerStats.SackYardsLost.ToString().Equals(passingSackYardsLost)
                        || !playerStats.RushingCarries.ToString().Equals(rushingCarries)
                        || !playerStats.RushingYards.ToString().Equals(rushingYards)
                        || !playerStats.RushingTDs.ToString().Equals(rushingTDs)
                        || !playerStats.ReceivingReceptions.ToString().Equals(receivingReceptions)
                        || !playerStats.ReceivingYards.ToString().Equals(receivingYards)
                        || !playerStats.ReceivingTDs.ToString().Equals(receivingTDs)
                        || !playerStats.ReceivingTargets.ToString().Equals(receivingTargets)
                        || !playerStats.Fumbles.ToString().Equals(fumbles)
                        || !playerStats.FumblesLost.ToString().Equals(fumblesLost)
                        || !playerStats.FumblesRecovered.ToString().Equals(fumblesReceovered)
                        || !playerStats.TotalTackles.ToString().Equals(totalTackles)
                        || !playerStats.SoloTackles.ToString().Equals(soloTackles)
                        || playerStats.Sacks != Convert.ToDecimal(sacks)
                        || !playerStats.TacklesForLoss.ToString().Equals(tacklesForLoss)
                        || !playerStats.PassesDefended.ToString().Equals(passesDefended)
                        || !playerStats.QBHits.ToString().Equals(qbHits)
                        || !playerStats.DefensiveTDs.ToString().Equals(defensiveTDs)
                        || !playerStats.KickReturns.ToString().Equals(kickReturns)
                        || !playerStats.KickReturnYards.ToString().Equals(kickReturnYards)
                        || !playerStats.KickReturnTDs.ToString().Equals(kickReturnTDs)
                        || !playerStats.PuntReturns.ToString().Equals(puntReturns)
                        || !playerStats.PuntReturnYards.ToString().Equals(puntReturnYards)
                        || !playerStats.PuntReturnTDs.ToString().Equals(puntReturnTDs)
                        || !playerStats.FieldGoalsMade.ToString().Equals(fieldGoalsMade)
                        || !playerStats.FieldGoalAttempts.ToString().Equals(fieldGoalsAttempted)
                        || !playerStats.ExtraPointsMade.ToString().Equals(extraPointsMade)
                        || !playerStats.ExtraPointAttempts.ToString().Equals(extraPointsAttempted)
                        || !playerStats.KickingPointsScored.ToString().Equals(kickingPointsScored)
                        || !playerStats.Punts.ToString().Equals(punts)
                        || !playerStats.PuntYards.ToString().Equals(puntYards))
                {
                    needToUpdate = true;
                }

                if (needToUpdate)
                {
                    Console.WriteLine(string.Format("{0}:{1}", "Update is needed for player", playerStats.Players.Name));
                    playerStats.PassingCompletions = Convert.ToInt32(passingCompletions);
                    playerStats.PassingAttempts = Convert.ToInt32(passingAttempts);
                    playerStats.PassingYards = Convert.ToInt32(passingYards);
                    playerStats.PassingTDs = Convert.ToInt32(passingTDS);
                    playerStats.PassingINTs = Convert.ToInt32(passingINTS);
                    playerStats.SacksTaken = Convert.ToInt32(passingSacksTaken);
                    playerStats.SackYardsLost = Convert.ToInt32(passingSackYardsLost);
                    playerStats.RushingCarries = Convert.ToInt32(rushingCarries);
                    playerStats.RushingYards = Convert.ToInt32(rushingYards);
                    playerStats.RushingTDs = Convert.ToInt32(rushingTDs);
                    playerStats.ReceivingReceptions = Convert.ToInt32(receivingReceptions);
                    playerStats.ReceivingYards = Convert.ToInt32(receivingYards);
                    playerStats.ReceivingTDs = Convert.ToInt32(receivingTDs);
                    playerStats.ReceivingTargets = Convert.ToInt32(receivingTargets);
                    playerStats.Fumbles = Convert.ToInt32(fumbles);
                    playerStats.FumblesLost = Convert.ToInt32(fumblesLost);
                    playerStats.FumblesRecovered = Convert.ToInt32(fumblesReceovered);
                    playerStats.TotalTackles = Convert.ToInt32(totalTackles);
                    playerStats.SoloTackles = Convert.ToInt32(soloTackles);
                    playerStats.Sacks = Convert.ToDecimal(sacks);
                    playerStats.TacklesForLoss = Convert.ToInt32(tacklesForLoss);
                    playerStats.PassesDefended = Convert.ToInt32(passesDefended);
                    playerStats.QBHits = Convert.ToInt32(qbHits);
                    playerStats.DefensiveTDs = Convert.ToInt32(defensiveTDs);
                    playerStats.KickReturns = Convert.ToInt32(kickReturns);
                    playerStats.KickReturnYards = Convert.ToInt32(kickReturnYards);
                    playerStats.KickReturnTDs = Convert.ToInt32(kickReturnTDs);
                    playerStats.PuntReturns = Convert.ToInt32(puntReturns);
                    playerStats.PuntReturnYards = Convert.ToInt32(puntReturnYards);
                    playerStats.PuntReturnTDs = Convert.ToInt32(puntReturnTDs);
                    playerStats.FieldGoalsMade = Convert.ToInt32(fieldGoalsMade);
                    playerStats.FieldGoalAttempts = Convert.ToInt32(fieldGoalsAttempted);
                    playerStats.ExtraPointsMade = Convert.ToInt32(extraPointsMade);
                    playerStats.ExtraPointAttempts = Convert.ToInt32(extraPointsAttempted);
                    playerStats.KickingPointsScored = Convert.ToInt32(kickingPointsScored);
                    playerStats.Punts = Convert.ToInt32(punts);
                    playerStats.PuntYards = Convert.ToInt32(puntYards);

                    //context.SubmitChanges();
                }
                else
                {
                    //Console.WriteLine(string.Format("{0}:{1}", "Skipping update of player", playerStats.Players.Name));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#30
0
 public static PlayerPointsLine GetPlayerPoints(NPGGFFLDataContext context, int playerId, int gameId)
 {
     var query = NPGGFFLApi.queries.PlayerPointsQuery;
     query = query.Replace("{{:GameFilter}}", string.Format("and g.gameid = {0}", gameId)).Replace("{{:PlayerFilter}}", string.Format("and p.playerid = {0}", playerId));
     return context.ExecuteQuery<PlayerPointsLine>(query).FirstOrDefault();
 }