Esempio n. 1
0
        public static void AdjustTeamScores(TeamList teams)
        {
            double maxScore   = teams[0].Score;
            double minScore   = teams[teams.Count - 1].Score;
            double rangeScore = maxScore - minScore;

            foreach (Team t in teams)
            {
                t.OldScore = t.Score;
            }
            foreach (Team team in teams)
            {
                double s      = 0.0;
                double fade   = 1.0;
                double factor = 0.95;
                //foreach (Matchup m in team.Matchups)
                for (int m = team.Matchups.Count - 1; m >= 0; m--)
                {
                    Team t = teams[team.Matchups[m].Opponent];
                    if (t != null)
                    {
                        s += fade * ((t.OldScore - minScore) / rangeScore + (team.Matchups[m].Win ? 0 : -tolerance));
                    }
                    fade *= factor;
                }
                team.Score = s + team.weight;
            }
        }
Esempio n. 2
0
        //public static void GetNflTeams(TeamList teams)
        //{

        //    HtmlIterator teamPage = new HtmlIterator(WebUtility.GetNflURL().ToString());
        //    while (teamPage.GetNext("<h5 ><a href=\"http://www.espn.com/nfl/team/_/name/"))
        //    {
        //        Team te = new Team();
        //        te.teamName = teamPage.GetNextTagText("a");
        //        teamPage.GetNext("<h5 ><a href=\"/nfl/team/roster/_/name/");
        //        te.teamURL = "http://www.espn.com" + teamPage.GetNextAttributeValue("href");
        //        teams.Add(te);
        //        PlayerList playerList = new PlayerList();
        //        HtmlIterator t = new HtmlIterator(te.teamURL);
        //        if (!t.GetNext("COLLEGE")) continue;
        //        int endOfTable = t.HTML.IndexOf("</table>", t.StartIndex);
        //        while (t.StartIndex < endOfTable && t.StartIndex >= 0)
        //        {
        //            FootballPlayer player = new FootballPlayer();
        //            int dummy;
        //            if (int.TryParse(t.GetNextTagText("td"), out dummy))
        //                player.Number = dummy;
        //            player.Name = t.GetNextTagText("a");
        //            player.Position = t.GetNextTagText("td");
        //            if (int.TryParse(t.GetNextTagText("td"), out dummy))
        //                player.Age = dummy;
        //            player.Height = 0;
        //            string[] height = t.GetNextTagText("td").Split('-');
        //            for (int i = 0; i < height.Length; i++)
        //            {
        //                if (int.TryParse(height[i], out dummy))
        //                    player.Height += (12 * dummy) / (11 * i + 1);
        //            }
        //            if (int.TryParse(t.GetNextTagText("td"), out dummy))
        //                player.Weight = dummy;
        //            if (int.TryParse(t.GetNextTagText("td"), out dummy))
        //                player.Experience = dummy;
        //            else player.Experience = 0; // Rookie
        //            player.College = t.GetNextTagText("td");
        //            te.Players.Add(player);
        //        }
        //    }
        //}

        public static void GetNcaabTeams(TeamList teams)
        {
            HtmlIterator teamPage = new HtmlIterator(WebUtility.GetURL().ToString());

            while (teamPage.GetNext("<tr><td class='nowrap'"))
            {
                BasketballTeam te = new BasketballTeam();
                te.teamName = teamPage.GetNextAttributeValue("rel");
                te.teamURL  = "http://basketball.realgm.com" + teamPage.GetNextAttributeValue("href");
                teams.Add(te);
                BasketballPlayerList playerList = new BasketballPlayerList();
                HtmlIterator         t          = new HtmlIterator(te.teamURL + "rosters/");
                if (!t.GetNext("High School/Prep School"))
                {
                    continue;
                }
                int endOfTable = t.HTML.IndexOf("</tbody>", t.StartIndex);
                while (t.StartIndex < endOfTable && t.StartIndex >= 0)
                {
                    BasketballPlayer player = new BasketballPlayer();
                    int dummy;
                    if (int.TryParse(t.GetNextTagText("td"), out dummy))
                    {
                        player.Number = dummy;
                    }
                    else
                    {
                        continue;
                    }
                    player.Name     = t.GetNextTagText("a");
                    player.Class    = t.GetNextTagText("td");
                    player.Position = t.GetNextTagText("td");
                    player.Height   = 0;
                    string[] height = t.GetNextTagText("td").Split('-');
                    for (int i = 0; i < height.Length; i++)
                    {
                        if (int.TryParse(height[i], out dummy))
                        {
                            player.Height += (12 * dummy) / (11 * i + 1);
                        }
                    }
                    if (int.TryParse(t.GetNextTagText("td"), out dummy))
                    {
                        player.Weight = dummy;
                    }
                    player.BirthDate   = t.GetNextTagText("td");
                    player.BirthCity   = t.GetNextTagText("td");
                    player.Nationality = t.GetNextTagText("td");
                    player.HighSchool  = t.GetNextTagText("td");
                    te.Players.Add(player);
                }
            }
        }
