Esempio n. 1
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. 2
0
 public TeamSimulationOutcome(TeamSimulationDetails sim)
 {
     SimDetails = sim;
     SimDetails.Outcomes.Add(this);
     foreach (BasketballPlayer p in SimDetails.Players)
     {
         BasketballPerformance perf = new BasketballPerformance()
         {
             Player = p
         };
         this.Performances.Add(perf);
     }
 }
Esempio n. 3
0
 public static BasketballPerformance Deserialize(string input, List <Matchup> Matchups)
 {
     try
     {
         BasketballPerformance p = new BasketballPerformance();
         if (!input.StartsWith("Performance:"))
         {
             return(null);
         }
         string[] fields = input.Substring(12).Split(';');
         p.Points                 = int.Parse(fields[0]);
         p.OffensiveRebounds      = int.Parse(fields[1]);
         p.DefensiveRebounds      = int.Parse(fields[2]);
         p.Assists                = int.Parse(fields[3]);
         p.Steals                 = int.Parse(fields[4]);
         p.Blocks                 = int.Parse(fields[5]);
         p.Turnovers              = int.Parse(fields[6]);
         p.PersonalFouls          = int.Parse(fields[7]);
         p.FieldGoalsMade         = int.Parse(fields[8]);
         p.FieldGoalsAttempted    = int.Parse(fields[9]);
         p.FreeThrowsMade         = int.Parse(fields[10]);
         p.FreeThrowsAttempted    = int.Parse(fields[11]);
         p.ThreePointersMade      = int.Parse(fields[12]);
         p.ThreePointersAttempted = int.Parse(fields[13]);
         p.Minutes                = double.Parse(fields[14]);
         p.FIC     = double.Parse(fields[15]);
         p.Status  = fields[16];
         p.Matchup = Matchups.Find(m => m.ID == fields[17]);
         if (p.Matchup != null)
         {
             p.Matchup.Performances.Add(p);
         }
         return(p);
     }
     catch { }
     return(null);
 }
