示例#1
0
        private static void GetPlayerInfo(BasketballTeam t, string s, ref int count, ref int end)
        {
            count = s.IndexOf("a href=", count + 11) + 8;
            count = s.IndexOf("\">", count) + 2;
            end   = s.IndexOf("</a>", count);
            BasketballPlayer p = t.Players[s.Substring(count, end - count)];

            if (p != null)
            {
                count      = s.IndexOf("<td>", end) + 4;
                end        = s.IndexOf("</td>", count);
                p.Position = char.Parse(s.Substring(count, 1)).ToString();

                count = s.IndexOf("<td>", end) + 4;
                end   = s.IndexOf("</td>", count);
                int feet = (int)(s[count] - '0');
                if (feet < 0)
                {
                    feet = 6;
                }
                int inches = 0;
                if (!int.TryParse(s.Substring(count + 2, end - count - 2), out inches))
                {
                    inches = 0;
                }
                p.Height = 12 * feet + inches;
            }
        }
示例#2
0
 public static BasketballPlayer Deserialize(string input)
 {
     try
     {
         BasketballPlayer p = new BasketballPlayer();
         if (!input.StartsWith("Player:"))
         {
             return(null);
         }
         string[] fields = input.Substring(7).Split(';');
         p.Name        = fields[0];
         p.Class       = fields[1];
         p.BirthDate   = fields[2];
         p.BirthCity   = fields[3];
         p.Nationality = fields[4];
         p.HighSchool  = fields[5];
         p.GP          = int.Parse(fields[6]);
         p.Height      = int.Parse(fields[7]);
         p.Weight      = int.Parse(fields[8]);
         p.Number      = int.Parse(fields[9]);
         p.Position    = fields[10];
         return(p);
     }
     catch { }
     return(null);
 }
示例#3
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);
                }
            }
        }
示例#4
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);
        }
示例#5
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            BasketballTeam   te = teamURLs[(string)comboBox1.SelectedItem];
            BasketballPlayer p  = te.Players[listBoxTeams.SelectedIndex];

            if (p != null && p.Performances.Count > 0)
            {
                double[] minutes = new double[p.Performances.Count];
                double[] points  = new double[p.Performances.Count];
                double[] fgp     = new double[p.Performances.Count];
                double[] ftp     = new double[p.Performances.Count];
                double[] p3p     = new double[p.Performances.Count];
                double[] reb     = new double[p.Performances.Count];
                double[] offreb  = new double[p.Performances.Count];
                double[] defreb  = new double[p.Performances.Count];
                double[] ast     = new double[p.Performances.Count];
                double[] stl     = new double[p.Performances.Count];
                double[] blk     = new double[p.Performances.Count];
                double[] to      = new double[p.Performances.Count];
                for (int k = 0; k < p.Performances.Count; k++)
                {
                    minutes[k] = p.Performances[k].Minutes;
                    points[k]  = p.Performances[k].Points;
                    fgp[k]     = p.Performances[k].FieldGoalPercentage;
                    ftp[k]     = p.Performances[k].FreeThrowPercentage;
                    p3p[k]     = p.Performances[k].ThreePointPercentage;
                    reb[k]     = p.Performances[k].Rebounds;
                    offreb[k]  = p.Performances[k].OffensiveRebounds;
                    defreb[k]  = p.Performances[k].DefensiveRebounds;
                    ast[k]     = p.Performances[k].Assists;
                    stl[k]     = p.Performances[k].Steals;
                    blk[k]     = p.Performances[k].Blocks;
                    to[k]      = p.Performances[k].Turnovers;
                }

                lineGraphMinutes.FeedData(minutes);
                lineGraphPoint.FeedData(points);
                lineGraphFieldGoal.FeedData(fgp);
                lineGraphFreeThrow.FeedData(ftp);
                lineGraphThreePoint.FeedData(p3p);
                lineGraphRebound.FeedData(reb);
                lineGraphOffensiveRebound.FeedData(offreb);
                lineGraphDefensiveRebound.FeedData(defreb);
                lineGraphAssist.FeedData(ast);
                lineGraphSteal.FeedData(stl);
                lineGraphBlock.FeedData(blk);
                lineGraphTurnover.FeedData(to);
            }
        }
示例#6
0
 private void SortPlayersByMinutes()
 {
     for (int i = 0; i < this.Players.Count - 1; i++)
     {
         for (int j = i + 1; j < this.Players.Count; j++)
         {
             if (((BasketballPlayer)this.Players[j]).MIN > ((BasketballPlayer)this.Players[j]).MIN)
             {
                 BasketballPlayer temp = this.Players[i];
                 this.Players[i] = this.Players[j];
                 this.Players[j] = temp;
             }
         }
     }
 }
示例#7
0
        private static BasketballPlayer GetPlayer(string s, ref int count, ref int end)
        {
            count = s.IndexOf("a href=", count + 11) + 8;
            count = s.IndexOf("\">", count) + 2;
            end   = s.IndexOf("</a>", count);
            BasketballPlayer p = new BasketballPlayer(s.Substring(count, end - count));

            //p.GP = (int)GetStatistic(s, ref count, ref end);
            //p.MIN = GetStatistic(s, ref count, ref end);
            //p.PPG = GetStatistic(s, ref count, ref end);
            //p.RPG = GetStatistic(s, ref count, ref end);
            //p.APG = GetStatistic(s, ref count, ref end);
            //p.SPG = GetStatistic(s, ref count, ref end);
            //p.BPG = GetStatistic(s, ref count, ref end);
            //p.TPG = GetStatistic(s, ref count, ref end);
            //p.FGP = GetStatistic(s, ref count, ref end);
            //p.FTP = GetStatistic(s, ref count, ref end);
            //p.P3P = GetStatistic(s, ref count, ref end);
            return(p);
        }
示例#8
0
        private static BasketballPlayer GetPlayerStats(BasketballTeam t, string s, ref int count, ref int end)
        {
            count = s.IndexOf("a href=", count + 11) + 8;
            count = s.IndexOf("\">", count) + 2;
            end   = s.IndexOf("</a>", count);
            BasketballPlayer p = t.Players[s.Substring(count, end - count)];

            //p.MIN_T = (int)GetStatistic(s, ref count, ref end);
            //p.FGM = (int)GetStatistic(s, ref count, ref end);
            //p.FGA = (int)GetStatistic(s, ref count, ref end);
            //p.FTM = (int)GetStatistic(s, ref count, ref end);
            //p.FTA = (int)GetStatistic(s, ref count, ref end);
            //p.M3P = (int)GetStatistic(s, ref count, ref end);
            //p.A3P = (int)GetStatistic(s, ref count, ref end);
            //p.PTS = (int)GetStatistic(s, ref count, ref end);
            //p.OFFR = (int)GetStatistic(s, ref count, ref end);
            //p.DEFR = (int)GetStatistic(s, ref count, ref end);
            //p.REB = (int)GetStatistic(s, ref count, ref end);
            //p.AST = (int)GetStatistic(s, ref count, ref end);
            //p.TO = (int)GetStatistic(s, ref count, ref end);
            //p.STL = (int)GetStatistic(s, ref count, ref end);
            //p.BLK = (int)GetStatistic(s, ref count, ref end);
            return(p);
        }