Esempio n. 3
0
        public static TeamList Deserialize(string path)
        {
            try
            {
                TeamList teams = new TeamList();
                using (System.IO.StreamReader reader = new System.IO.StreamReader(path))
                {
                    string[]              lines = reader.ReadToEnd().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    BasketballTeam        t     = new BasketballTeam();
                    Matchup               m     = new Matchup();
                    BasketballPlayer      p     = new BasketballPlayer();
                    BasketballPerformance perf  = new BasketballPerformance();
                    foreach (string line in lines)
                    {
                        int index = line.IndexOf(':');
                        if (index > 0)
                        {
                            switch (line.Substring(0, index))
                            {
                            case "Team":
                                t = BasketballTeam.Deserialize(line);
                                teams.Add(t);
                                break;

                            case "Matchup":
                                m = Matchup.Deserialize(line);
                                t.Matchups.Add(m);
                                break;

                            case "Player":
                                p = BasketballPlayer.Deserialize(line);
                                t.Players.Add(p);
                                break;

                            case "Performance":
                                perf        = BasketballPerformance.Deserialize(line, t.Matchups);
                                perf.Player = p;
                                p.Performances.Add(perf);
                                break;
                            }
                        }
                    }
                }
                foreach (BasketballTeam t in teams)
                {
                    t.Teams = teams;
                }
                return(teams);
            }
            catch { }
            return(null);
        }
Esempio n. 4
0
 public static void Serialize(TeamList teams, string path)
 {
     try
     {
         using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path))
         {
             foreach (BasketballTeam t in teams)
             {
                 writer.Write(t.Serialize());
             }
         }
     }
     catch { }
 }
Esempio n. 5
0
        public static void GetTeamSchedule(TeamList tl)
        {
            fetch = 0;
            teams = tl;
            foreach (Team t in teams)
            {
                // System.Threading.Thread thr = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(_getncaabsched));
                // thr.Start(t);
                _getncaabsched((object)t);
            }

            while (fetch < teams.Count)
            {
                ;
            }
        }
Esempio n. 6
0
        public static void GetTeamStatistics(TeamList tl)
        {
            fetch = 0;
            teams = tl;
            foreach (BasketballTeam t in teams)
            {
                //	System.Threading.Thread thr = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(_getstats));
                //	thr.Start(t);
                _getstats(t);
            }

            while (fetch < teams.Count)
            {
                ;
            }
        }
Esempio n. 7
0
        public static void SortTeamsAve(TeamList teams)
        {
            List <string> ranks = new List <string>();

            for (int i = 0; i < teams.Count; i++)
            {
                for (int j = i + 1; j < teams.Count; j++)
                {
                    if (teams[i].aveScore < teams[j].aveScore)
                    {
                        BasketballTeam t = teams[i];
                        teams[i] = teams[j];
                        teams[j] = t;
                    }
                }
            }
        }
Esempio n. 8
0
        public static bool SortTeams(TeamList teams)
        {
            count = 0;
            List <string> ranks = new List <string>();

            for (int i = 0; i < teams.Count; i++)
            {
                for (int j = i + 1; j < teams.Count; j++)
                {
                    if (teams[i].Score < teams[j].Score)
                    {
                        count++;
                        BasketballTeam t = teams[i];
                        teams[i] = teams[j];
                        teams[j] = t;
                    }
                }
            }

            return(count < 5);
        }
