Esempio n. 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;
            }
        }
        public TeamSimulationDetails(BasketballTeam t)
        {
            Team     = t;
            Players  = new BasketballPlayerList();
            Outcomes = new List <TeamSimulationOutcome>();
            double[] oppfg = t.OpponentFieldGoalsTakenByGame();
            double[] fg    = t.FieldGoalsTakenByGame();
            FieldGoalPercentage         = t.RemoveHomeAdvantage(t.FieldGoalPercentageByGame()).Average();
            FieldGoalsTaken             = t.RemoveHomeAdvantage(fg).Average();
            FreeThrowPercentage         = t.RemoveHomeAdvantage(t.FreeThrowPercentageByGame()).Average();
            ThreePointPercentage        = t.RemoveHomeAdvantage(t.ThreePointPercentageByGame()).Average();
            ThreePointsTakenPercentage  = t.RemoveHomeAdvantage(t.ThreePointersTakenByGame().Divide(fg)).Average();
            OffensiveReboundPercentage  = t.RemoveHomeAdvantage(t.OffensiveReboundPercentageByGame()).Average();
            DefensiveReboundPercentage  = t.RemoveHomeAdvantage(t.DefensiveReboundPercentageByGame()).Average();
            OffensiveTurnoverPercentage = t.RemoveHomeAdvantage(t.TurnoversByGame().Divide(fg)).Average();
            double[] b = t.StealsByGame();
            StealPercentage = t.RemoveHomeAdvantage(b.Divide(b.Add(oppfg))).Average();
            b = t.BlocksByGame();
            BlockPercentage               = t.RemoveHomeAdvantage(b.Divide(b.Add(oppfg))).Average();
            BlockedPercentage             = t.RemoveHomeAdvantage(t.OpponentBlocksByGame().Divide(fg)).Average();
            FoulPercentage                = t.RemoveHomeAdvantage(t.FoulsByGame().Divide(oppfg)).Average();
            FouledPercentage              = t.RemoveHomeAdvantage(t.OpponentFoulsByGame().Divide(fg)).Average();
            PlayerFreeThrowProbabilities  = new double[t.Players.Count];
            PlayerFreeThrowPercentages    = new double[t.Players.Count];
            PlayerFieldGoalProbabilities  = new double[t.Players.Count];
            PlayerFieldGoalPercentages    = new double[t.Players.Count];
            PlayerThreePointProbabilities = new double[t.Players.Count];
            PlayerThreePointPercentages   = new double[t.Players.Count];
            PlayerAssistPercentages       = new double[t.Players.Count];
            PlayerOnCourtProbabilities    = new double[t.Players.Count];
            PlayerStartProbabilities      = new double[t.Players.Count];
            PlayersOnCourt                = new double[t.Players.Count];
            double ft  = t.FreeThrowsTakenByGame().Sum();
            double fgs = fg.Sum();
            double ap  = t.AssistsByGame().Sum();

            for (int p = 0; p < t.Players.Count; p++)
            {
                Players.Add(t.Players[p]);
                PlayerFreeThrowProbabilities[p] = t.Players[p].FTA / ft;
                PlayerFreeThrowPercentages[p]   = t.Players[p].FTP;
                PlayerFieldGoalProbabilities[p] = t.Players[p].FTA / fgs;
                PlayerFieldGoalPercentages[p]   = t.Players[p].FGP;
                if (t.Players[p].FGA > 0)
                {
                    PlayerThreePointProbabilities[p] = t.Players[p].A3P / t.Players[p].FGA;
                }
                else
                {
                    PlayerThreePointProbabilities[p] = 0;
                }
                PlayerThreePointPercentages[p] = t.Players[p].P3P;
                PlayerAssistPercentages[p]     = t.Players[p].AST / (double)(t.Players[p].AST + t.Players[p].FGA);
                PlayerOnCourtProbabilities[p]  = t.Players[p].MIN_T * t.Matchups.Count / 48.0;
                PlayerStartProbabilities[p]    = t.Players[p].Starts / (double)t.Matchups.Count;
            }
        }
Esempio n. 3
0
        public static double[] PointsAllowedByGame(this BasketballTeam t)
        {
            double[] pts = new double[t.Matchups.Count];
            for (int i = 0; i < t.Matchups.Count; i++)
            {
                pts[i] = t.Matchups[i].OppScore;
            }

            return(pts);
        }
Esempio n. 4
0
        public static double TurnoversPerGame(this BasketballTeam t)
        {
            double to = 0.0;

            foreach (BasketballPlayer p in t.Players)
            {
                to += p.TO;
            }

            return(to / t.Matchups.Count);
        }
 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;
                                          } }));
 }
        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);
        }
