public static double BenchPointsAgainstOpponent(this BasketballTeam t, Matchup m)
 {
     return(m.Performances.StatSum(p => { if (p.Status == "Bench")
                                          {
                                              return ((BasketballPerformance)p).OffensiveRebounds;
                                          }
                                          else
                                          {
                                              return 0;
                                          } }));
 }
Beispiel #2
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);
        }
Beispiel #3
0
 public Matchup GetOpposingMatchup(Matchup m, out BasketballTeam opponent)
 {
     opponent = Teams[m.Opponent];
     if (opponent != null)
     {
         Matchup oppMatch = opponent.Matchups.Find(z => z.ID == teamName + m.OppScore.ToString() + m.TeamScore.ToString());
         if (oppMatch != null)
         {
             return(oppMatch);
         }
     }
     return(null);
 }
Beispiel #4
0
        public static double[] OpponentFreeThrowPercentageByGame(this BasketballTeam t)
        {
            double[] ofgp = new double[t.Matchups.Count];

            for (int i = 0; i < t.Matchups.Count; i++)
            {
                BasketballTeam opp;
                Matchup        oppMatch = t.GetOpposingMatchup(i, out opp);
                if (opp != null && oppMatch != null)
                {
                    ofgp[i] = opp.FreeThrowPercentageAgainstOpponent(oppMatch);
                }
            }

            return(ofgp);
        }
Beispiel #5
0
        public static double[] OpponentFoulsByGame(this BasketballTeam t)
        {
            double[] ofgp = new double[t.Matchups.Count];

            for (int i = 0; i < t.Matchups.Count; i++)
            {
                BasketballTeam opp;
                Matchup        oppMatch = t.GetOpposingMatchup(i, out opp);
                if (opp != null && oppMatch != null)
                {
                    foreach (BasketballPerformance p in oppMatch.Performances)
                    {
                        ofgp[i] += p.PersonalFouls;
                    }
                }
            }

            return(ofgp);
        }
Beispiel #6
0
 public static Matchup Deserialize(string input)
 {
     try
     {
         Matchup p = new Matchup();
         if (!input.StartsWith("Matchup:"))
         {
             return(null);
         }
         string[] fields = input.Substring(8).Split(';');
         p.Opponent  = fields[0];
         p.Win       = bool.Parse(fields[1]);
         p.Home      = bool.Parse(fields[2]);
         p.TeamScore = int.Parse(fields[3]);
         p.OppScore  = int.Parse(fields[4]);
         p.ID        = fields[5];
         return(p);
     }
     catch { }
     return(null);
 }
Beispiel #7
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);
        }
 public static double BlocksAgainstOpponent(this BasketballTeam t, Matchup m)
 {
     return(m.Performances.StatSum(p => { return ((BasketballPerformance)p).Blocks; }));
 }
 public static double DefensiveReboundsAgainstOpponent(this BasketballTeam t, Matchup m)
 {
     return(m.Performances.StatSum(p => { return ((BasketballPerformance)p).DefensiveRebounds; }));
 }
        public static double ThreePointPercentageAgainstOpponent(this BasketballTeam t, Matchup m)
        {
            double fgm = m.Performances.FieldFoldLeft <Performance, int>(0, (i, p) => { return(i + ((BasketballPerformance)p).ThreePointersMade); });
            double fga = m.Performances.FieldFoldLeft <Performance, int>(0, (i, p) => { return(i + ((BasketballPerformance)p).ThreePointersAttempted); });

            if (fgm == 0 || fga == 0)
            {
                return(0);
            }
            return(fgm / fga);
        }
        public static double FreeThrowPercentageAgainstOpponent(this BasketballTeam t, Matchup m)
        {
            double fgm = 0.0, fga = 0.0;

            foreach (BasketballPerformance p in m.Performances)
            {
                fgm += p.FreeThrowsMade;
                fga += p.FreeThrowsAttempted;
            }
            if (fgm == 0 || fga == 0)
            {
                return(0);
            }
            return(fgm / fga);
        }