Esempio n. 9
0
        public static void GetTeamRawScores(TeamList teams, double p5, double g5, double fcs)
        {
            foreach (Team team in teams)
            {
                team.weight = (team.flag == 2 ? p5 : team.flag == 1 ? g5 : fcs);
                double s      = 0.0;
                double fade   = 1.0;
                double factor = 1.0;
                //foreach (Matchup m in team.Matchups)
                for (int m = team.Matchups.Count - 1; m >= 0; m--)
                {
                    Team t = teams[team.Matchups[m].Opponent];
                    if (t != null)
                    {
                        s += fade * (t.WinPercentage + (double)(team.Matchups[m].TeamScore - team.Matchups[m].OppScore) / 35 + (team.Matchups[m].Win ? 0 : -tolerance));
                    }

                    fade *= factor;
                }
                team.Score = s + team.weight;
            }
        }
Esempio n. 10
0
        private void get_data()
        {
            bool downloadLatestData = true;

            StatusUpdate("Retrieving teams...");

            if (downloadLatestData)
            {
                teamURLs = new TeamList();
                Teams.GetNcaabTeams(teamURLs);
                StatusUpdate("Getting team schedules...");
                Schedule.GetTeamSchedule(teamURLs);
                StatusUpdate("Accessing player statistics...");
                Statistics.GetTeamStatistics(teamURLs);
            }
            else
            {
                teamURLs = TeamList.Deserialize("C:\\Users\\Dustin\\Desktop\\Teams.txt");
            }
            StatusUpdate("Determining team power rankings...");
            TeamRankings.GetTeamRawScores(teamURLs, 2.0, 2.0, 0.0);
            while (!TeamRankings.SortTeams(teamURLs))
            {
                TeamRankings.AdjustTeamScores(teamURLs);
            }

            double maxScore = teamURLs[0].Score;
            double minScore = teamURLs[teamURLs.Count - 1].Score;

            for (int k = 0; k < teamURLs.Count; k++)
            {
                teamURLs[k].Score -= minScore;
                teamURLs[k].Score /= (maxScore - minScore);
                teamURLs[k].Score++;
                teamURLs[k].Score /= 2;
                teamURLs[k].Score *= teamURLs[k].Score;
                //teamURLs[k].Score = Math.Log(teamURLs[k].Score, 2);
            }

            string[] ind = new string[] { "Virginia", "UMBC", "Creighton", "Kansas State", "Kentucky", "Davidson", "Arizona", "Buffalo",
                                          "Miami (FL)", "Loyola (IL)", "Tennessee", "Wright State", "Nevada", "Texas", "Cincinnati", "Georgia State",
                                          "Xavier", "Texas Southern", "Missouri", "Florida State", "Ohio State", "South Dakota State", "Gonzaga", "UNC Greensboro",
                                          "Houston", "San Diego State", "Michigan", "Montana", "Texas A&M", "Providence", "North Carolina", "Lipscomb",
                                          "Villanova", "Radford", "Virginia Tech", "Alabama", "West Virginia", "Murray State", "Wichita State", "Marshall",
                                          "Florida", "St. Bonaventure", "Texas Tech", "Stephen F. Austin", "Arkansas", "Butler", "Purdue", "Cal State Fullerton",
                                          "Kansas", "Pennsylvania", "Seton Hall", "NC State", "Clemson", "New Mexico State", "Auburn", "Charleston",
                                          "Texas Christian", "Syracuse", "Michigan State", "Bucknell", "Rhode Island", "Oklahoma", "Duke", "Iona" };
            for (int i = 0; i < 64; i++)
            {
                BasketballTeam t = teamURLs[ind[i]];
                bracketGraph1.Add(t);
            }

            bracketGraph1.Bracket.RunBracketMatchup();

            if (downloadLatestData)
            {
                TeamRankings.SortTeamsAve(teamURLs);
                StatusUpdate("");
                TeamList.Serialize(teamURLs, "C:\\Users\\Dustin\\Desktop\\Teams.txt");
            }
            else
            {
                StatusUpdate("");
            }

            EnableControls();
        }