Esempio n. 7
0
        public static double PointsAllowedPerGame(this BasketballTeam t)
        {
            double papg = 0.0;

            foreach (Matchup m in t.Matchups)
            {
                papg += m.OppScore;
            }

            return(papg / t.Matchups.Count);
        }
 public static double[] FoulsByGame(this BasketballTeam t)
 {
     double[] pts = new double[t.Matchups.Count];
     for (int i = 0; i < t.Matchups.Count; i++)
     {
         foreach (BasketballPerformance p in t.Matchups[i].Performances)
         {
             pts[i] = p.PersonalFouls;
         }
     }
     return(pts);
 }
Esempio n. 9
0
 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBox2.SelectedIndex >= 0)
     {
         lineGraphTeamStats.Text = (string)(listBox1.SelectedItem);
         BasketballTeam t = teamURLs[comboBox2.SelectedIndex];
         if (t != null)
         {
             lineGraphTeamStats.FeedData(GetTeamStatByGame(t, (string)listBox1.SelectedItem));
         }
     }
 }
Esempio n. 10
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. 11
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBoxTeams.Items.Clear();
            BasketballTeam te = teamURLs[(string)comboBox1.SelectedItem];

            foreach (BasketballPlayer p in te.Players)
            {
                if (p != null)
                {
                    listBoxTeams.Items.Add(p.Name);
                }
            }
        }
        public static double HomeAdvantage(this BasketballTeam team, double[] stat)
        {
            double den = stat.Given(team.AwayGames(), x => x >= 0.5).AverageNonZero();

            if (den != 0)
            {
                return(stat.Given(team.HomeGames(), x => x >= 0.5).AverageNonZero() / den);
            }
            else
            {
                return(double.MaxValue);
            }
        }
Esempio n. 13
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);
 }
Esempio n. 14
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);
            }
        }
Esempio n. 15
0
        public static double[] OpponentPointsPerGameByGame(this BasketballTeam t)
        {
            double[] ofgp = new double[t.Matchups.Count];

            for (int i = 0; i < t.Matchups.Count; i++)
            {
                BasketballTeam opp = t.Teams[t.Matchups[i].Opponent];
                if (opp != null)
                {
                    ofgp[i] = opp.PointsPerGame();
                }
            }

            return(ofgp);
        }
        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);
        }
Esempio n. 17
0
        public static double[] TurnoversByGame(this BasketballTeam t)
        {
            double[] to = new double[t.Matchups.Count];
            for (int i = 0; i < to.Length; i++)
            {
                double topg = 0;
                foreach (BasketballPerformance p in t.Matchups[i].Performances)
                {
                    topg += p.Turnovers;
                }
                to[i] = topg;
            }

            return(to);
        }
        public static double FieldGoalPercentage(this BasketballTeam t)
        {
            double fgm = 0.0, fga = 0.0;

            foreach (BasketballPlayer p in t.Players)
            {
                fgm += p.FGM;
                fga += p.FGA;
            }
            if (fgm == 0 || fga == 0)
            {
                return(0);
            }
            return(fgm / fga);
        }
Esempio n. 19
0
 public BracketMatchup(BasketballTeam t1, BasketballTeam t2, BracketMatchup p1, BracketMatchup p2)
 {
     Team1      = t1;
     Team2      = t2;
     PrevRound1 = p1;
     PrevRound2 = p2;
     if (PrevRound1 != null)
     {
         PrevRound1.NextRound = this;
     }
     if (PrevRound2 != null)
     {
         PrevRound2.NextRound = this;
     }
 }
        public static double ThreePointPercentage(this BasketballTeam t)
        {
            double fgm = 0.0, fga = 0.0;

            foreach (BasketballPlayer p in t.Players)
            {
                fgm += p.M3P;
                fga += p.A3P;
            }
            if (fgm == 0 || fga == 0)
            {
                return(0);
            }
            return(fgm / fga);
        }
        public static double[] OffensivePpgRatio(this BasketballTeam t)
        {
            double[] d   = t.PointsPerGameByGame();
            double   ppg = t.PointsPerGame();

            for (int k = 0; k < t.Matchups.Count; k++)
            {
                BasketballTeam opp = t.Teams[t.Matchups[k].Opponent];
                if (opp != null)
                {
                    d[k] /= (opp.DefensivePpgRatioAverage() * ppg);
                }
            }
            return(d);
        }
        public static double[] FreeThrowsTakenByGame(this BasketballTeam t)
        {
            double[] to = new double[t.Matchups.Count];
            for (int i = 0; i < to.Length; i++)
            {
                double topg = 0;
                foreach (BasketballPerformance p in t.Matchups[i].Performances)
                {
                    topg += p.FreeThrowsAttempted;
                }
                to[i] = topg;
            }

            return(to);
        }
