Example #1
0
        public static void UpdateOpponents(ref List<Player> myPlayers)
        {
            FantasyFootballEntities db = new FantasyFootballEntities();
            tbl_ff_weeks myWeek = db.tbl_ff_weeks.Where(w => w.StartDate <= DateTime.Now && w.EndDate >= DateTime.Now).SingleOrDefault();
            if (myWeek != null)
            {
                List<tbl_ff_matchups> matches = db.tbl_ff_matchups.Where(mch => mch.Week == myWeek.Id).ToList();
                //Correct Jacksonville abbrev
                foreach (tbl_ff_matchups matchrow in matches)
                {
                    switch (matchrow.HomeTeam)
                    {
                        case "JAC":
                            matchrow.HomeTeam = "JAX";
                            break;
                    }
                    switch (matchrow.AwayTeam)
                    {
                        case "JAC":
                            matchrow.AwayTeam = "JAX";
                            break;
                    }
                }

                foreach(Player myPlayer in myPlayers)
                {
                    tbl_ff_matchups myMatchUp = matches.Where(m => m.HomeTeam == myPlayer.Team.ToUpper() || m.AwayTeam == myPlayer.Team.ToUpper()).FirstOrDefault();
                    bool isHomeTeam = myMatchUp.HomeTeam == myPlayer.Team.ToUpper();
                    myPlayer.Opponent = (isHomeTeam ? myMatchUp.AwayTeam.ToLower() : myMatchUp.HomeTeam.ToLower());
                }
            }
        }
Example #2
0
        public static void UpdateOpponents(ref List<RankingsPost> myWriters)
        {
            FantasyFootballEntities db = new FantasyFootballEntities();
            tbl_ff_weeks myWeek = db.tbl_ff_weeks.Where(w => w.StartDate <= DateTime.Now && w.EndDate >= DateTime.Now).SingleOrDefault();
            if (myWeek != null)
            {
                List<tbl_ff_matchups> matches = db.tbl_ff_matchups.Where(mch => mch.Week == myWeek.Id).ToList();
                //Correct Jacksonville abbrev
                foreach (tbl_ff_matchups matchrow in matches)
                {
                    switch (matchrow.HomeTeam)
                    {
                        case "JAX":
                            matchrow.HomeTeam = "JAC";
                            break;
                        case "LA":
                            matchrow.HomeTeam = "LAR";
                            break;
                    }
                    switch (matchrow.AwayTeam)
                    {
                        case "JAX":
                            matchrow.AwayTeam = "JAC";
                            break;
                        case "LA":
                            matchrow.AwayTeam = "LAR";
                            break;
                    }
                }

                foreach(RankingsPost myWriter in myWriters)
                {
                    //Search Rankings
                    foreach(KeyValuePair<string, List<Ranking>> myPosRankings in myWriter.MultiPartRankings)
                    {
                        foreach (Ranking myRanking in myPosRankings.Value)
                        {
                            tbl_ff_matchups myMatchUp = matches.Where(m => m.HomeTeam == myRanking.Team.ToUpper() || m.AwayTeam == myRanking.Team.ToUpper()).FirstOrDefault();
                            bool isHomeTeam = myMatchUp.HomeTeam == myRanking.Team.ToUpper();

                            myRanking.Opponent = (isHomeTeam ? myMatchUp.AwayTeam.ToLower() : myMatchUp.HomeTeam.ToLower());
                            myRanking.IsHomeTeam = isHomeTeam;
                        }
                    }
                }
            }
        }