Esempio n. 4
0
        //private static void _getnflsched(object o)
        //{
        //    Team team = (Team)o;
        //    // HtmlIterator h_team = new HtmlIterator(((Team)o).teamURL), h;
        //    //  HtmlIterator h = new HtmlIterator("http://espn.go.com/college-football/team/schedule/"+((Team)o).teamURL.Substring(((Team)o).teamURL.IndexOf('_')));
        //    HtmlIterator h = new HtmlIterator(((FootballTeam)o).ScheduleUrl);
        //    while (h.GetNext("<li class=\"game-status\">"))
        //    {
        //        Matchup m = new Matchup();
        //        m.Home = !h.GetNextTagText("li").Contains("@");
        //        h.GetNext("<li class=\"team - name\"><a href=\"");
        //        m.Opponent = h.GetNextAttributeValue("href");
        //        h.GetNext("<li class=\"score\"><a href=\"");
        //        m.MatchupURL = "http:" + h.GetNextAttributeValue("href");
        //        HtmlIterator g = new HtmlIterator(m.MatchupURL);

        //        if (!g.GetNext("<h2>" + team.teamName)) continue;
        //        g.GetNext("<tbody");

        //        int endOfTable = g.HTML.IndexOf("/tbody", g.StartIndex);
        //        while (g.StartIndex < endOfTable)
        //        {
        //            string name = g.GetNextTagText("a");
        //            FootballPlayer p;
        //            if ((p = (FootballPlayer)team.Players[name]) != null)
        //            {
        //                int dummy;
        //                double doubleDummy;
        //                FootballPerformance perf = new FootballPerformance();
        //                perf.Status = g.GetNextTagText("td");
        //                g.GetNextTagText("td");
        //                if (double.TryParse(g.GetNextAttributeValue("rel"), out doubleDummy))
        //                    perf.Minutes = doubleDummy;
        //                string[] fg = g.GetNextTagText("td").Split('-');
        //                if (fg != null && fg.Length > 0)
        //                {
        //                    if (int.TryParse(fg[0], out dummy))
        //                        perf.FieldGoalsMade = dummy;
        //                    if (fg.Length > 1 && int.TryParse(fg[1], out dummy))
        //                        perf.FieldGoalsAttempted = dummy;
        //                }
        //                fg = g.GetNextTagText("td").Split('-');
        //                if (fg != null && fg.Length > 0)
        //                {
        //                    if (int.TryParse(fg[0], out dummy))
        //                        perf.ThreePointersMade = dummy;
        //                    if (fg.Length > 1 && int.TryParse(fg[1], out dummy))
        //                        perf.ThreePointersAttempted = dummy;
        //                }
        //                fg = g.GetNextTagText("td").Split('-');
        //                if (fg != null && fg.Length > 0)
        //                {
        //                    if (int.TryParse(fg[0], out dummy))
        //                        perf.FreeThrowsMade = dummy;
        //                    if (fg.Length > 1 && int.TryParse(fg[1], out dummy))
        //                        perf.FreeThrowsAttempted = dummy;
        //                }
        //                if (double.TryParse(g.GetNextAttributeValue("rel"), out doubleDummy))
        //                    perf.FIC = doubleDummy;
        //                if (double.TryParse(g.GetNextAttributeValue("rel"), out doubleDummy))
        //                    perf.OffensiveRebounds = (int)doubleDummy;
        //                if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
        //                    perf.DefensiveRebounds = dummy;
        //                g.GetNextAttributeValue("rel");
        //                if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
        //                    perf.Assists = dummy;
        //                if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
        //                    perf.PersonalFouls = dummy;
        //                if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
        //                    perf.Steals = dummy;
        //                if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
        //                    perf.Turnovers = dummy;
        //                if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
        //                    perf.Blocks = dummy;
        //                if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
        //                    perf.Points = dummy;
        //                perf.Matchup = m;
        //                perf.Player = p;
        //                p.Performances.Add(perf);
        //            }
        //        }

        //    }
        //    System.Threading.Interlocked.Increment(ref fetch);
        //}

        private static void _getncaabsched(object o)
        {
            BasketballTeam team = (BasketballTeam)o;
            // HtmlIterator h_team = new HtmlIterator(((Team)o).teamURL), h;
            //  HtmlIterator h = new HtmlIterator("http://espn.go.com/college-football/team/schedule/"+((Team)o).teamURL.Substring(((Team)o).teamURL.IndexOf('_')));
            HtmlIterator h = new HtmlIterator(((BasketballTeam)o).teamURL + "Schedule");

            while (h.GetNext("data-th=\"Opponent\""))
            {
                Matchup m = new Matchup();
                m.Home = !h.GetNextTagText("div").Contains("@");
                h.GetNext("<img");
                h.GetNext("</div>");
                h.ExtendToBeginningOfNext("</td>");
                if (h.Selection.Contains("<a href"))
                {
                    h.EndIndex = h.StartIndex;
                    m.Opponent = h.GetNextTagText("a");
                }
                else
                {
                    h.StartIndex += 6;
                    m.Opponent    = h.Selection;
                }
                bool win = false;
                int  awayScore = 0, homeScore = 0;
                h.GetNext("data-th=\"Result\"");
                string gameUrl = h.GetNextAttributeValue("href");
                h.GetPrevious("Result");
                string[] GameResult = h.GetNextTagText("a").RemoveWhiteSpace().Split(',', '-');
                if (GameResult.Length >= 3)
                {
                    win = GameResult[0].Contains("W");
                    int.TryParse(GameResult[1], out homeScore);
                    int.TryParse(GameResult[2], out awayScore);
                    if (m.Home)
                    {
                        //m.Opponent = away_team;
                        m.Win       = homeScore > awayScore;
                        m.TeamScore = homeScore;
                        m.OppScore  = awayScore;
                        // m.MatchupURL = h_team.Selection;
                    }
                    else
                    {
                        //m.Opponent = home_team;
                        m.Win       = homeScore < awayScore;
                        m.TeamScore = awayScore;
                        m.OppScore  = homeScore;
                        // m.MatchupURL = h_team.Selection;
                    }
                    m.ID = m.Opponent + m.TeamScore.ToString() + m.OppScore.ToString();
                    team.Matchups.Add(m);
                }
                HtmlIterator g = new HtmlIterator("http://basketball.realgm.com" + gameUrl);

                if (!g.GetNext("<h2>" + team.teamName))
                {
                    continue;
                }
                g.GetNext("<tbody");

                int endOfTable = g.HTML.IndexOf("/tbody", g.StartIndex);
                while (g.StartIndex < endOfTable)
                {
                    string           name = g.GetNextTagText("a");
                    BasketballPlayer p;
                    if ((p = (BasketballPlayer)team.Players[name]) != null)
                    {
                        int    dummy;
                        double doubleDummy;
                        BasketballPerformance perf = new BasketballPerformance();
                        perf.Status = g.GetNextTagText("td");
                        g.GetNextTagText("td");
                        if (double.TryParse(g.GetNextAttributeValue("rel"), out doubleDummy))
                        {
                            perf.Minutes = doubleDummy;
                        }
                        string[] fg = g.GetNextTagText("td").Split('-');
                        if (fg != null && fg.Length > 0)
                        {
                            if (int.TryParse(fg[0], out dummy))
                            {
                                perf.FieldGoalsMade = dummy;
                            }
                            if (fg.Length > 1 && int.TryParse(fg[1], out dummy))
                            {
                                perf.FieldGoalsAttempted = dummy;
                            }
                        }
                        fg = g.GetNextTagText("td").Split('-');
                        if (fg != null && fg.Length > 0)
                        {
                            if (int.TryParse(fg[0], out dummy))
                            {
                                perf.ThreePointersMade = dummy;
                            }
                            if (fg.Length > 1 && int.TryParse(fg[1], out dummy))
                            {
                                perf.ThreePointersAttempted = dummy;
                            }
                        }
                        fg = g.GetNextTagText("td").Split('-');
                        if (fg != null && fg.Length > 0)
                        {
                            if (int.TryParse(fg[0], out dummy))
                            {
                                perf.FreeThrowsMade = dummy;
                            }
                            if (fg.Length > 1 && int.TryParse(fg[1], out dummy))
                            {
                                perf.FreeThrowsAttempted = dummy;
                            }
                        }
                        if (double.TryParse(g.GetNextAttributeValue("rel"), out doubleDummy))
                        {
                            perf.FIC = doubleDummy;
                        }
                        if (double.TryParse(g.GetNextAttributeValue("rel"), out doubleDummy))
                        {
                            perf.OffensiveRebounds = (int)doubleDummy;
                        }
                        if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
                        {
                            perf.DefensiveRebounds = dummy;
                        }
                        g.GetNextAttributeValue("rel");
                        if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
                        {
                            perf.Assists = dummy;
                        }
                        if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
                        {
                            perf.PersonalFouls = dummy;
                        }
                        if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
                        {
                            perf.Steals = dummy;
                        }
                        if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
                        {
                            perf.Turnovers = dummy;
                        }
                        if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
                        {
                            perf.Blocks = dummy;
                        }
                        if (int.TryParse(g.GetNextAttributeValue("rel"), out dummy))
                        {
                            perf.Points = dummy;
                        }
                        perf.Matchup = m;
                        perf.Player  = p;
                        p.Performances.Add(perf);
                    }
                }
            }
            System.Threading.Interlocked.Increment(ref fetch);
        }