Esempio n. 23
0
 public void Add(BasketballTeam t)
 {
     if (m_Count < 64)
     {
         int index = m_Count / 2;
         if (m_Count % 2 == 0)
         {
             Bracket.Matchups[index].Team1 = t;
         }
         else
         {
             Bracket.Matchups[index].Team2 = t;
         }
         m_Count++;
     }
 }
Esempio n. 24
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);
        }
Esempio n. 25
0
 public static BasketballTeam Deserialize(string input)
 {
     try
     {
         BasketballTeam p = new BasketballTeam();
         if (!input.StartsWith("Team:"))
         {
             return(null);
         }
         string[] fields = input.Substring(5).Split(';');
         p.teamName = fields[0];
         p.teamURL  = fields[1];
         return(p);
     }
     catch { }
     return(null);
 }
Esempio n. 26
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. 27
0
        public static double[] DefensivePpgRatio(this BasketballTeam t)
        {
            double[] data = new double[t.Matchups.Count];
            for (int k = 0; k < data.Length; k++)
            {
                BasketballTeam opp = t.Teams[t.Matchups[k].Opponent];
                if (opp == null)
                {
                    data[k] = 1.0;
                }
                else
                {
                    data[k] = t.Matchups[k].OppScore / opp.PointsPerGame();
                }
            }

            return(data);
        }
Esempio n. 28
0
        public void RunMatchup()
        {
            if (PrevRound1 != null)
            {
                PrevRound1.RunMatchup();
                Team1 = PrevRound1.Winner;
            }

            if (PrevRound2 != null)
            {
                PrevRound2.RunMatchup();
                Team2 = PrevRound2.Winner;
            }

            int numSims = 21;

            Simulation = new Simulation(this.Team1, this.Team2);
            Simulation.SimulationCompleted += Simulation_SimulationCompleted;
            Simulation.StartSimulation(numSims);
            int numWins = 0;

            for (int k = 0; k < numSims; k++)
            {
                if (Simulation.team1.Outcomes[k].Win)
                {
                    numWins++;
                }
            }

            Team1Wins = numWins;
            Team2Wins = numSims - numWins;

            if (numWins > 0 && numSims / numWins < 2)
            {
                this.Winner = Team1;
                this.Loser  = Team2;
            }
            else
            {
                this.Winner = Team2;
                this.Loser  = Team1;
            }
        }
Esempio n. 29
0
        private double[] GetTeamStatByGame(BasketballTeam t, string stat)
        {
            switch (stat)
            {
            case "Points Per Game":
                return(t.PointsPerGameByGame());

            case "Field Goal Percentage":
                return(t.FieldGoalPercentageByGame());

            case "Free Throw Percentage":
                return(t.FreeThrowPercentageByGame());

            case "Three Point Percentage":
                return(t.ThreePointPercentageByGame());

            case "Average Offensive PPG Ratio":
                return(t.PointsPerGameByGame());

            case "Points Allowed Per Game":
                return(t.PointsAllowedByGame());

            case "Opponent Field Goal Percentage":
                return(t.OpponentFieldGoalPercentageByGame());

            case "Opponent Free Throw Percentage":
                return(t.OpponentFreeThrowPercentageByGame());

            case "Opponent Three Point Percentage":
                return(t.OpponentThreePointPercentageByGame());

            case "Opponent Field Goal Percentage Ratio":
                return(t.OpponentFieldGoalPercentageRatioByGame());

            case "Opponent Free Throw Percentage Ratio":
                return(t.OpponentFreeThrowPercentageRatioByGame());

            case "Opponent Three Point Percentage Ratio":
                return(t.OpponentThreePointPercentageRatioByGame());
            }

            return(new double[] { 0 });
        }
Esempio n. 30
0
 private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBox5.SelectedItem != null)
     {
         scatterPlot2.Clear();
         BasketballTeam t = teamURLs[comboBox5.SelectedIndex];
         scatterPlot2.Add(t.teamName, 0, 0);
         foreach (Matchup m in t.Matchups)
         {
             BasketballTeam opp = t.Teams[m.Opponent];
             if (opp != null)
             {
                 scatterPlot2.Add(t.teamName, m.TeamScore, opp.OpponentPointsPerGame());
             }
         }
         scatterPlot2.Text = "Points vs. Points Allowed Per Game";
         scatterPlot2.Feed();
     }
 }