Example #3
0
        protected void SetTeamWeeklyStats(string leagueId, int weeks)
        {
            List<TeamWeeklyStats> myStats = new List<TeamWeeklyStats>();
            List<TeamWeeklyStats> opponentStats = new List<TeamWeeklyStats>();
            FantasyFootballEntities db = new FantasyFootballEntities();
            tbl_ff_weeks myWeek = db.tbl_ff_weeks.Where(w => w.StartDate <= DateTime.Now && w.EndDate >= DateTime.Now).SingleOrDefault();
            if (myWeek != null)
            {
                List<tbl_ff_matchups> matchups = db.tbl_ff_matchups.Where(mch => mch.Week >= myWeek.Id - weeks).OrderBy(o => o.Date).ToList();
                //Correct Jacksonville abbrev
                foreach (tbl_ff_matchups matchrow in matchups)
                {
                    switch (matchrow.HomeTeam)
                    {
                        case "JAC":
                            matchrow.HomeTeam = "JAX";
                            break;
                        case "WAS":
                            matchrow.HomeTeam = "WSH";
                            break;
                    }
                    switch (matchrow.AwayTeam)
                    {
                        case "JAC":
                            matchrow.AwayTeam = "JAX";
                            break;
                        case "WAS":
                            matchrow.AwayTeam = "WSH";
                            break;
                    }
                }

                for (int i = myWeek.Id - weeks; i < myWeek.Id; i++)
                {
                    bool reachedZero = false; int count = 0;
                    while (reachedZero == false)
                    {
                        string html = Functions.GetHttpHtml(string.Format("http://games.espn.go.com/ffl/leaders?leagueId={0}&scoringPeriodId={1}&startIndex={2}", leagueId, i, count), (string)Session["espn"]);
                        MatchCollection myTRs = Regex.Matches(html, @"(?i)<tr[^>]+pncPlayerRow[^>]+>(?<Content>.*?)</tr>", RegexOptions.Singleline);
                        if (myTRs.Count > 0)
                        {
                            foreach (Match myTR in myTRs)
                            {
                                MatchCollection myTDs = Regex.Matches(myTR.Groups["Content"].Value, @"(?i)<td[^>]*>(?<Content>.*?)</td>", RegexOptions.Singleline);
                                if (myTDs.Count > 0)
                                {
                                    Match myPlayerMatch = Regex.Match(myTDs[0].Groups["Content"].Value, @"(?i)playerid=""(?<PlayerId>\d+)""[^>]*>(?<PlayerName>[^<]+)</a>\W+(?<Team>\w{2,3})&nbsp;(?<Position>\w{1,4})", RegexOptions.Singleline);
                                    //Match myPlayerMatch = Regex.Match(myTDs[1].Groups["Content"].Value, @"(?i)(?<Team>\w+)\s-\s(?<Position>\w+)</span>", RegexOptions.Singleline);
                                    Decimal myPoints;
                                    if (myPlayerMatch.Success && decimal.TryParse(Functions.StripHtmlTags(myTDs[myTDs.Count - 1].Groups["Content"].Value), out myPoints))
                                    {
                                        if (myPoints > 0)
                                        {
                                            TeamWeeklyStats tmpStats = myStats.Where(s => s.Team == myPlayerMatch.Groups["Team"].Value && s.Position == myPlayerMatch.Groups["Position"].Value && s.Week == i).SingleOrDefault();
                                            if (tmpStats != null)
                                            {
                                                tmpStats.Points += myPoints;
                                            }
                                            else
                                            {
                                                myStats.Add(new TeamWeeklyStats()
                                                {
                                                    Week = i,
                                                    Team = myPlayerMatch.Groups["Team"].Value,
                                                    Position = myPlayerMatch.Groups["Position"].Value,
                                                    Points = myPoints
                                                });
                                            }
                                        }
                                        else
                                        {
                                            reachedZero = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            break;
                        }

                        //increment results count
                        count += 50;
                    }
                }

                //Calculate opposite results for opponents
                Dictionary<string, int> teamWeekCounts = new Dictionary<string, int>();
                for (int i = myWeek.Id - weeks; i < myWeek.Id; i++)
                {
                    List<tbl_ff_matchups> myMatchups = matchups.Where(mch => mch.Week == i).ToList();
                    foreach (tbl_ff_matchups match in myMatchups)
                    {
                        List<TeamWeeklyStats> homeStats = myStats.Where(hm => hm.Week == i && hm.Team.ToUpper() == match.HomeTeam).Select(hm => new TeamWeeklyStats() { Week = 0, Points = hm.Points, Team = match.AwayTeam, Position = hm.Position }).ToList();
                        List<TeamWeeklyStats> awayStats = myStats.Where(aw => aw.Week == i && aw.Team.ToUpper() == match.AwayTeam).Select(aw => new TeamWeeklyStats() { Week = 0, Points = aw.Points, Team = match.HomeTeam, Position = aw.Position }).ToList();
                        List<TeamWeeklyStats> oppStats = homeStats.Union(awayStats).ToList();

                        foreach (TeamWeeklyStats myWeeklyStat in oppStats)
                        {
                            TeamWeeklyStats opponentStat = opponentStats.Where(ost => ost.Team == myWeeklyStat.Team && ost.Position == myWeeklyStat.Position).SingleOrDefault();
                            if (opponentStat != null)
                            {
                                opponentStat.Points += myWeeklyStat.Points;
                            }
                            else
                            {
                                opponentStats.Add(myWeeklyStat);
                            }
                        }

                        //Add to week count tally for HomeTeam
                        if (teamWeekCounts.ContainsKey(match.HomeTeam))
                            teamWeekCounts[match.HomeTeam] += 1;
                        else
                            teamWeekCounts.Add(match.HomeTeam, 1);
                        //And for AwayTeam too
                        if (teamWeekCounts.ContainsKey(match.AwayTeam))
                            teamWeekCounts[match.AwayTeam] += 1;
                        else
                            teamWeekCounts.Add(match.AwayTeam, 1);
                    }
                }

                //Create a collection ranking teams by points allowed
                List<string> myPositions = new List<string>() { "QB", "RB", "WR", "TE", "K", "DE", "DT", "LB", "S", "CB" };
                Dictionary<string, string[]> myTeamsPointsDictionary = new Dictionary<string, string[]>();
                myPositions = myPositions.Intersect(opponentStats.Select(myp => myp.Position).Distinct().ToList()).ToList();
                List<string> myTeams = opponentStats.Select(s => s.Team.ToUpper()).Distinct().ToList();
                foreach (string position in myPositions)
                {
                    Dictionary<string, decimal> teamPts = new Dictionary<string, decimal>();
                    foreach (string myTeam in myTeams)
                    {
                        int weekCount = teamWeekCounts[myTeam];
                        decimal pts = opponentStats.Where(w => w.Position == position && w.Team == myTeam).Sum(d => d.Points);
                        teamPts.Add(myTeam, pts / weekCount);
                    }

                    if (teamPts.Count > 0)
                        myTeamsPointsDictionary.Add(position, teamPts.OrderBy(o => o.Value).Select(s => s.Key).ToArray());
                }

                //Save stats to Application scope
                Common.Functions.SetWeeklyStats(new ApplicationWeeklyStats() { Website = "ESPN", LeagueId = leagueId, PositionStats = myTeamsPointsDictionary });
            }
        }
Example #4
0
        protected List<Player> GetWaivers(string leagueId)
        {
            List<Player> myPlayers = new List<Player>();
            string html = Functions.GetHttpHtml(string.Format("http://games.espn.go.com/ffl/playertable/prebuilt/freeagency?leagueId={0}&=undefined&context=freeagency&view=overview&sortMap=AAAAARgAAAADAQAIY2F0ZWdvcnkDAAAAAwEABmNvbHVtbgMAAAAIAQAJZGlyZWN0aW9uA%2F%2F%2F%2F%2F8%3D&r=41671407&r=77879267", leagueId), (string)Session["espn"]);
            MatchCollection myTRs = Regex.Matches(html, @"(?i)<tr[^>]+pncPlayerRow[^>]+>(?<Content>.*?)</tr>", RegexOptions.Singleline);
            if (myTRs.Count > 0)
            {
                foreach (Match myTR in myTRs)
                {
                    MatchCollection myTDs = Regex.Matches(myTR.Groups["Content"].Value, @"(?i)<td[^>]*>(?<Content>.*?)</td>", RegexOptions.Singleline);
                    if (myTDs.Count > 0)
                    {
                        Match playerMatch = Regex.Match(myTDs[0].Groups["Content"].Value, @"(?i)playerid=""(?<PlayerId>\d+)""[^>]*>(?<PlayerName>[^<]+)</a>\W+(?<Team>\w{2,3})&nbsp;(?<Position>\w{1,4})", RegexOptions.Singleline);
                        Match injuryMatch = Regex.Match(myTDs[0].Groups["Content"].Value, @"(?i)<span[^>]*>(?<Content>[^<]+)</span>", RegexOptions.Singleline);
                        Match opponentMatch = Regex.Match(myTDs[5].Groups["Content"].Value, @"(?i)<a\s+[^>]+>(?<Opponent>[^<]+)</a>", RegexOptions.Singleline);

                        if (playerMatch.Success && opponentMatch.Success)
                        {
                            myPlayers.Add(new Player()
                            {
                                PlayerId = playerMatch.Groups["PlayerId"].Value,
                                Name = playerMatch.Groups["PlayerName"].Value
                                + string.Format(" {0}%", Regex.Replace(Common.Functions.StripHtmlTags(myTDs[myTDs.Count - 2].Groups["Content"].Value), @"\.\d+", string.Empty))
                                + (injuryMatch.Success ? string.Format(" - <span class=\"txRed\">{0}</span>", injuryMatch.Groups["Content"].Value) : string.Empty),
                                Position = playerMatch.Groups["Position"].Value,
                                Team = playerMatch.Groups["Team"].Value.ToLower(),
                                Opponent = Regex.Replace(opponentMatch.Groups["Opponent"].Value, @"(@|vs)", string.Empty).ToLower(),
                                Note01 = Common.Functions.StripHtmlTags(myTDs[2].Groups["Content"].Value) + " - " + Common.Functions.StripHtmlTags(myTDs[6].Groups["Content"].Value) + " " + (opponentMatch.Groups["Opponent"].Value.Contains("@") ? "@" : "vs")
                            });
                        }
                    }
                }
            }

            //Get the CBS images for the players
            using (FantasyFootballEntities db = new FantasyFootballEntities())
            {
                List<string> espnIdList = (from p in myPlayers select p.PlayerId).ToList();
                List<tbl_ff_players> playerEntityList = db.tbl_ff_players.Where(x => espnIdList.Contains(x.Espn) && x.Cbs != null).ToList();
                foreach (tbl_ff_players entityPlayer in playerEntityList)
                {
                    Player espnPlayer = (from p in myPlayers where p.PlayerId == entityPlayer.Espn select p).FirstOrDefault();
                    espnPlayer.PlayerAltId = entityPlayer.Cbs;
                }
            }

            return myPlayers;
        }
Example #5
0
        protected void GetSchedules(ref int week, ref List<tbl_ff_matchups> matchups)
        {
            FantasyFootballEntities db = new FantasyFootballEntities();
            tbl_ff_weeks myWeek = db.tbl_ff_weeks.Where(w => w.StartDate <= DateTime.Now && w.EndDate >= DateTime.Now).SingleOrDefault();
            if (myWeek != null)
            {
                List<tbl_ff_matchups> matches = db.tbl_ff_matchups.Where(mch => mch.Week <= myWeek.Id + 3).OrderBy(o => o.Date).ToList();
                //Correct Jacksonville abbrev
                foreach (tbl_ff_matchups matchrow in matches)
                {
                    switch (matchrow.HomeTeam)
                    {
                        case "JAC":
                            matchrow.HomeTeam = "JAX";
                            break;
                        case "WAS":
                            matchrow.HomeTeam = "WSH";
                            break;
                    }
                    switch (matchrow.AwayTeam)
                    {
                        case "JAC":
                            matchrow.AwayTeam = "JAX";
                            break;
                        case "WAS":
                            matchrow.AwayTeam = "WSH";
                            break;
                    }
                }

                week = myWeek.Id;
                matchups = matches;
            }
        }
Example #6
0
        protected List<Player> GetPlayers(string leagueId, string teamId, string seasonId)
        {
            string html = Functions.GetHttpHtml(string.Format("http://games.espn.go.com/ffl/clubhouse?leagueId={0}&teamId={1}&seasonId={2}", leagueId, teamId, seasonId), (string)Session["espn"]);
            Match htmlMatch = Regex.Match(html, @"(?i)<table[^>]+?class=""playertableFrameBorder""[^>]*>.*?</table>", RegexOptions.Singleline);
            List<Player> myPlayers = new List<Player>();
            if (htmlMatch.Success)
            {
                MatchCollection myTRs = Regex.Matches(htmlMatch.Value, @"(?i)<tr[^>]*>.*?</tr>", RegexOptions.Singleline);
                if (myTRs.Count > 0)
                {
                    bool isEditPage = htmlMatch.Value.Contains(@"pncButton");
                    foreach (Match myTR in myTRs)
                    {
                        if (myTR.Value.Contains("pncPlayerRow"))
                        {
                            MatchCollection myTDs = Regex.Matches(myTR.Value, @"(?i)<td[^>]*>(?<Content>.*?)</td>", RegexOptions.Singleline);
                            if (myTDs.Count > 0)
                            {
                                Match playerMatch = Regex.Match(myTDs[1].Groups["Content"].Value, @"(?i)playerid=""(?<PlayerId>\d+)""[^>]*>(?<PlayerName>[^<]+)</a>\W+(?<Team>\w{2,3})&nbsp;(?<Position>\w{1,4})", RegexOptions.Singleline);
                                Match opponentMatch = Regex.Match(myTDs[(isEditPage ? 4 : 3)].Groups["Content"].Value, @"(?i)<a[^>]+>(?<Opponent>[^<]+)</a>", RegexOptions.Singleline);
                                Match opponentRankMatch = Regex.Match(myTDs[(isEditPage ? 13 : 12)].Groups["Content"].Value, @"(?i)<a[^>]+?>(?<Content>.*?)</a>", RegexOptions.Singleline);
                                Match noteMatch = Regex.Match(myTDs[(isEditPage ? 5 : 4)].Groups["Content"].Value, @"(?i)<a[^>]+>(?<Content>[^<]+)</a>", RegexOptions.Singleline);
                                if (playerMatch.Success && opponentMatch.Success)
                                {
                                    myPlayers.Add(new Player()
                                    {
                                        PlayerId = playerMatch.Groups["PlayerId"].Value,
                                        Name = playerMatch.Groups["PlayerName"].Value,
                                        Position = playerMatch.Groups["Position"].Value,
                                        Team = playerMatch.Groups["Team"].Value.ToLower(),
                                        Opponent = Regex.Replace(opponentMatch.Groups["Opponent"].Value, @"@", string.Empty, RegexOptions.Singleline).ToLower(),
                                        OpponentRank = (opponentRankMatch.Success ? opponentRankMatch.Groups["Content"].Value : "&nbsp;"),
                                        Note01 = (noteMatch.Success ? noteMatch.Groups["Content"].Value : string.Empty)
                                    });
                                }
                            }
                        }
                    }
                }
            }

            //Get the CBS images for the players
            using (FantasyFootballEntities db = new FantasyFootballEntities())
            {
                List<string> espnIdList = (from p in myPlayers select p.PlayerId).ToList();
                List<tbl_ff_players> playerEntityList = db.tbl_ff_players.Where(x => espnIdList.Contains(x.Espn) && x.Cbs != null).ToList();
                foreach (tbl_ff_players entityPlayer in playerEntityList)
                {
                    Player espnPlayer = (from p in myPlayers where p.PlayerId == entityPlayer.Espn select p).FirstOrDefault();
                    espnPlayer.PlayerAltId = entityPlayer.Cbs;
                }
            }

            return myPlayers;
        }
Example #7
0
        public ActionResult WeeklyRankingsPPR()
        {
            List<string> playerEspnIds = new List<string>(), playerCbsIds = new List<string>();
            if (Session["espn"] != null)
            {
                string html = Functions.GetHttpHtml(string.Format("http://games.espn.go.com/ffl/leaguerosters?leagueId={0}", Request.Params["leagueId"]), (string)Session["espn"]);
                MatchCollection players = Regex.Matches(html, @"(?i)playerid=""(?<PlayerId>\d+)""", RegexOptions.Singleline);
                if (players.Count > 0)
                {
                    foreach (Match player in players)
                    {
                        playerEspnIds.Add(player.Groups["PlayerId"].Value);
                    }

                    using (FantasyFootballEntities db = new FantasyFootballEntities())
                    {
                        playerCbsIds = db.tbl_ff_players.Where(x => playerEspnIds.Contains(x.Espn) && x.Cbs != null).Select(s => s.Cbs).ToList();
                    }
                }
            }

            List<RankingsPost> myRankings = CbsController.GetRankingsWeeklyPPR(playerCbsIds);

            ViewBag.Title = "Weekly PPR Rankings";
            ViewBag.LeagueId = Request.Params["leagueId"];
            return View(myRankings);
        }
Example #8
0
        protected List<Player> GetWaivers(string leagueId)
        {
            string html = Functions.GetHttpHtml(string.Format("http://football.fantasysports.yahoo.com/f1/{0}/players?&sort=R_PO&sdir=1&status=A", leagueId), (string)Session["yahoo"]);
            Match htmlMatch = Regex.Match(html, @"(?i)<section[^>]+?id=""players-table-wrapper""[^>]*>.*?</section>", RegexOptions.Singleline);
            List<Player> myPlayers = new List<Player>();
            if (htmlMatch.Success)
            {
                MatchCollection myTRs = Regex.Matches(htmlMatch.Value, @"(?i)<tr[^>]*>.*?</tr>", RegexOptions.Singleline);
                if (myTRs.Count > 0)
                {
                    foreach (Match myTR in myTRs)
                    {
                        MatchCollection myTDs = Regex.Matches(myTR.Value, @"(?i)<td[^>]*>(?<Content>.*?)</td>", RegexOptions.Singleline);
                        if (myTDs.Count > 0)
                        {
                            Match playerMatch = Regex.Match(myTDs[1].Groups["Content"].Value, @"(?i)ysf-player-name.*?http://sports.yahoo.com/nfl/players/(?<PlayerId>\d+)[^>]+>(?<PlayerName>[^<]+)</a>.*?(?<Team>\w{2,3})\s+\-\s+(?<Position>\w{2,3})</span>", RegexOptions.Singleline);
                            Match opponentMatch = Regex.Match(myTDs[1].Groups["Content"].Value, @"(?i)ysf-game-status.*?<a\s+[^>]+>(?<Opponent>[^<]+)</a>", RegexOptions.Singleline);
                            Match injuryMatch = Regex.Match(myTDs[1].Groups["Content"].Value, @"(?i)<abbr[^>]*>(?<Content>[^<]+)</abbr>", RegexOptions.Singleline);
                            if (playerMatch.Success && opponentMatch.Success)
                            {
                                myPlayers.Add(new Player()
                                {
                                    PlayerId = playerMatch.Groups["PlayerId"].Value,
                                    Name = playerMatch.Groups["PlayerName"].Value
                                    + string.Format(" {0}", Regex.Replace(myTDs[6].Groups["Content"].Value, @"(?i)<[^>]+>", string.Empty))
                                    + (injuryMatch.Success ? string.Format(" - <span class=\"txRed\">{0}</span>", injuryMatch.Groups["Content"].Value) : string.Empty),
                                    Position = playerMatch.Groups["Position"].Value,
                                    Team = playerMatch.Groups["Team"].Value.ToLower(),
                                    Opponent = Regex.Match(opponentMatch.Groups["Opponent"].Value, @"\w+$", RegexOptions.Singleline).Value.ToLower(),
                                    Note01 = Regex.Replace(opponentMatch.Groups["Opponent"].Value, @"\s+(@|vs)\s+\w+$", string.Empty) + " - " + Regex.Replace(myTDs[3].Groups["Content"].Value, @"(?i)<[^>]+>", string.Empty)
                                });
                            }
                        }
                    }
                }
            }

            //Get the CBS images for the players
            using (FantasyFootballEntities db = new FantasyFootballEntities())
            {
                List<string> yahooIdList = (from p in myPlayers select p.PlayerId).ToList();
                List<tbl_ff_players> playerEntityList = db.tbl_ff_players.Where(x => yahooIdList.Contains(x.Yahoo) && x.Cbs != null).ToList();
                foreach (tbl_ff_players entityPlayer in playerEntityList)
                {
                    Player yahooPlayer = (from p in myPlayers where p.PlayerId == entityPlayer.Yahoo select p).FirstOrDefault();
                    yahooPlayer.PlayerAltId = entityPlayer.Cbs;
                }
            }

            return myPlayers;
        }
Example #9
0
        protected List<Player> GetPlayers(string leagueId, string teamId)
        {
            string html = Functions.GetHttpHtml(string.Format("http://football.fantasysports.yahoo.com/f1/{0}/{1}", leagueId, teamId), (string)Session["yahoo"]);
            Match htmlMatch = Regex.Match(html, @"(?i)<section[^>]+?id=""team-roster""[^>]*>.*?</section>", RegexOptions.Singleline);
            List<Player> myPlayers = new List<Player>();
            if (htmlMatch.Success)
            {
                MatchCollection myTRs = Regex.Matches(htmlMatch.Value, @"(?i)<tr[^>]*>.*?</tr>", RegexOptions.Singleline);
                if (myTRs.Count > 0)
                {
                    bool isEditPage = htmlMatch.Value.Contains(@"roster-edit-form");
                    foreach (Match myTR in myTRs)
                    {
                        MatchCollection myTDs = Regex.Matches(myTR.Value, @"(?i)<td[^>]*>(?<Content>.*?)</td>", RegexOptions.Singleline);
                        if (myTDs.Count > 0)
                        {
                            MatchCollection hrefMatches = Regex.Matches(myTDs[(isEditPage ? 2 : 1)].Groups["Content"].Value, @"(?i)<a.*?href=""(?<Href>[^""]+)[^>]+>(?<Content>.*?)</a>", RegexOptions.Singleline);
                            if (hrefMatches.Count > 0)
                            {
                                Match playerMatch = Regex.Match(myTDs[(isEditPage ? 2 : 1)].Groups["Content"].Value, @"(?i)ysf-player-name.*?http://sports.yahoo.com/nfl/(players|teams)/(?<PlayerId>[^""]+)[^>]+>(?<PlayerName>[^<]+)</a>.*?(?<Team>\w{2,3})\s+\-\s+(?<Position>\w{1,3})</span>", RegexOptions.Singleline);
                                Match opponentMatch = Regex.Match(hrefMatches[hrefMatches.Count - 1].Groups["Content"].Value, @"(?i)^(?<Note>[^<]+)\s(?<Opponent>\w+)$", RegexOptions.Singleline);
                                //Match opponentMatch = Regex.Match(hrefMatches[hrefMatches.Count - 1].Groups["Content"].Value, @"(?i)^(?<Note>[^<]+)<a[^>]+>(?<Opponent>\w+)$", RegexOptions.Singleline);
                                Match injuryMatch = Regex.Match(myTDs[(isEditPage ? 2 : 1)].Groups["Content"].Value, @"(?i)F-injury[^>]+>(?<InjuryStatus>[^<]+)</span>", RegexOptions.Singleline);
                                if (playerMatch.Success)
                                {
                                    myPlayers.Add(new Player()
                                    {
                                        PlayerId = playerMatch.Groups["PlayerId"].Value,
                                        Name = playerMatch.Groups["PlayerName"].Value + (injuryMatch.Success ? @" - <span class=""txRed"">" + injuryMatch.Groups["InjuryStatus"].Value.Substring(0, 1) + "</span>" : string.Empty),
                                        Position = playerMatch.Groups["Position"].Value,
                                        Team = playerMatch.Groups["Team"].Value.ToLower(),
                                        Opponent = opponentMatch.Groups["Opponent"].Value.ToLower(),
                                        Note01 = opponentMatch.Groups["Note"].Value.Trim()
                                    });
                                }
                            }
                        }
                    }
                }
            }

            //Get the CBS images for the players
            using (FantasyFootballEntities db = new FantasyFootballEntities())
            {
                List<string> yahooIdList = (from p in myPlayers select p.PlayerId).ToList();
                List<tbl_ff_players> playerEntityList = db.tbl_ff_players.Where(x => yahooIdList.Contains(x.Yahoo) && x.Cbs != null).ToList();
                foreach (tbl_ff_players entityPlayer in playerEntityList)
                {
                    Player yahooPlayer = (from p in myPlayers where p.PlayerId == entityPlayer.Yahoo select p).FirstOrDefault();
                    if (yahooPlayer != null)
                    {
                        yahooPlayer.PlayerAltId = entityPlayer.Cbs;
                    }
                }
            }

            return myPlayers;
        }
Example #10
0
        public ActionResult WeeklyRankingsPPR()
        {
            List<string> playerYahooIds = new List<string>(), playerCbsIds = new List<string>();

            if (Session["yahoo"] != null)
            {
                string html = Functions.GetHttpHtml(string.Format("http://football.fantasysports.yahoo.com/f1/{0}/starters", Request.Params["leagueId"]), (string)Session["yahoo"]);

                MatchCollection players = Regex.Matches(html, @"(?i)/nfl/(players|teams)/(?<PlayerId>[\w\d]+)""", RegexOptions.Singleline);
                if (players.Count > 0)
                {
                    foreach (Match player in players)
                    {
                        playerYahooIds.Add(player.Groups["PlayerId"].Value);
                    }

                    using (FantasyFootballEntities db = new FantasyFootballEntities())
                    {
                        playerCbsIds = db.tbl_ff_players.Where(x => playerYahooIds.Contains(x.Yahoo) && x.Cbs != null).Select(s => s.Cbs).ToList();
                    }
                }
            }

            List<RankingsPost> myRankings = CbsController.GetRankingsWeeklyPPR(playerCbsIds);
            Augment.UpdateOpponents(ref myRankings);

            ViewBag.Title = "Weekly PPR Rankings";
            ViewBag.LeagueId = Request.Params["leagueId"];
            return View(myRankings);
        }
Example #11
0
        public ActionResult YearlyWeeks()
        {
            FantasyFootballEntities db = new FantasyFootballEntities();
            DateTime mySeasonStartDate = new DateTime(2016, 9, 6);

            for (int i = 0; i < 17; i++)
            {
                DateTime myWeekStartDate = mySeasonStartDate.AddDays(i * 7);
                DateTime myWeekEndDate = myWeekStartDate.AddDays(7);
                myWeekEndDate = myWeekEndDate.AddTicks(-1);

                db.tbl_ff_weeks.Add(new tbl_ff_weeks()
                {
                    Id = i + 1,
                    StartDate = myWeekStartDate,
                    EndDate = myWeekEndDate
                });
            }

            db.SaveChanges();

            return View();
        }
Example #12
0
        public ActionResult Yahoo()
        {
            //Our list of positions we care about
            List<string> myPositions = new List<string>() { "QB", "WR", "RB", "TE", "K" };

            //Get our HTML list of HTML pages
            WebClient client = new WebClient();
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            Stream data = client.OpenRead("http://sports.yahoo.com/nfl/teams/");
            StreamReader reader = new StreamReader(data);
            string s = reader.ReadToEnd();
            data.Close();
            reader.Close();
            //<a href="/nfl/teams/buf/roster/" title="Roster" data-rapid_p="4">Roster</a>
            MatchCollection myTeamPages = Regex.Matches(s, @"/nfl/teams/(?<Team>[^""]+)/roster/", RegexOptions.Singleline);
            if (myTeamPages.Count > 0)
            {
                FantasyFootballEntities db = new FantasyFootballEntities();
                foreach (Match teamUrl in myTeamPages)
                {
                    WebClient myclient = new WebClient();
                    myclient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                    Stream mydata = myclient.OpenRead("http://sports.yahoo.com/nfl/teams/" + teamUrl.Groups["Team"].Value + "/roster/");
                    StreamReader myreader = new StreamReader(mydata);
                    string mys = myreader.ReadToEnd();
                    mydata.Close();
                    myreader.Close();

                    string myTeam = teamUrl.Groups["Team"].Value.ToUpper();
                    switch(myTeam)
                    {
                        case "GNB":
                            myTeam = "GB";
                            break;
                        case "KAN":
                            myTeam = "KC";
                            break;
                        case "NOR":
                            myTeam = "NO";
                            break;
                        case "NWE":
                            myTeam = "NE";
                            break;
                        case "SDG":
                            myTeam = "SD";
                            break;
                        case "SFO":
                            myTeam = "SF";
                            break;
                        case "TAM":
                            myTeam = "TB";
                            break;
                        case "WSH":
                            myTeam = "WAS";
                            break;
                    }

                    MatchCollection myPlayers = Regex.Matches(mys, @"(?i)<td\s*class=""number"">(?<JerseyNumber>\d+)</td>\s*<td[^>]*>\s*<a\s+href=""/nfl/players/(?<YahooId>\d+)/", RegexOptions.Singleline);
                    if (myPlayers.Count > 0)
                    {
                        foreach (Match player in myPlayers)
                        {
                            string YahooId = Regex.Replace(player.Groups["YahooId"].Value, @"\D", string.Empty);
                            string JerseyNo = player.Groups["JerseyNumber"].Value;
                            tbl_ff_players playerObj = db.tbl_ff_players.FirstOrDefault(x => x.Team == myTeam && x.JerseyNumber == JerseyNo);
                            if (playerObj != null)
                            {
                                playerObj.Yahoo = YahooId;
                            }
                        }
                    }

                }
                db.SaveChanges();
            }

            return View();
        }
Example #13
0
        public ActionResult UsaToday()
        {
            FantasyFootballEntities db = new FantasyFootballEntities();
            int myYear = DateTime.Now.Year;

            for (int i = 1; i < 17; i++)
            {
                WebClient myclient = new WebClient();
                myclient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                Stream mydata = myclient.OpenRead(string.Format("http://www.usatoday.com/sports/nfl/schedule/{1}/season-regular/{0}/", i, myYear));
                StreamReader myreader = new StreamReader(mydata);
                string html = myreader.ReadToEnd();
                mydata.Close();
                myreader.Close();

                MatchCollection myTables = Regex.Matches(html, @"(?i)<table.*?class=""schedule""[^>]*>.*?<b>(?<Date>.*?)</b>.*?<tbody>(?<Content>.*?)</tbody>.*?</table>", RegexOptions.Singleline);
                if(myTables.Count > 0)
                {
                    foreach (Match myTable in myTables)
                    {
                        MatchCollection myTRs = Regex.Matches(myTable.Groups["Content"].Value, @"(?i)<tr>(?<Content>.*?)</tr>", RegexOptions.Singleline);
                        if (myTRs.Count > 0)
                        {
                            foreach (Match myTR in myTRs)
                            {
                                MatchCollection myTDs = Regex.Matches(myTR.Groups["Content"].Value, @"(?i)<t(d|h)[^>]*>(?<Content>.*?)</t(d|h)>", RegexOptions.Singleline);
                                MatchCollection myTeams = Regex.Matches(myTDs[0].Groups["Content"].Value, @"(?<Team>\w+)\.png", RegexOptions.Singleline);
                                string time = Regex.Replace(myTDs[1].Groups["Content"].Value, @"(AM|PM)\sET", @" $1", RegexOptions.Singleline);

                                if (myTeams.Count > 0)
                                {
                                    db.tbl_ff_matchups.Add(new tbl_ff_matchups()
                                    {
                                        HomeTeam = myTeams[1].Groups["Team"].Value.Trim(),
                                        AwayTeam = myTeams[0].Groups["Team"].Value.Trim(),
                                        Season = myYear,
                                        Week = i,
                                        Date = DateTime.Parse(string.Format("{0}, {2} {1}", Regex.Replace(myTable.Groups["Date"].Value, @"\w{2}$", string.Empty, RegexOptions.Singleline), time, myYear))
                                    });
                                }
                            }
                        }
                    }
                }
            }

            db.SaveChanges();

            return View();
        }
Example #14
0
        //public ActionResult CbsStatsWeeklyPlayers()
        //{
        //    FantasyFootballEntities db = new FantasyFootballEntities();
        //    for (int i = 1; i < 17; i++)
        //    {
        //        //Get our HTML list of HTML pages
        //        WebClient client = new WebClient();
        //        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
        //        Stream data = client.OpenRead("http://www.cbssports.com/nfl/scoreboard/2013/week" + i);
        //        StreamReader reader = new StreamReader(data);
        //        string s = reader.ReadToEnd();
        //        data.Close();
        //        reader.Close();
        //        MatchCollection myScoresPages = Regex.Matches(s, @"(?i)<a[^>]+?href=""(?<Uri>[^""]+)""[^>]*>GameTracker</a>", RegexOptions.Singleline);
        //        if (myScoresPages.Count > 0)
        //        {
        //            List<tbl_ff_stats_weekly_players> PlayerIds = new List<tbl_ff_stats_weekly_players>();
        //            foreach (Match myUri in myScoresPages)
        //            {
        //                //Get our HTML list of HTML pages
        //                WebClient myScoresClient = new WebClient();
        //                myScoresClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
        //                Stream myScoresData = myScoresClient.OpenRead("http://www.cbssports.com" + myUri.Groups["Uri"].Value);
        //                StreamReader myScoresReader = new StreamReader(myScoresData);
        //                string myScoresHtml = myScoresReader.ReadToEnd();
        //                myScoresData.Close();
        //                myScoresReader.Close();
        //                MatchCollection myStatTables = Regex.Matches(myScoresHtml, @"<span\sclass=""pStats(?<StatId>\d+)"">(?<Html>.*?)</span>", RegexOptions.Singleline);
        //                string myTempHtml = string.Empty;
        //                foreach (Match myHtml in myStatTables)
        //                    myTempHtml += myHtml.Value;
        //                MatchCollection myPlayerIds = Regex.Matches(myTempHtml, @"/nfl/players/playerpage/(?<PlayerId>\d+)/", RegexOptions.Singleline);
        //                List<String> PlayerTally = new List<string>();
        //                if (myPlayerIds.Count > 0)
        //                    foreach (Match myPlayer in myPlayerIds)
        //                        if (!PlayerTally.Contains(myPlayer.Groups["PlayerId"].Value))
        //                        {
        //                            PlayerIds.Add(new tbl_ff_stats_weekly_players()
        //                            {
        //                                Cbs = myPlayer.Groups["PlayerId"].Value,
        //                                Week = i
        //                            });
        //                            PlayerTally.Add(myPlayer.Groups["PlayerId"].Value);
        //                        }
        //                if (myStatTables.Count > 0)
        //                {
        //                    foreach (Match myStatsHtml in myStatTables)
        //                    {
        //                        MatchCollection myHtmlRows = Regex.Matches(myStatsHtml.Groups["Html"].Value, @"(?i)<tr[^>]*>.*?</tr>", RegexOptions.Singleline);
        //                        if (myHtmlRows.Count > 0)
        //                        {
        //                            MatchCollection myColumns = Regex.Matches(myHtmlRows[0].Value, @"(?i)<td[^>]*>(?<Header>.*?)</td>", RegexOptions.Singleline);
        //                            if ((myColumns.Count > 0) && (myHtmlRows.Count > 1))
        //                            {
        //                                for (int j = 1; j < myHtmlRows.Count; j++)
        //                                {
        //                                    Match myPlayerId = Regex.Match(myHtmlRows[j].Value, @"(?i)/playerpage/(?<PlayerId>\d+)/", RegexOptions.Singleline);
        //                                    if (myPlayerId.Success)
        //                                    {
        //                                        tbl_ff_stats_weekly_players myPlayer = PlayerIds.SingleOrDefault(x => x.Cbs == myPlayerId.Groups["PlayerId"].Value);
        //                                        if (myPlayer != null)
        //                                        {
        //                                            MatchCollection myCells = Regex.Matches(myHtmlRows[j].Value, @"(?i)<td[^>]*>(?<Content>.*?)</td>", RegexOptions.Singleline);
        //                                            for (int k = 1; k < myColumns.Count; k++)
        //                                            {
        //                                                switch (myStatsHtml.Groups["StatId"].Value)
        //                                                {
        //                                                    //QB
        //                                                    case "00":
        //                                                    case "10":
        //                                                        switch (myColumns[k].Groups["Header"].Value)
        //                                                        {
        //                                                            case "CP/AT":
        //                                                                string[] myVar01 = myCells[k].Groups["Content"].Value.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
        //                                                                if (myVar01.Length == 2)
        //                                                                {
        //                                                                    myPlayer.PassComp = Convert.ToInt32(myVar01[0]);
        //                                                                    myPlayer.PassAtt = Convert.ToInt32(myVar01[1]);
        //                                                                }
        //                                                                break;
        //                                                            case "YDS":
        //                                                                myPlayer.PassYds = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                            case "TD":
        //                                                                myPlayer.PassTDs = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                            case "INT":
        //                                                                myPlayer.PassINTs = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                        }
        //                                                        break;
        //                                                    //RB
        //                                                    case "01":
        //                                                    case "11":
        //                                                        switch (myColumns[k].Groups["Header"].Value)
        //                                                        {
        //                                                            case "ATT":
        //                                                                myPlayer.Rushes = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                            case "YDS":
        //                                                                myPlayer.RushYds = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                            case "TD":
        //                                                                myPlayer.RushTDs = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                        }
        //                                                        break;
        //                                                    //WR
        //                                                    case "02":
        //                                                    case "12":
        //                                                        switch (myColumns[k].Groups["Header"].Value)
        //                                                        {
        //                                                            case "REC":
        //                                                                myPlayer.Receptions = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                            case "YDS":
        //                                                                myPlayer.RecYards = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                            case "TD":
        //                                                                myPlayer.RecTDs = Convert.ToInt32(myCells[k].Groups["Content"].Value);
        //                                                                break;
        //                                                        }
        //                                                        break;
        //                                                }
        //                                            }
        //                                        }
        //                                    }
        //                                }
        //                            }
        //                        }
        //                    }
        //                }
        //                //var PlayerEntities = db.tbl_ff_players.Where(x => PlayerIds.Contains(x.Cbs)).ToList();
        //                //return View();
        //            }
        //            foreach (tbl_ff_stats_weekly_players weekStat in PlayerIds)
        //                db.tbl_ff_stats_weekly_players.Add(weekStat);
        //            db.SaveChanges();
        //        }
        //        else
        //        {
        //            break;
        //        }
        //    }
        //    return View();
        //}
        public ActionResult Espn()
        {
            //Get our HTML list of HTML pages
            WebClient client = new WebClient();
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            Stream data = client.OpenRead("http://espn.go.com/nfl/teams");
            StreamReader reader = new StreamReader(data);
            string s = reader.ReadToEnd();
            data.Close();
            reader.Close();

            MatchCollection myTeamPages = Regex.Matches(s, @"/nfl/team/roster/_/name/[^""]+", RegexOptions.Singleline);
            if (myTeamPages.Count > 0)
            {
                FantasyFootballEntities db = new FantasyFootballEntities();
                foreach (Match teamUrl in myTeamPages)
                {
                    WebClient myclient = new WebClient();
                    myclient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                    Stream mydata = myclient.OpenRead("http://espn.go.com" + teamUrl.Value);
                    StreamReader myreader = new StreamReader(mydata);
                    string mys = myreader.ReadToEnd();
                    mydata.Close();
                    myreader.Close();

                    string myTeam = Regex.Match(teamUrl.Value, @"/name/(?<Team>[^/]+)/", RegexOptions.Singleline).Groups["Team"].Value.ToUpper();
                    if (myTeam == "WSH")
                        myTeam = "WAS";
                    MatchCollection myPlayers = Regex.Matches(mys, @"(?i)<td[^>]*>(?<JerseyNumber>\d+)</td>\s*<td[^>]*>\s*<a\s+href=""http://espn.go.com/nfl/player/_/id/(?<EspnId>\d+)/", RegexOptions.Singleline);
                    if (myPlayers.Count > 0)
                    {
                        foreach (Match player in myPlayers)
                        {
                            string EspnId = Regex.Replace(player.Groups["EspnId"].Value, @"\D", string.Empty);
                            string JerseyNo = player.Groups["JerseyNumber"].Value;
                            tbl_ff_players playerObj = db.tbl_ff_players.FirstOrDefault(x => x.Team == myTeam && x.JerseyNumber == JerseyNo);
                            if (playerObj != null)
                            {
                                playerObj.Espn = EspnId;
                            }
                        }
                    }

                }
                db.SaveChanges();
            }

            return View();
        }
Example #15
0
        //
        // GET: /Database/
        public ActionResult Cbs()
        {
            //Our list of positions we care about
            List<string> myPositions = new List<string>() { "QB", "WR", "RB", "TE", "K" };

            //Get our HTML list of HTML pages
            WebClient client = new WebClient();
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            Stream data = client.OpenRead("http://www.cbssports.com/nfl/teams");
            StreamReader reader = new StreamReader(data);
            string s = reader.ReadToEnd();
            data.Close();
            reader.Close();

            MatchCollection myTeamPages = Regex.Matches(s, @"/nfl/teams/roster/[^""]+", RegexOptions.Singleline);
            if (myTeamPages.Count > 0)
            {
                FantasyFootballEntities db = new FantasyFootballEntities();
                foreach (Match teamUrl in myTeamPages)
                {
                    WebClient myclient = new WebClient();
                    myclient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                    Stream mydata = myclient.OpenRead("http://www.cbssports.com" + teamUrl.Value);
                    StreamReader myreader = new StreamReader(mydata);
                    string mys = myreader.ReadToEnd();
                    mydata.Close();
                    myreader.Close();

                    string myTeam = Regex.Match(teamUrl.Value, @"/roster/(?<Team>[^/]+)/", RegexOptions.Singleline).Groups["Team"].Value;
                    Match myHtml = Regex.Match(mys, @"id=""roster"".*?class=""data""", RegexOptions.Singleline);
                    if (myHtml.Success)
                    {
                        MatchCollection myPlayers = Regex.Matches(myHtml.Value, @"(?i)<td[^>]*>(?<JerseyNumber>\d+)</td>\s*<td[^>]*>\s*<a[^>]*?id=""(?<CbsId>[^""]+)""[^>]*>(?<PlayerName>.*?)</a>.*?</td>\s*<td[^>]*>(?<Position>.*?)</td>", RegexOptions.Singleline);
                        if (myPlayers.Count > 0)
                        {
                            foreach (Match player in myPlayers)
                            {
                                string Position = player.Groups["Position"].Value.Trim();
                                if(myPositions.Contains(Position))
                                {
                                    string CbsId = Regex.Replace(player.Groups["CbsId"].Value, @"\D", string.Empty);
                                    string[] Name = player.Groups["PlayerName"].Value.Replace(" (IR)", string.Empty).Split(new char[] { ',' });

                                    tbl_ff_players playerObj = db.tbl_ff_players.FirstOrDefault(x => x.Cbs == CbsId);
                                    if (playerObj != null)
                                    {
                                        playerObj.FirstName = Name[1].Trim();
                                        playerObj.LastName = Name[0].Trim();
                                        playerObj.JerseyNumber = player.Groups["JerseyNumber"].Value.Trim();
                                        playerObj.Position = Position;
                                        playerObj.Team = myTeam;
                                    }
                                    else
                                    {
                                        db.tbl_ff_players.Add(new tbl_ff_players()
                                        {
                                            FirstName = Name[1].Trim(),
                                            LastName = Name[0].Trim(),
                                            JerseyNumber = player.Groups["JerseyNumber"].Value.Trim(),
                                            Position = Position,
                                            Team = myTeam,
                                            Cbs = CbsId
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
                db.SaveChanges();
            }

            return View();
        }