예제 #1
0
        /// <summary>
        ///     Retrieves teams and team record by parsing an HTML page.
        /// </summary>
        private void GetStandings()
        {
            //Get the file text
            var source = GetHTML("http://www.thebestdamnleague.com/game/lgreports/leagues/league_100_standings.html");

            //Decode the html
            source = WebUtility.HtmlDecode(source);

            //Load the decoded string
            var resultat = new HtmlDocument();

            resultat.LoadHtml(source);

            //Retrieve the team W/L information
            var standingsHtmlNodes = resultat.DocumentNode.Descendants().Where
                                         (x => x.Name == "table" && x.Attributes["class"] != null &&
                                         x.Attributes["class"].Value.Contains("sortable")).ToList();

            var Team   = "";
            var Wins   = "";
            var Losses = "";


            foreach (var htmlNode in standingsHtmlNodes)
            {
                if (htmlNode.ChildNodes.Count == 13)
                {
                    foreach (var childNode in htmlNode.ChildNodes)
                    {
                        if (childNode.Name != "#text" && childNode != htmlNode.ChildNodes[1])
                        {
                            Team   = childNode.ChildNodes[1].InnerText;
                            Wins   = childNode.ChildNodes[3].InnerText;
                            Losses = childNode.ChildNodes[5].InnerText;
                            var PythRecord = childNode.ChildNodes[11].InnerText.Split('-');

                            if (Teams.Any(x => x.Name == Team) && Wins != "W")
                            {
                                Teams.FirstOrDefault(x => x.Name == Team).Wins   = Convert.ToInt32(Wins);
                                Teams.FirstOrDefault(x => x.Name == Team).Losses = Convert.ToInt32(Losses);

                                Teams.FirstOrDefault(x => x.Name == Team).PythWins   = Convert.ToInt32(PythRecord[0]);
                                Teams.FirstOrDefault(x => x.Name == Team).PythLosses = Convert.ToInt32(PythRecord[1]);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Calculates average of  Opponent's Opponent's Win Percentage based on Pythagorean W/L
        /// </summary>
        /// <param name="teams"></param>
        public void CalcPythOppOppWinPercentage(SortableBindingList <TeamModel> teams)
        {
            //Opponent's Opponent's Win percentage is calculated by summing all of the opponents win percentages together, and
            //dividing by total number of opponents.

            float totalOpponentWinPercentage = 0;

            foreach (var opponentModel in OpponentsList)
            {
                if (opponentModel.OpponentTeamID != TeamID)
                {
                    if (opponentModel.WinsVersus != 0 || opponentModel.LossesVersus != 0)
                    {
                        //Get the opponent's OpponentsWinPercentage
                        float currentOppWinPercentage =
                            teams.FirstOrDefault(x => x.Name.Equals(opponentModel.OpponentTeamName)).PythOpponentsWinPercentage;

                        //Add it to the total
                        totalOpponentWinPercentage += currentOppWinPercentage;
                    }
                }
            }
            //Divide the total by the number of opponents against whom the team has wins or losses
            PythOpponentsOpponentWinPercentage = totalOpponentWinPercentage / OpponentsList.Count(x => x.WinsVersus != 0 || x.LossesVersus != 0);
        }