예제 #1
0
        /// <summary>Calculates the metric stats for this team.</summary>
        /// <param name="tsopp">The opposing team stats.</param>
        /// <param name="playoffs">
        ///     if set to <c>true</c>, the metrics will be calculated based on the team's playoff performances.
        /// </param>
        public void CalcMetrics(TeamStats tsopp, bool playoffs = false)
        {
            var tempMetricsOwn = new Dictionary<string, double>();

            var tempTotalsOwn = new double[Totals.Length];
            for (var i = 0; i < Totals.Length; i++)
            {
                if (!playoffs)
                {
                    tempTotalsOwn[i] = Totals[i];
                }
                else
                {
                    tempTotalsOwn[i] = PlTotals[i];
                }
            }

            var tempTotalsOpp = new double[tsopp.Totals.Length];
            if ((!playoffs && (GetGames() != tsopp.GetGames())) || (playoffs && (GetPlayoffGames() != tsopp.GetPlayoffGames())))
            {
                for (var i = 0; i < tsopp.Totals.Length; i++)
                {
                    tempTotalsOpp[i] = double.NaN;
                }
            }
            else
            {
                for (var i = 0; i < tsopp.Totals.Length; i++)
                {
                    if (!playoffs)
                    {
                        tempTotalsOpp[i] = tsopp.Totals[i];
                    }
                    else
                    {
                        tempTotalsOpp[i] = tsopp.PlTotals[i];
                    }
                }
            }

            var games = (!playoffs) ? GetGames() : GetPlayoffGames();

            var poss = calcPossMetric(tempTotalsOwn, tempTotalsOpp);
            tempMetricsOwn.Add("Poss", poss);
            tempMetricsOwn.Add("PossPG", poss / games);

            var tempMetricsOpp = (!playoffs) ? tsopp.Metrics : tsopp.PlMetrics;
            try
            {
                tempMetricsOpp.Add("Poss", poss);
            }
            catch (ArgumentException)
            {
                tempMetricsOpp["Poss"] = poss;
            }
            catch
            {
                Console.WriteLine("Possessions metric couldn't be calculated for team " + ID);
            }

            var pace = MainWindow.GameLength * ((tempMetricsOwn["Poss"] + tempMetricsOpp["Poss"]) / (2 * (tempTotalsOwn[TAbbrT.MINS])));
            tempMetricsOwn.Add("Pace", pace);

            var ortg = (tempTotalsOwn[TAbbrT.PF] / tempMetricsOwn["Poss"]) * 100;
            tempMetricsOwn.Add("ORTG", ortg);

            var drtg = (tempTotalsOwn[TAbbrT.PA] / tempMetricsOwn["Poss"]) * 100;
            tempMetricsOwn.Add("DRTG", drtg);

            var astP = (tempTotalsOwn[TAbbrT.AST])
                       / (tempTotalsOwn[TAbbrT.FGA] + tempTotalsOwn[TAbbrT.FTA] * 0.44 + tempTotalsOwn[TAbbrT.AST]
                          + tempTotalsOwn[TAbbrT.TOS]);
            tempMetricsOwn.Add("AST%", astP);

            var drebP = tempTotalsOwn[TAbbrT.DREB] / (tempTotalsOwn[TAbbrT.DREB] + tempTotalsOpp[TAbbrT.OREB]);
            tempMetricsOwn.Add("DREB%", drebP);

            var efgP = (tempTotalsOwn[TAbbrT.FGM] + tempTotalsOwn[TAbbrT.TPM] * 0.5) / tempTotalsOwn[TAbbrT.FGA];
            tempMetricsOwn.Add("EFG%", efgP);

            var effD = ortg - drtg;
            tempMetricsOwn.Add("EFFd", effD);

            var tor = tempTotalsOwn[TAbbrT.TOS]
                      / (tempTotalsOwn[TAbbrT.FGA] + 0.44 * tempTotalsOwn[TAbbrT.FTA] + tempTotalsOwn[TAbbrT.TOS]);
            tempMetricsOwn.Add("TOR", tor);

            var orebP = tempTotalsOwn[TAbbrT.OREB] / (tempTotalsOwn[TAbbrT.OREB] + tempTotalsOpp[TAbbrT.DREB]);
            tempMetricsOwn.Add("OREB%", orebP);

            var ftr = tempTotalsOwn[TAbbrT.FTM] / tempTotalsOwn[TAbbrT.FGA];
            tempMetricsOwn.Add("FTR", ftr);

            var tempPerGame = (!playoffs) ? PerGame : PlPerGame;

            var pwP = (((tempPerGame[TAbbrPG.PPG] - tempPerGame[TAbbrPG.PAPG]) * 2.7) + ((double) MainWindow.SeasonLength / 2))
                      / MainWindow.SeasonLength;
            tempMetricsOwn.Add("PW%", pwP);

            var tsP = tempTotalsOwn[TAbbrT.PF] / (2 * (tempTotalsOwn[TAbbrT.FGA] + 0.44 * tempTotalsOwn[TAbbrT.FTA]));
            tempMetricsOwn.Add("TS%", tsP);

            var tpr = tempTotalsOwn[TAbbrT.TPA] / tempTotalsOwn[TAbbrT.FGA];
            tempMetricsOwn.Add("3PR", tpr);

            var pythW = MainWindow.SeasonLength * (Math.Pow(tempTotalsOwn[TAbbrT.PF], 16.5))
                        / (Math.Pow(tempTotalsOwn[TAbbrT.PF], 16.5) + Math.Pow(tempTotalsOwn[TAbbrT.PA], 16.5));
            tempMetricsOwn.Add("PythW", pythW);

            var pythL = MainWindow.SeasonLength - pythW;
            tempMetricsOwn.Add("PythL", pythL);

            var gmsc = tempTotalsOwn[TAbbrT.PF] + 0.4 * tempTotalsOwn[TAbbrT.FGM] - 0.7 * tempTotalsOwn[TAbbrT.FGA]
                       - 0.4 * (tempTotalsOwn[TAbbrT.FTA] - tempTotalsOwn[TAbbrT.FTM]) + 0.7 * tempTotalsOwn[TAbbrT.OREB]
                       + 0.3 * tempTotalsOwn[TAbbrT.DREB] + tempTotalsOwn[TAbbrT.STL] + 0.7 * tempTotalsOwn[TAbbrT.AST]
                       + 0.7 * tempTotalsOwn[TAbbrT.BLK] - 0.4 * tempTotalsOwn[TAbbrT.FOUL] - tempTotalsOwn[TAbbrT.TOS];
            tempMetricsOwn.Add("GmSc", gmsc / games);

            if (!playoffs)
            {
                Metrics = new Dictionary<string, double>(tempMetricsOwn);
            }
            else
            {
                PlMetrics = new Dictionary<string, double>(tempMetricsOwn);
            }
        }
        /// <summary>Updates the Overview tab and loads the appropriate box scores depending on the timeframe.</summary>
        private void updateOverviewAndBoxScores()
        {
            var id = _curTeam;

            _curts = _tst[id];
            _curtsopp = _tstOpp[id];

            _tbsList = new List<TeamBoxScore>();

            #region Prepare Team Overview

            _bseList = MainWindow.BSHist.Where(bse => bse.BS.Team1ID == _curTeam || bse.BS.Team2ID == _curTeam).ToList();
            _bseListSea = _bseList.Where(bse => bse.BS.IsPlayoff == false).ToList();
            _bseListPl = _bseList.Where(bse => bse.BS.IsPlayoff).ToList();

            foreach (var r in _bseList)
            {
                var bsr = r.BS.CustomClone();
                bsr.PrepareForDisplay(_tst, _curTeam);
                _tbsList.Add(bsr);
            }

            #region Regular Season

            var dr = _dtOv.NewRow();

            dr["Type"] = "Stats";
            dr["Games"] = _curts.GetGames();
            dr["Wins (W%)"] = _curts.Record[0].ToString();
            dr["Losses (Weff)"] = _curts.Record[1].ToString();
            dr["PF"] = _curts.Totals[TAbbrT.PF].ToString();
            dr["PA"] = _curts.Totals[TAbbrT.PA].ToString();
            dr["PD"] = " ";
            dr["FG"] = _curts.Totals[TAbbrT.FGM].ToString() + "-" + _curts.Totals[TAbbrT.FGA].ToString();
            dr["3PT"] = _curts.Totals[TAbbrT.TPM].ToString() + "-" + _curts.Totals[TAbbrT.TPA].ToString();
            dr["FT"] = _curts.Totals[TAbbrT.FTM].ToString() + "-" + _curts.Totals[TAbbrT.FTA].ToString();
            dr["REB"] = (_curts.Totals[TAbbrT.DREB] + _curts.Totals[TAbbrT.OREB]).ToString();
            dr["OREB"] = _curts.Totals[TAbbrT.OREB].ToString();
            dr["DREB"] = _curts.Totals[TAbbrT.DREB].ToString();
            dr["AST"] = _curts.Totals[TAbbrT.AST].ToString();
            dr["TO"] = _curts.Totals[TAbbrT.TOS].ToString();
            dr["STL"] = _curts.Totals[TAbbrT.STL].ToString();
            dr["BLK"] = _curts.Totals[TAbbrT.BLK].ToString();
            dr["FOUL"] = _curts.Totals[TAbbrT.FOUL].ToString();
            dr["MINS"] = _curts.Totals[TAbbrT.MINS].ToString();

            _dtOv.Rows.Add(dr);

            dr = _dtOv.NewRow();

            _curts.CalcAvg(); // Just to be sure...

            dr["Type"] = "Averages";
            //dr["Games"] = curts.getGames();
            dr["Wins (W%)"] = String.Format("{0:F3}", _curts.PerGame[TAbbrPG.Wp]);
            dr["Losses (Weff)"] = String.Format("{0:F2}", _curts.PerGame[TAbbrPG.Weff]);
            dr["PF"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.PPG]);
            dr["PA"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.PAPG]);
            dr["PD"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.PD]);
            dr["FG"] = String.Format("{0:F3}", _curts.PerGame[TAbbrPG.FGp]);
            dr["FGeff"] = String.Format("{0:F2}", _curts.PerGame[TAbbrPG.FGeff]);
            dr["3PT"] = String.Format("{0:F3}", _curts.PerGame[TAbbrPG.TPp]);
            dr["3Peff"] = String.Format("{0:F2}", _curts.PerGame[TAbbrPG.TPeff]);
            dr["FT"] = String.Format("{0:F3}", _curts.PerGame[TAbbrPG.FTp]);
            dr["FTeff"] = String.Format("{0:F2}", _curts.PerGame[TAbbrPG.FTeff]);
            dr["REB"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.RPG]);
            dr["OREB"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.ORPG]);
            dr["DREB"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.DRPG]);
            dr["AST"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.APG]);
            dr["TO"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.TPG]);
            dr["STL"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.SPG]);
            dr["BLK"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.BPG]);
            dr["FOUL"] = String.Format("{0:F1}", _curts.PerGame[TAbbrPG.FPG]);

            _dtOv.Rows.Add(dr);

            // Rankings can only be shown based on total stats
            // ...for now
            var dr2 = _dtOv.NewRow();

            dr2["Type"] = "Rankings";
            dr2["Wins (W%)"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.Wp];
            dr2["Losses (Weff)"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.Weff];
            dr2["PF"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.PPG];
            dr2["PA"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.PAPG];
            dr2["PD"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.PD];
            dr2["FG"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.FGp];
            dr2["FGeff"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.FGeff];
            dr2["3PT"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.TPp];
            dr2["3Peff"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.TPeff];
            dr2["FT"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.FTp];
            dr2["FTeff"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.FTeff];
            dr2["REB"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.RPG];
            dr2["OREB"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.ORPG];
            dr2["DREB"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.DRPG];
            dr2["AST"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.APG];
            dr2["TO"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.TPG];
            dr2["STL"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.SPG];
            dr2["BLK"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.BPG];
            dr2["FOUL"] = _seasonRankings.RankingsPerGame[id][TAbbrPG.FPG];

            _dtOv.Rows.Add(dr2);

            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Opp Stats";
            dr2["Games"] = _curtsopp.GetGames();
            dr2["Wins (W%)"] = _curtsopp.Record[0].ToString();
            dr2["Losses (Weff)"] = _curtsopp.Record[1].ToString();
            dr2["PF"] = _curtsopp.Totals[TAbbrT.PF].ToString();
            dr2["PA"] = _curtsopp.Totals[TAbbrT.PA].ToString();
            dr2["PD"] = " ";
            dr2["FG"] = _curtsopp.Totals[TAbbrT.FGM].ToString() + "-" + _curtsopp.Totals[TAbbrT.FGA].ToString();
            dr2["3PT"] = _curtsopp.Totals[TAbbrT.TPM].ToString() + "-" + _curtsopp.Totals[TAbbrT.TPA].ToString();
            dr2["FT"] = _curtsopp.Totals[TAbbrT.FTM].ToString() + "-" + _curtsopp.Totals[TAbbrT.FTA].ToString();
            dr2["REB"] = (_curtsopp.Totals[TAbbrT.DREB] + _curtsopp.Totals[TAbbrT.OREB]).ToString();
            dr2["OREB"] = _curtsopp.Totals[TAbbrT.OREB].ToString();
            dr2["DREB"] = _curtsopp.Totals[TAbbrT.DREB].ToString();
            dr2["AST"] = _curtsopp.Totals[TAbbrT.AST].ToString();
            dr2["TO"] = _curtsopp.Totals[TAbbrT.TOS].ToString();
            dr2["STL"] = _curtsopp.Totals[TAbbrT.STL].ToString();
            dr2["BLK"] = _curtsopp.Totals[TAbbrT.BLK].ToString();
            dr2["FOUL"] = _curtsopp.Totals[TAbbrT.FOUL].ToString();
            dr2["MINS"] = _curtsopp.Totals[TAbbrT.MINS].ToString();

            _dtOv.Rows.Add(dr2);

            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Opp Avg";
            dr2["Wins (W%)"] = String.Format("{0:F3}", _curtsopp.PerGame[TAbbrPG.Wp]);
            dr2["Losses (Weff)"] = String.Format("{0:F2}", _curtsopp.PerGame[TAbbrPG.Weff]);
            dr2["PF"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.PPG]);
            dr2["PA"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.PAPG]);
            dr2["PD"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.PD]);
            dr2["FG"] = String.Format("{0:F3}", _curtsopp.PerGame[TAbbrPG.FGp]);
            dr2["FGeff"] = String.Format("{0:F2}", _curtsopp.PerGame[TAbbrPG.FGeff]);
            dr2["3PT"] = String.Format("{0:F3}", _curtsopp.PerGame[TAbbrPG.TPp]);
            dr2["3Peff"] = String.Format("{0:F2}", _curtsopp.PerGame[TAbbrPG.TPeff]);
            dr2["FT"] = String.Format("{0:F3}", _curtsopp.PerGame[TAbbrPG.FTp]);
            dr2["FTeff"] = String.Format("{0:F2}", _curtsopp.PerGame[TAbbrPG.FTeff]);
            dr2["REB"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.RPG]);
            dr2["OREB"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.ORPG]);
            dr2["DREB"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.DRPG]);
            dr2["AST"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.APG]);
            dr2["TO"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.TPG]);
            dr2["STL"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.SPG]);
            dr2["BLK"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.BPG]);
            dr2["FOUL"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbrPG.FPG]);

            _dtOv.Rows.Add(dr2);

            #endregion

            #region Playoffs

            _dtOv.Rows.Add(_dtOv.NewRow());

            dr = _dtOv.NewRow();

            dr["Type"] = "Playoffs";
            dr["Games"] = _curts.GetPlayoffGames();
            dr["Wins (W%)"] = _curts.PlRecord[0].ToString();
            dr["Losses (Weff)"] = _curts.PlRecord[1].ToString();
            dr["PF"] = _curts.PlTotals[TAbbrT.PF].ToString();
            dr["PA"] = _curts.PlTotals[TAbbrT.PA].ToString();
            dr["PD"] = " ";
            dr["FG"] = _curts.PlTotals[TAbbrT.FGM].ToString() + "-" + _curts.PlTotals[TAbbrT.FGA].ToString();
            dr["3PT"] = _curts.PlTotals[TAbbrT.TPM].ToString() + "-" + _curts.PlTotals[TAbbrT.TPA].ToString();
            dr["FT"] = _curts.PlTotals[TAbbrT.FTM].ToString() + "-" + _curts.PlTotals[TAbbrT.FTA].ToString();
            dr["REB"] = (_curts.PlTotals[TAbbrT.DREB] + _curts.PlTotals[TAbbrT.OREB]).ToString();
            dr["OREB"] = _curts.PlTotals[TAbbrT.OREB].ToString();
            dr["DREB"] = _curts.PlTotals[TAbbrT.DREB].ToString();
            dr["AST"] = _curts.PlTotals[TAbbrT.AST].ToString();
            dr["TO"] = _curts.PlTotals[TAbbrT.TOS].ToString();
            dr["STL"] = _curts.PlTotals[TAbbrT.STL].ToString();
            dr["BLK"] = _curts.PlTotals[TAbbrT.BLK].ToString();
            dr["FOUL"] = _curts.PlTotals[TAbbrT.FOUL].ToString();
            dr["MINS"] = _curts.PlTotals[TAbbrT.MINS].ToString();

            _dtOv.Rows.Add(dr);

            dr = _dtOv.NewRow();

            dr["Type"] = "Pl Avg";
            dr["Wins (W%)"] = String.Format("{0:F3}", _curts.PlPerGame[TAbbrPG.Wp]);
            dr["Losses (Weff)"] = String.Format("{0:F2}", _curts.PlPerGame[TAbbrPG.Weff]);
            dr["PF"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.PPG]);
            dr["PA"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.PAPG]);
            dr["PD"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.PD]);
            dr["FG"] = String.Format("{0:F3}", _curts.PlPerGame[TAbbrPG.FGp]);
            dr["FGeff"] = String.Format("{0:F2}", _curts.PlPerGame[TAbbrPG.FGeff]);
            dr["3PT"] = String.Format("{0:F3}", _curts.PlPerGame[TAbbrPG.TPp]);
            dr["3Peff"] = String.Format("{0:F2}", _curts.PlPerGame[TAbbrPG.TPeff]);
            dr["FT"] = String.Format("{0:F3}", _curts.PlPerGame[TAbbrPG.FTp]);
            dr["FTeff"] = String.Format("{0:F2}", _curts.PlPerGame[TAbbrPG.FTeff]);
            dr["REB"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.RPG]);
            dr["OREB"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.ORPG]);
            dr["DREB"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.DRPG]);
            dr["AST"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.APG]);
            dr["TO"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.TPG]);
            dr["STL"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.SPG]);
            dr["BLK"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.BPG]);
            dr["FOUL"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbrPG.FPG]);

            _dtOv.Rows.Add(dr);

            dr2 = _dtOv.NewRow();

            var count = _tst.Count(z => z.Value.GetPlayoffGames() > 0);

            dr2["Type"] = "Pl Rank";
            dr2["Wins (W%)"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.Wp];
            dr2["Losses (Weff)"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.Weff];
            dr2["PF"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.PPG];
            dr2["PA"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.PAPG];
            dr2["PD"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.PD];
            dr2["FG"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.FGp];
            dr2["FGeff"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.FGeff];
            dr2["3PT"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.TPp];
            dr2["3Peff"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.TPeff];
            dr2["FT"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.FTp];
            dr2["FTeff"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.FTeff];
            dr2["REB"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.RPG];
            dr2["OREB"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.ORPG];
            dr2["DREB"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.DRPG];
            dr2["AST"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.APG];
            dr2["TO"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.TPG];
            dr2["STL"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.SPG];
            dr2["BLK"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.BPG];
            dr2["FOUL"] = _playoffRankings.RankingsPerGame[id][TAbbrPG.FPG];

            _dtOv.Rows.Add(dr2);

            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Opp Pl Stats";
            dr2["Games"] = _curtsopp.GetPlayoffGames();
            dr2["Wins (W%)"] = _curtsopp.PlRecord[0].ToString();
            dr2["Losses (Weff)"] = _curtsopp.PlRecord[1].ToString();
            dr2["PF"] = _curtsopp.PlTotals[TAbbrT.PF].ToString();
            dr2["PA"] = _curtsopp.PlTotals[TAbbrT.PA].ToString();
            dr2["PD"] = " ";
            dr2["FG"] = _curtsopp.PlTotals[TAbbrT.FGM].ToString() + "-" + _curtsopp.PlTotals[TAbbrT.FGA].ToString();
            dr2["3PT"] = _curtsopp.PlTotals[TAbbrT.TPM].ToString() + "-" + _curtsopp.PlTotals[TAbbrT.TPA].ToString();
            dr2["FT"] = _curtsopp.PlTotals[TAbbrT.FTM].ToString() + "-" + _curtsopp.PlTotals[TAbbrT.FTA].ToString();
            dr2["REB"] = (_curtsopp.PlTotals[TAbbrT.DREB] + _curtsopp.PlTotals[TAbbrT.OREB]).ToString();
            dr2["OREB"] = _curtsopp.PlTotals[TAbbrT.OREB].ToString();
            dr2["DREB"] = _curtsopp.PlTotals[TAbbrT.DREB].ToString();
            dr2["AST"] = _curtsopp.PlTotals[TAbbrT.AST].ToString();
            dr2["TO"] = _curtsopp.PlTotals[TAbbrT.TOS].ToString();
            dr2["STL"] = _curtsopp.PlTotals[TAbbrT.STL].ToString();
            dr2["BLK"] = _curtsopp.PlTotals[TAbbrT.BLK].ToString();
            dr2["FOUL"] = _curtsopp.PlTotals[TAbbrT.FOUL].ToString();
            dr2["MINS"] = _curtsopp.PlTotals[TAbbrT.MINS].ToString();

            _dtOv.Rows.Add(dr2);

            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Opp Pl Avg";
            dr2["Wins (W%)"] = String.Format("{0:F3}", _curtsopp.PlPerGame[TAbbrPG.Wp]);
            dr2["Losses (Weff)"] = String.Format("{0:F2}", _curtsopp.PlPerGame[TAbbrPG.Weff]);
            dr2["PF"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.PPG]);
            dr2["PA"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.PAPG]);
            dr2["PD"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.PD]);
            dr2["FG"] = String.Format("{0:F3}", _curtsopp.PlPerGame[TAbbrPG.FGp]);
            dr2["FGeff"] = String.Format("{0:F2}", _curtsopp.PlPerGame[TAbbrPG.FGeff]);
            dr2["3PT"] = String.Format("{0:F3}", _curtsopp.PlPerGame[TAbbrPG.TPp]);
            dr2["3Peff"] = String.Format("{0:F2}", _curtsopp.PlPerGame[TAbbrPG.TPeff]);
            dr2["FT"] = String.Format("{0:F3}", _curtsopp.PlPerGame[TAbbrPG.FTp]);
            dr2["FTeff"] = String.Format("{0:F2}", _curtsopp.PlPerGame[TAbbrPG.FTeff]);
            dr2["REB"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.RPG]);
            dr2["OREB"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.ORPG]);
            dr2["DREB"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.DRPG]);
            dr2["AST"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.APG]);
            dr2["TO"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.TPG]);
            dr2["STL"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.SPG]);
            dr2["BLK"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.BPG]);
            dr2["FOUL"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbrPG.FPG]);

            _dtOv.Rows.Add(dr2);

            #endregion

            createViewAndUpdateOverview();

            dgvBoxScores.ItemsSource = _tbsList;

            #endregion

            _curTSR = new TeamStatsRow(_curts);
            dgMetrics.ItemsSource = new List<TeamStatsRow> { _curTSR };

            updatePBPStats();
        }
        private void calculate2KRatings(bool playoffs = false)
        {
            string gpPctSetting = MainWindow.RatingsGPPctSetting;
            double gpPCTreq = MainWindow.RatingsGPPctRequired;
            string mpgSetting = MainWindow.RatingsMPGSetting;
            float MPGreq = MainWindow.RatingsMPGRequired;

            uint pGP = GP;
            var team = new TeamStats();
            uint tGP = 0;
            try
            {
                team = MainWindow.TST.Single(ts => ts.Value.ID == TeamF).Value;
                tGP = playoffs ? team.GetPlayoffGames() : team.GetGames();
            }
            catch (InvalidOperationException)
            {
                gpPctSetting = "-1";
            }

            if ((gpPctSetting != "-1" && (double) (pGP*100)/tGP < gpPCTreq) || (mpgSetting != "-1" && MPG < MPGreq))
            {
                reRFT = -1;
                reRPass = -1;
                reRBlock = -1;
                reRSteal = -1;
                reROffRbd = -1;
                reRDefRbd = -1;
                reTShotTnd = -1;
                reTDrawFoul = -1;
                reTTouch = -1;
                reTCommitFl = -1;
                return;
            }

            try
            {
                reRFT = Convert.ToInt32(100*FTp);
                if (reRFT > 99)
                {
                    reRFT = 99;
                }
            }
            catch
            {
                reRFT = -1;
            }

            try
            {
                double ASTp100 = ASTp*100;
                reRPass = Convert.ToInt32(31.1901795687457 + 1.36501096444891*ASTp100 + 4.34894327991171/(-0.702541953738967 - ASTp100));
                if (reRPass > 99)
                {
                    reRPass = 99;
                }
            }
            catch
            {
                reRPass = -1;
            }

            try
            {
                double BLKp100 = BLKp*100;
                reRBlock =
                    Convert.ToInt32(25.76 + 17.03*BLKp100 + 0.8376*Math.Pow(BLKp100, 3) - 3.195*Math.Pow(BLKp100, 2) -
                                    0.07319*Math.Pow(BLKp100, 4));
                if (reRBlock > 99)
                {
                    reRBlock = 99;
                }
            }
            catch
            {
                reRBlock = -1;
            }

            try
            {
                double STLp100 = STLp*100;
                reRSteal = Convert.ToInt32(29.92 + 14.57*STLp100 - 0.1509*Math.Pow(STLp100, 2));
                if (reRSteal > 99)
                {
                    reRSteal = 99;
                }
            }
            catch
            {
                reRSteal = -1;
            }

            try
            {
                double OREBp100 = OREBp*100;
                reROffRbd =
                    Convert.ToInt32(24.67 + 3.864*OREBp100 + 0.3523*Math.Pow(OREBp100, 2) + 0.0007358*Math.Pow(OREBp100, 4) -
                                    0.02796*Math.Pow(OREBp100, 3));
                if (reROffRbd > 99)
                {
                    reROffRbd = 99;
                }
            }
            catch
            {
                reROffRbd = -1;
            }

            try
            {
                double DREBp100 = DREBp*100;
                reRDefRbd = Convert.ToInt32(25 + 2.5*DREBp100);
                if (reRDefRbd > 99)
                {
                    reRDefRbd = 99;
                }
            }
            catch
            {
                reRDefRbd = -1;
            }

            try
            {
                reTShotTnd = Convert.ToInt32(2 + 4*FGAPG);
                if (reTShotTnd > 90)
                {
                    reTShotTnd = 90;
                }
            }
            catch
            {
                reTShotTnd = -1;
            }

            try
            {
                reTDrawFoul = Convert.ToInt32(FTAR*10);
                if (reTDrawFoul > 99)
                {
                    reTDrawFoul = 99;
                }
            }
            catch
            {
                reTDrawFoul = -1;
            }

            try
            {
                double FGAR = (double) FGA/MINS*36;
                int touchTotal = Convert.ToInt32(FGAR + FTAR + TOR + ASTR);
                reTTouch = Convert.ToInt32(3.141*Math.Pow(touchTotal, 2)/(1.178 + touchTotal));
                if (reTTouch > 99)
                {
                    reTTouch = 99;
                }
            }
            catch
            {
                reTTouch = -1;
            }

            try
            {
                reTCommitFl = Convert.ToInt32((double) FOUL/MINS*36*10);
                if (reTCommitFl > 99)
                {
                    reTCommitFl = 99;
                }
            }
            catch
            {
                reTCommitFl = -1;
            }
        }
 /// <summary>Creates a data row from a TeamStats instance.</summary>
 /// <param name="ts">The TeamStats instance.</param>
 /// <param name="dr">The data row to be edited.</param>
 /// <param name="title">The title for the row's Type or Name column.</param>
 /// <param name="playoffs">
 ///     if set to <c>true</c>, the row will present the team's playoff stats; otherwise, the regular season's.
 /// </param>
 private static void createDataRowFromTeamStats(TeamStats ts, ref DataRow dr, string title, bool playoffs = false)
 {
     try
     {
         dr["Type"] = title;
     }
     catch
     {
         dr["Name"] = title;
     }
     float[] PerGame;
     if (!playoffs)
     {
         PerGame = ts.PerGame;
         dr["Games"] = ts.GetGames();
         dr["Wins"] = ts.Record[0].ToString();
         dr["Losses"] = ts.Record[1].ToString();
     }
     else
     {
         PerGame = ts.PlPerGame;
         dr["Games"] = ts.GetPlayoffGames();
         dr["Wins"] = ts.PlRecord[0].ToString();
         dr["Losses"] = ts.PlRecord[1].ToString();
     }
     dr["W%"] = String.Format("{0:F3}", PerGame[TAbbrPG.Wp]);
     dr["Weff"] = String.Format("{0:F2}", PerGame[TAbbrPG.Weff]);
     dr["PF"] = String.Format("{0:F1}", PerGame[TAbbrPG.PPG]);
     dr["PA"] = String.Format("{0:F1}", PerGame[TAbbrPG.PAPG]);
     dr["PD"] = String.Format("{0:F1}", PerGame[TAbbrPG.PD]);
     dr["FG"] = String.Format("{0:F3}", PerGame[TAbbrPG.FGp]);
     dr["FGeff"] = String.Format("{0:F2}", PerGame[TAbbrPG.FGeff]);
     dr["3PT"] = String.Format("{0:F3}", PerGame[TAbbrPG.TPp]);
     dr["3Peff"] = String.Format("{0:F2}", PerGame[TAbbrPG.TPeff]);
     dr["FT"] = String.Format("{0:F3}", PerGame[TAbbrPG.FTp]);
     dr["FTeff"] = String.Format("{0:F2}", PerGame[TAbbrPG.FTeff]);
     dr["REB"] = String.Format("{0:F1}", PerGame[TAbbrPG.RPG]);
     dr["OREB"] = String.Format("{0:F1}", PerGame[TAbbrPG.ORPG]);
     dr["DREB"] = String.Format("{0:F1}", PerGame[TAbbrPG.DRPG]);
     dr["AST"] = String.Format("{0:F1}", PerGame[TAbbrPG.APG]);
     dr["TO"] = String.Format("{0:F1}", PerGame[TAbbrPG.TPG]);
     dr["STL"] = String.Format("{0:F1}", PerGame[TAbbrPG.SPG]);
     dr["BLK"] = String.Format("{0:F1}", PerGame[TAbbrPG.BPG]);
     dr["FOUL"] = String.Format("{0:F1}", PerGame[TAbbrPG.FPG]);
     dr["MINS"] = String.Format("{0:F1}", PerGame[TAbbrPG.MPG]);
 }
        /// <summary>
        ///     Updates the Overview tab and loads the appropriate box scores depending on the timeframe.
        /// </summary>
        private void updateOverviewAndBoxScores()
        {
            int id = _curTeam;

            _curts = _tst[id];
            _curtsopp = _tstOpp[id];

            _bsrList = new List<TeamBoxScore>();

            #region Prepare Team Overview

            IEnumerable<BoxScoreEntry> boxScoreEntries =
                MainWindow.BSHist.Where(bse => bse.BS.Team1ID == _curTeam || bse.BS.Team2ID == _curTeam);

            foreach (BoxScoreEntry r in boxScoreEntries)
            {
                TeamBoxScore bsr = r.BS.DeepClone();
                bsr.PrepareForDisplay(_tst, _curTeam);
                _bsrList.Add(bsr);
            }

            #region Regular Season

            DataRow dr = _dtOv.NewRow();

            dr["Type"] = "Stats";
            dr["Games"] = _curts.GetGames();
            dr["Wins (W%)"] = _curts.Record[0].ToString();
            dr["Losses (Weff)"] = _curts.Record[1].ToString();
            dr["PF"] = _curts.Totals[TAbbr.PF].ToString();
            dr["PA"] = _curts.Totals[TAbbr.PA].ToString();
            dr["PD"] = " ";
            dr["FG"] = _curts.Totals[TAbbr.FGM].ToString() + "-" + _curts.Totals[TAbbr.FGA].ToString();
            dr["3PT"] = _curts.Totals[TAbbr.TPM].ToString() + "-" + _curts.Totals[TAbbr.TPA].ToString();
            dr["FT"] = _curts.Totals[TAbbr.FTM].ToString() + "-" + _curts.Totals[TAbbr.FTA].ToString();
            dr["REB"] = (_curts.Totals[TAbbr.DREB] + _curts.Totals[TAbbr.OREB]).ToString();
            dr["OREB"] = _curts.Totals[TAbbr.OREB].ToString();
            dr["DREB"] = _curts.Totals[TAbbr.DREB].ToString();
            dr["AST"] = _curts.Totals[TAbbr.AST].ToString();
            dr["TO"] = _curts.Totals[TAbbr.TOS].ToString();
            dr["STL"] = _curts.Totals[TAbbr.STL].ToString();
            dr["BLK"] = _curts.Totals[TAbbr.BLK].ToString();
            dr["FOUL"] = _curts.Totals[TAbbr.FOUL].ToString();
            dr["MINS"] = _curts.Totals[TAbbr.MINS].ToString();

            _dtOv.Rows.Add(dr);

            dr = _dtOv.NewRow();

            _curts.CalcAvg(); // Just to be sure...

            dr["Type"] = "Averages";
            //dr["Games"] = curts.getGames();
            dr["Wins (W%)"] = String.Format("{0:F3}", _curts.PerGame[TAbbr.Wp]);
            dr["Losses (Weff)"] = String.Format("{0:F2}", _curts.PerGame[TAbbr.Weff]);
            dr["PF"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.PPG]);
            dr["PA"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.PAPG]);
            dr["PD"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.PD]);
            dr["FG"] = String.Format("{0:F3}", _curts.PerGame[TAbbr.FGp]);
            dr["FGeff"] = String.Format("{0:F2}", _curts.PerGame[TAbbr.FGeff]);
            dr["3PT"] = String.Format("{0:F3}", _curts.PerGame[TAbbr.TPp]);
            dr["3Peff"] = String.Format("{0:F2}", _curts.PerGame[TAbbr.TPeff]);
            dr["FT"] = String.Format("{0:F3}", _curts.PerGame[TAbbr.FTp]);
            dr["FTeff"] = String.Format("{0:F2}", _curts.PerGame[TAbbr.FTeff]);
            dr["REB"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.RPG]);
            dr["OREB"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.ORPG]);
            dr["DREB"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.DRPG]);
            dr["AST"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.APG]);
            dr["TO"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.TPG]);
            dr["STL"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.SPG]);
            dr["BLK"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.BPG]);
            dr["FOUL"] = String.Format("{0:F1}", _curts.PerGame[TAbbr.FPG]);

            _dtOv.Rows.Add(dr);

            // Rankings can only be shown based on total stats
            // ...for now
            DataRow dr2;
            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Rankings";
            dr2["Wins (W%)"] = _seasonRankings.RankingsPerGame[id][TAbbr.Wp];
            dr2["Losses (Weff)"] = _seasonRankings.RankingsPerGame[id][TAbbr.Weff];
            dr2["PF"] = _seasonRankings.RankingsPerGame[id][TAbbr.PPG];
            dr2["PA"] = cmbTeam.Items.Count + 1 - _seasonRankings.RankingsPerGame[id][TAbbr.PAPG];
            dr2["PD"] = _seasonRankings.RankingsPerGame[id][TAbbr.PD];
            dr2["FG"] = _seasonRankings.RankingsPerGame[id][TAbbr.FGp];
            dr2["FGeff"] = _seasonRankings.RankingsPerGame[id][TAbbr.FGeff];
            dr2["3PT"] = _seasonRankings.RankingsPerGame[id][TAbbr.TPp];
            dr2["3Peff"] = _seasonRankings.RankingsPerGame[id][TAbbr.TPeff];
            dr2["FT"] = _seasonRankings.RankingsPerGame[id][TAbbr.FTp];
            dr2["FTeff"] = _seasonRankings.RankingsPerGame[id][TAbbr.FTeff];
            dr2["REB"] = _seasonRankings.RankingsPerGame[id][TAbbr.RPG];
            dr2["OREB"] = _seasonRankings.RankingsPerGame[id][TAbbr.ORPG];
            dr2["DREB"] = _seasonRankings.RankingsPerGame[id][TAbbr.DRPG];
            dr2["AST"] = _seasonRankings.RankingsPerGame[id][TAbbr.APG];
            dr2["TO"] = cmbTeam.Items.Count + 1 - _seasonRankings.RankingsPerGame[id][TAbbr.TPG];
            dr2["STL"] = _seasonRankings.RankingsPerGame[id][TAbbr.SPG];
            dr2["BLK"] = _seasonRankings.RankingsPerGame[id][TAbbr.BPG];
            dr2["FOUL"] = cmbTeam.Items.Count + 1 - _seasonRankings.RankingsPerGame[id][TAbbr.FPG];

            _dtOv.Rows.Add(dr2);

            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Opp Stats";
            dr2["Games"] = _curtsopp.GetGames();
            dr2["Wins (W%)"] = _curtsopp.Record[0].ToString();
            dr2["Losses (Weff)"] = _curtsopp.Record[1].ToString();
            dr2["PF"] = _curtsopp.Totals[TAbbr.PF].ToString();
            dr2["PA"] = _curtsopp.Totals[TAbbr.PA].ToString();
            dr2["PD"] = " ";
            dr2["FG"] = _curtsopp.Totals[TAbbr.FGM].ToString() + "-" + _curtsopp.Totals[TAbbr.FGA].ToString();
            dr2["3PT"] = _curtsopp.Totals[TAbbr.TPM].ToString() + "-" + _curtsopp.Totals[TAbbr.TPA].ToString();
            dr2["FT"] = _curtsopp.Totals[TAbbr.FTM].ToString() + "-" + _curtsopp.Totals[TAbbr.FTA].ToString();
            dr2["REB"] = (_curtsopp.Totals[TAbbr.DREB] + _curtsopp.Totals[TAbbr.OREB]).ToString();
            dr2["OREB"] = _curtsopp.Totals[TAbbr.OREB].ToString();
            dr2["DREB"] = _curtsopp.Totals[TAbbr.DREB].ToString();
            dr2["AST"] = _curtsopp.Totals[TAbbr.AST].ToString();
            dr2["TO"] = _curtsopp.Totals[TAbbr.TOS].ToString();
            dr2["STL"] = _curtsopp.Totals[TAbbr.STL].ToString();
            dr2["BLK"] = _curtsopp.Totals[TAbbr.BLK].ToString();
            dr2["FOUL"] = _curtsopp.Totals[TAbbr.FOUL].ToString();
            dr2["MINS"] = _curtsopp.Totals[TAbbr.MINS].ToString();

            _dtOv.Rows.Add(dr2);

            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Opp Avg";
            dr2["Wins (W%)"] = String.Format("{0:F3}", _curtsopp.PerGame[TAbbr.Wp]);
            dr2["Losses (Weff)"] = String.Format("{0:F2}", _curtsopp.PerGame[TAbbr.Weff]);
            dr2["PF"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.PPG]);
            dr2["PA"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.PAPG]);
            dr2["PD"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.PD]);
            dr2["FG"] = String.Format("{0:F3}", _curtsopp.PerGame[TAbbr.FGp]);
            dr2["FGeff"] = String.Format("{0:F2}", _curtsopp.PerGame[TAbbr.FGeff]);
            dr2["3PT"] = String.Format("{0:F3}", _curtsopp.PerGame[TAbbr.TPp]);
            dr2["3Peff"] = String.Format("{0:F2}", _curtsopp.PerGame[TAbbr.TPeff]);
            dr2["FT"] = String.Format("{0:F3}", _curtsopp.PerGame[TAbbr.FTp]);
            dr2["FTeff"] = String.Format("{0:F2}", _curtsopp.PerGame[TAbbr.FTeff]);
            dr2["REB"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.RPG]);
            dr2["OREB"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.ORPG]);
            dr2["DREB"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.DRPG]);
            dr2["AST"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.APG]);
            dr2["TO"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.TPG]);
            dr2["STL"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.SPG]);
            dr2["BLK"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.BPG]);
            dr2["FOUL"] = String.Format("{0:F1}", _curtsopp.PerGame[TAbbr.FPG]);

            _dtOv.Rows.Add(dr2);

            #endregion

            #region Playoffs

            _dtOv.Rows.Add(_dtOv.NewRow());

            dr = _dtOv.NewRow();

            dr["Type"] = "Playoffs";
            dr["Games"] = _curts.GetPlayoffGames();
            dr["Wins (W%)"] = _curts.PlRecord[0].ToString();
            dr["Losses (Weff)"] = _curts.PlRecord[1].ToString();
            dr["PF"] = _curts.PlTotals[TAbbr.PF].ToString();
            dr["PA"] = _curts.PlTotals[TAbbr.PA].ToString();
            dr["PD"] = " ";
            dr["FG"] = _curts.PlTotals[TAbbr.FGM].ToString() + "-" + _curts.PlTotals[TAbbr.FGA].ToString();
            dr["3PT"] = _curts.PlTotals[TAbbr.TPM].ToString() + "-" + _curts.PlTotals[TAbbr.TPA].ToString();
            dr["FT"] = _curts.PlTotals[TAbbr.FTM].ToString() + "-" + _curts.PlTotals[TAbbr.FTA].ToString();
            dr["REB"] = (_curts.PlTotals[TAbbr.DREB] + _curts.PlTotals[TAbbr.OREB]).ToString();
            dr["OREB"] = _curts.PlTotals[TAbbr.OREB].ToString();
            dr["DREB"] = _curts.PlTotals[TAbbr.DREB].ToString();
            dr["AST"] = _curts.PlTotals[TAbbr.AST].ToString();
            dr["TO"] = _curts.PlTotals[TAbbr.TOS].ToString();
            dr["STL"] = _curts.PlTotals[TAbbr.STL].ToString();
            dr["BLK"] = _curts.PlTotals[TAbbr.BLK].ToString();
            dr["FOUL"] = _curts.PlTotals[TAbbr.FOUL].ToString();
            dr["MINS"] = _curts.PlTotals[TAbbr.MINS].ToString();

            _dtOv.Rows.Add(dr);

            dr = _dtOv.NewRow();

            dr["Type"] = "Pl Avg";
            dr["Wins (W%)"] = String.Format("{0:F3}", _curts.PlPerGame[TAbbr.Wp]);
            dr["Losses (Weff)"] = String.Format("{0:F2}", _curts.PlPerGame[TAbbr.Weff]);
            dr["PF"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.PPG]);
            dr["PA"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.PAPG]);
            dr["PD"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.PD]);
            dr["FG"] = String.Format("{0:F3}", _curts.PlPerGame[TAbbr.FGp]);
            dr["FGeff"] = String.Format("{0:F2}", _curts.PlPerGame[TAbbr.FGeff]);
            dr["3PT"] = String.Format("{0:F3}", _curts.PlPerGame[TAbbr.TPp]);
            dr["3Peff"] = String.Format("{0:F2}", _curts.PlPerGame[TAbbr.TPeff]);
            dr["FT"] = String.Format("{0:F3}", _curts.PlPerGame[TAbbr.FTp]);
            dr["FTeff"] = String.Format("{0:F2}", _curts.PlPerGame[TAbbr.FTeff]);
            dr["REB"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.RPG]);
            dr["OREB"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.ORPG]);
            dr["DREB"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.DRPG]);
            dr["AST"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.APG]);
            dr["TO"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.TPG]);
            dr["STL"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.SPG]);
            dr["BLK"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.BPG]);
            dr["FOUL"] = String.Format("{0:F1}", _curts.PlPerGame[TAbbr.FPG]);

            _dtOv.Rows.Add(dr);

            dr2 = _dtOv.NewRow();

            int count = _tst.Count(z => z.Value.GetPlayoffGames() > 0);

            dr2["Type"] = "Pl Rank";
            dr2["Wins (W%)"] = _playoffRankings.RankingsPerGame[id][TAbbr.Wp];
            dr2["Losses (Weff)"] = _playoffRankings.RankingsPerGame[id][TAbbr.Weff];
            dr2["PF"] = _playoffRankings.RankingsPerGame[id][TAbbr.PPG];
            dr2["PA"] = count + 1 - _playoffRankings.RankingsPerGame[id][TAbbr.PAPG];
            dr2["PD"] = _playoffRankings.RankingsPerGame[id][TAbbr.PD];
            dr2["FG"] = _playoffRankings.RankingsPerGame[id][TAbbr.FGp];
            dr2["FGeff"] = _playoffRankings.RankingsPerGame[id][TAbbr.FGeff];
            dr2["3PT"] = _playoffRankings.RankingsPerGame[id][TAbbr.TPp];
            dr2["3Peff"] = _playoffRankings.RankingsPerGame[id][TAbbr.TPeff];
            dr2["FT"] = _playoffRankings.RankingsPerGame[id][TAbbr.FTp];
            dr2["FTeff"] = _playoffRankings.RankingsPerGame[id][TAbbr.FTeff];
            dr2["REB"] = _playoffRankings.RankingsPerGame[id][TAbbr.RPG];
            dr2["OREB"] = _playoffRankings.RankingsPerGame[id][TAbbr.ORPG];
            dr2["DREB"] = _playoffRankings.RankingsPerGame[id][TAbbr.DRPG];
            dr2["AST"] = _playoffRankings.RankingsPerGame[id][TAbbr.APG];
            dr2["TO"] = count + 1 - _playoffRankings.RankingsPerGame[id][TAbbr.TPG];
            dr2["STL"] = _playoffRankings.RankingsPerGame[id][TAbbr.SPG];
            dr2["BLK"] = _playoffRankings.RankingsPerGame[id][TAbbr.BPG];
            dr2["FOUL"] = count + 1 - _playoffRankings.RankingsPerGame[id][TAbbr.FPG];

            _dtOv.Rows.Add(dr2);

            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Opp Pl Stats";
            dr2["Games"] = _curtsopp.GetPlayoffGames();
            dr2["Wins (W%)"] = _curtsopp.PlRecord[0].ToString();
            dr2["Losses (Weff)"] = _curtsopp.PlRecord[1].ToString();
            dr2["PF"] = _curtsopp.PlTotals[TAbbr.PF].ToString();
            dr2["PA"] = _curtsopp.PlTotals[TAbbr.PA].ToString();
            dr2["PD"] = " ";
            dr2["FG"] = _curtsopp.PlTotals[TAbbr.FGM].ToString() + "-" + _curtsopp.PlTotals[TAbbr.FGA].ToString();
            dr2["3PT"] = _curtsopp.PlTotals[TAbbr.TPM].ToString() + "-" + _curtsopp.PlTotals[TAbbr.TPA].ToString();
            dr2["FT"] = _curtsopp.PlTotals[TAbbr.FTM].ToString() + "-" + _curtsopp.PlTotals[TAbbr.FTA].ToString();
            dr2["REB"] = (_curtsopp.PlTotals[TAbbr.DREB] + _curtsopp.PlTotals[TAbbr.OREB]).ToString();
            dr2["OREB"] = _curtsopp.PlTotals[TAbbr.OREB].ToString();
            dr2["DREB"] = _curtsopp.PlTotals[TAbbr.DREB].ToString();
            dr2["AST"] = _curtsopp.PlTotals[TAbbr.AST].ToString();
            dr2["TO"] = _curtsopp.PlTotals[TAbbr.TOS].ToString();
            dr2["STL"] = _curtsopp.PlTotals[TAbbr.STL].ToString();
            dr2["BLK"] = _curtsopp.PlTotals[TAbbr.BLK].ToString();
            dr2["FOUL"] = _curtsopp.PlTotals[TAbbr.FOUL].ToString();
            dr2["MINS"] = _curtsopp.PlTotals[TAbbr.MINS].ToString();

            _dtOv.Rows.Add(dr2);

            dr2 = _dtOv.NewRow();

            dr2["Type"] = "Opp Pl Avg";
            dr2["Wins (W%)"] = String.Format("{0:F3}", _curtsopp.PlPerGame[TAbbr.Wp]);
            dr2["Losses (Weff)"] = String.Format("{0:F2}", _curtsopp.PlPerGame[TAbbr.Weff]);
            dr2["PF"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.PPG]);
            dr2["PA"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.PAPG]);
            dr2["PD"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.PD]);
            dr2["FG"] = String.Format("{0:F3}", _curtsopp.PlPerGame[TAbbr.FGp]);
            dr2["FGeff"] = String.Format("{0:F2}", _curtsopp.PlPerGame[TAbbr.FGeff]);
            dr2["3PT"] = String.Format("{0:F3}", _curtsopp.PlPerGame[TAbbr.TPp]);
            dr2["3Peff"] = String.Format("{0:F2}", _curtsopp.PlPerGame[TAbbr.TPeff]);
            dr2["FT"] = String.Format("{0:F3}", _curtsopp.PlPerGame[TAbbr.FTp]);
            dr2["FTeff"] = String.Format("{0:F2}", _curtsopp.PlPerGame[TAbbr.FTeff]);
            dr2["REB"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.RPG]);
            dr2["OREB"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.ORPG]);
            dr2["DREB"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.DRPG]);
            dr2["AST"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.APG]);
            dr2["TO"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.TPG]);
            dr2["STL"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.SPG]);
            dr2["BLK"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.BPG]);
            dr2["FOUL"] = String.Format("{0:F1}", _curtsopp.PlPerGame[TAbbr.FPG]);

            _dtOv.Rows.Add(dr2);

            #endregion

            createViewAndUpdateOverview();

            dgvBoxScores.ItemsSource = _bsrList;

            #endregion
        }
예제 #6
0
        /// <summary>Calculates the Metric Stats for this Player</summary>
        /// <param name="ts">The player's team's stats</param>
        /// <param name="tsopp">The player's team's opponents' stats</param>
        /// <param name="ls">The total league stats</param>
        /// <param name="leagueOv">Whether CalcMetrics is being called from the League Overview screen</param>
        /// <param name="GmScOnly">Whether to only calculate the GmSc metric.</param>
        /// <param name="playoffs">Whether to calculate the metrics based on the playoffs stats.</param>
        public void CalcMetrics(
            TeamStats ts, TeamStats tsopp, TeamStats ls, bool leagueOv = false, bool GmScOnly = false, bool playoffs = false)
        {
            var pstats = new double[Totals.Length];
            for (var i = 0; i < Totals.Length; i++)
            {
                if (!playoffs)
                {
                    pstats[i] = Totals[i];
                }
                else
                {
                    pstats[i] = PlTotals[i];
                }
            }

            var tstats = new double[ts.Totals.Length];
            for (var i = 0; i < ts.Totals.Length; i++)
            {
                if (!playoffs)
                {
                    tstats[i] = ts.Totals[i];
                }
                else
                {
                    tstats[i] = ts.PlTotals[i];
                }
            }

            var toppstats = new double[tsopp.Totals.Length];
            for (var i = 0; i < tsopp.Totals.Length; i++)
            {
                if (!playoffs)
                {
                    toppstats[i] = tsopp.Totals[i];
                }
                else
                {
                    toppstats[i] = tsopp.PlTotals[i];
                }
            }

            var lstats = new double[ls.Totals.Length];
            for (var i = 0; i < ls.Totals.Length; i++)
            {
                if (!playoffs)
                {
                    lstats[i] = ls.Totals[i];
                }
                else
                {
                    lstats[i] = ls.PlTotals[i];
                }
            }

            var pREB = pstats[PAbbrT.OREB] + pstats[PAbbrT.DREB];
            var tREB = tstats[TAbbrT.OREB] + tstats[TAbbrT.DREB];

            var tempTeamMetricsOwn = !playoffs ? ts.Metrics : ts.PlMetrics;

            var tempMetrics = new Dictionary<string, double>(PlayerStatsHelper.MetricsDict);

            var gmSc = pstats[PAbbrT.PTS] + 0.4 * pstats[PAbbrT.FGM] - 0.7 * pstats[PAbbrT.FGA]
                       - 0.4 * (pstats[PAbbrT.FTA] - pstats[PAbbrT.FTM]) + 0.7 * pstats[PAbbrT.OREB] + 0.3 * pstats[PAbbrT.DREB]
                       + pstats[PAbbrT.STL] + 0.7 * pstats[PAbbrT.AST] + 0.7 * pstats[PAbbrT.BLK] - 0.4 * pstats[PAbbrT.FOUL]
                       - pstats[PAbbrT.TOS];
            tempMetrics["GmSc"] = gmSc / pstats[PAbbrT.GP];

            var gmScE = 36 * (1 / pstats[PAbbrT.MINS]) * gmSc;
            tempMetrics["GmScE"] = gmScE;

            if (!GmScOnly)
            {
                #region Metrics that do not require Opponent Stats

                var ASTp = pstats[PAbbrT.AST]
                           / (((pstats[PAbbrT.MINS] / (tstats[TAbbrT.MINS])) * tstats[TAbbrT.FGM]) - pstats[PAbbrT.FGM]);
                tempMetrics["AST%"] = ASTp;

                var EFGp = (pstats[PAbbrT.FGM] + 0.5 * pstats[PAbbrT.TPM]) / pstats[PAbbrT.FGA];
                tempMetrics["EFG%"] = EFGp;

                var tempTeamMetricsOpp = !playoffs ? tsopp.Metrics : tsopp.PlMetrics;

                var STLp = (pstats[PAbbrT.STL] * (tstats[TAbbrT.MINS])) / (pstats[PAbbrT.MINS] * tempTeamMetricsOpp["Poss"]);
                tempMetrics["STL%"] = STLp;

                var TOp = pstats[PAbbrT.TOS] / (pstats[PAbbrT.FGA] + 0.44 * pstats[PAbbrT.FTA] + pstats[PAbbrT.TOS]);
                tempMetrics["TO%"] = TOp;

                var TSp = pstats[PAbbrT.PTS] / (2 * (pstats[PAbbrT.FGA] + 0.44 * pstats[PAbbrT.FTA]));
                tempMetrics["TS%"] = TSp;

                var USGp = ((pstats[PAbbrT.FGA] + 0.44 * pstats[PAbbrT.FTA] + pstats[PAbbrT.TOS]) * (tstats[TAbbrT.MINS]))
                           / (pstats[PAbbrT.MINS] * (tstats[TAbbrT.FGA] + 0.44 * tstats[TAbbrT.FTA] + tstats[TAbbrT.TOS]));
                tempMetrics["USG%"] = USGp;

                calculateRates(pstats, ref tempMetrics);
                // PER preparations
                var lREB = lstats[TAbbrT.OREB] + lstats[TAbbrT.DREB];
                var factor = (2 / 3)
                             - (0.5 * (lstats[TAbbrT.AST] / lstats[TAbbrT.FGM])) / (2 * (lstats[TAbbrT.FGM] / lstats[TAbbrT.FTM]));
                var VOP = lstats[TAbbrT.PF]
                          / (lstats[TAbbrT.FGA] - lstats[TAbbrT.OREB] + lstats[TAbbrT.TOS] + 0.44 * lstats[TAbbrT.FTA]);
                var lDRBp = lstats[TAbbrT.DREB] / lREB;

                var uPER = (1 / pstats[PAbbrT.MINS])
                           * (pstats[PAbbrT.TPM] + (2 / 3) * pstats[PAbbrT.AST]
                              + (2 - factor * (tstats[TAbbrT.AST] / tstats[TAbbrT.FGM])) * pstats[PAbbrT.FGM]
                              + (pstats[PAbbrT.FTM] * 0.5
                                 * (1 + (1 - (tstats[TAbbrT.AST] / tstats[TAbbrT.FGM]))
                                    + (2 / 3) * (tstats[TAbbrT.AST] / tstats[TAbbrT.FGM]))) - VOP * pstats[PAbbrT.TOS]
                              - VOP * lDRBp * (pstats[PAbbrT.FGA] - pstats[PAbbrT.FGM])
                              - VOP * 0.44 * (0.44 + (0.56 * lDRBp)) * (pstats[PAbbrT.FTA] - pstats[PAbbrT.FTM])
                              + VOP * (1 - lDRBp) * (pREB - pstats[PAbbrT.OREB]) + VOP * lDRBp * pstats[PAbbrT.OREB]
                              + VOP * pstats[PAbbrT.STL] + VOP * lDRBp * pstats[PAbbrT.BLK]
                              - pstats[PAbbrT.FOUL]
                              * ((lstats[TAbbrT.FTM] / lstats[TAbbrT.FOUL]) - 0.44 * (lstats[TAbbrT.FTA] / lstats[TAbbrT.FOUL]) * VOP));
                tempMetrics["EFF"] = uPER * 100;

                #endregion

                #region Metrics that require Opponents stats

                if (ts.GetGames() == tsopp.GetGames())
                {
                    var BLKp = (pstats[PAbbrT.BLK] * (tstats[TAbbrT.MINS]))
                               / (pstats[PAbbrT.MINS] * (toppstats[TAbbrT.FGA] - toppstats[TAbbrT.TPA]));

                    var DRBp = (pstats[PAbbrT.DREB] * (tstats[TAbbrT.MINS]))
                               / (pstats[PAbbrT.MINS] * (tstats[TAbbrT.DREB] + toppstats[TAbbrT.OREB]));

                    var ORBp = (pstats[PAbbrT.OREB] * (tstats[TAbbrT.MINS]))
                               / (pstats[PAbbrT.MINS] * (tstats[TAbbrT.OREB] + toppstats[TAbbrT.DREB]));

                    var toppREB = toppstats[TAbbrT.OREB] + toppstats[TAbbrT.DREB];

                    var REBp = (pREB * (tstats[TAbbrT.MINS])) / (pstats[PAbbrT.MINS] * (tREB + toppREB));

                    #region Metrics that require league stats

                    double aPER;
                    double PPR;

                    if (ls.Name != "$$Empty")
                    {
                        //double paceAdj = ls.temp_metrics["Pace"]/ts.temp_metrics["Pace"];
                        double estPaceAdj;
                        if (!playoffs)
                        {
                            estPaceAdj = 2 * ls.PerGame[TAbbrPG.PPG] / (ts.PerGame[TAbbrPG.PPG] + tsopp.PerGame[TAbbrPG.PPG]);
                        }
                        else
                        {
                            estPaceAdj = 2 * ls.PlPerGame[TAbbrPG.PPG] / (ts.PlPerGame[TAbbrPG.PPG] + tsopp.PlPerGame[TAbbrPG.PPG]);
                        }

                        aPER = estPaceAdj * uPER;

                        PPR = 100 * estPaceAdj * (((pstats[PAbbrT.AST] * 2 / 3) - pstats[PAbbrT.TOS]) / pstats[PAbbrT.MINS]);
                    }
                    else
                    {
                        aPER = Double.NaN;
                        PPR = Double.NaN;
                    }

                    #endregion

                    tempMetrics["aPER"] = aPER;
                    tempMetrics["BLK%"] = BLKp;
                    tempMetrics["DREB%"] = DRBp;
                    tempMetrics["OREB%"] = ORBp;
                    tempMetrics["REB%"] = REBp;
                    tempMetrics["PPR"] = PPR;

                    #region Offensive Rating

                    var qAST = ((pstats[PAbbrT.MINS] / (tstats[TAbbrT.MINS] / 5))
                                * (1.14 * ((tstats[TAbbrT.AST] - pstats[PAbbrT.AST]) / tstats[TAbbrT.FGM])))
                               + ((((tstats[TAbbrT.AST] / tstats[TAbbrT.MINS]) * pstats[PAbbrT.MINS] * 5 - pstats[PAbbrT.AST])
                                   / ((tstats[TAbbrT.FGM] / tstats[TAbbrT.MINS]) * pstats[PAbbrT.MINS] * 5 - pstats[PAbbrT.FGM]))
                                  * (1 - (pstats[PAbbrT.MINS] / (tstats[TAbbrT.MINS] / 5))));

                    var fgPart = pstats[PAbbrT.FGM]
                                 * (1 - 0.5 * ((pstats[PAbbrT.PTS] - pstats[PAbbrT.FTM]) / (2 * pstats[PAbbrT.FGA])) * qAST);

                    var astPart = 0.5
                                  * (((tstats[TAbbrT.PF] - tstats[TAbbrT.FTM]) - (pstats[PAbbrT.PTS] - pstats[PAbbrT.FTM]))
                                     / (2 * (tstats[TAbbrT.FGA] - pstats[PAbbrT.FGA]))) * pstats[PAbbrT.AST];

                    var pFTp = pstats[PAbbrT.FTM] / pstats[PAbbrT.FTA];

                    if (double.IsNaN(pFTp))
                    {
                        pFTp = 0;
                    }

                    var ftPart = (1 - Math.Pow(1 - pFTp, 2)) * 0.4 * pstats[PAbbrT.FTA];

                    var tFTp = tstats[TAbbrT.FTM] / tstats[TAbbrT.FTA];

                    if (double.IsNaN(tFTp))
                    {
                        tFTp = 0;
                    }

                    var teamScPoss = tstats[TAbbrT.FGM] + (1 - Math.Pow(1 - tFTp, 2)) * tstats[TAbbrT.FTA] * 0.4;

                    var teamOREBPct = tstats[TAbbrT.OREB] / (tstats[TAbbrT.OREB] + toppstats[TAbbrT.DREB]);

                    var teamPlayPct = teamScPoss / (tstats[TAbbrT.FGA] + tstats[TAbbrT.FTA] * 0.4 + tstats[TAbbrT.TOS]);

                    var teamOREBWeight = ((1 - teamOREBPct) * teamPlayPct)
                                         / ((1 - teamOREBPct) * teamPlayPct + teamOREBPct * (1 - teamPlayPct));

                    var orebPart = pstats[PAbbrT.OREB] * teamOREBWeight * teamPlayPct;

                    var scPoss = (fgPart + astPart + ftPart) * (1 - (tstats[TAbbrT.OREB] / teamScPoss) * teamOREBWeight * teamPlayPct)
                                 + orebPart;

                    var fgxPoss = (pstats[PAbbrT.FGA] - pstats[PAbbrT.FGM]) * (1 - 1.07 * teamOREBPct);

                    var ftxPoss = Math.Pow(1 - pFTp, 2) * 0.4 * pstats[PAbbrT.FTA];

                    var totPoss = scPoss + fgxPoss + ftxPoss + pstats[PAbbrT.TOS];

                    var pprodFGPart = 2 * (pstats[PAbbrT.FGM] + 0.5 * pstats[PAbbrT.TPM])
                                      * (1 - 0.5 * ((pstats[PAbbrT.PTS] - pstats[PAbbrT.FTM]) / (2 * pstats[PAbbrT.FGA])) * qAST);

                    var pprodASTPart = 2
                                       * ((tstats[TAbbrT.FGM] - pstats[PAbbrT.FGM] + 0.5 * (tstats[TAbbrT.TPM] - pstats[PAbbrT.TPM]))
                                          / (tstats[TAbbrT.FGM] - pstats[PAbbrT.FGM])) * 0.5
                                       * (((tstats[TAbbrT.PF] - tstats[TAbbrT.FTM]) - (pstats[PAbbrT.PTS] - pstats[PAbbrT.FTM]))
                                          / (2 * (tstats[TAbbrT.FGA] - pstats[PAbbrT.FGA]))) * pstats[PAbbrT.AST];

                    var pprodOREBPart = pstats[PAbbrT.OREB] * teamOREBWeight * teamPlayPct
                                        * (tstats[TAbbrT.PF]
                                           / (tstats[TAbbrT.FGM] + (1 - Math.Pow(1 - tFTp, 2)) * 0.4 * tstats[TAbbrT.FTA]));

                    var pProd = (pprodFGPart + pprodASTPart + pstats[PAbbrT.FTM])
                                * (1 - (tstats[TAbbrT.OREB] / teamScPoss) * teamOREBWeight * teamPlayPct) + pprodOREBPart;

                    var ortg = 100 * (pProd / totPoss);

                    var floorPct = scPoss / totPoss;

                    tempMetrics["ORTG"] = ortg;
                    tempMetrics["Floor%"] = floorPct;

                    #endregion

                    #region Defensive Rating

                    var dorPct = toppstats[TAbbrT.OREB] / (toppstats[TAbbrT.OREB] + tstats[TAbbrT.DREB]);

                    var dfgPct = toppstats[TAbbrT.FGM] / toppstats[TAbbrT.FGA];

                    var fmWt = (dfgPct * (1 - dorPct)) / (dfgPct * (1 - dorPct) + (1 - dfgPct) * dorPct);

                    var stops1 = pstats[PAbbrT.STL] + pstats[PAbbrT.BLK] * fmWt * (1 - 1.07 * dorPct)
                                 + pstats[PAbbrT.DREB] * (1 - fmWt);

                    var stops2 = (((toppstats[TAbbrT.FGA] - toppstats[TAbbrT.FGM] - tstats[TAbbrT.BLK]) / tstats[TAbbrT.MINS]) * fmWt
                                  * (1 - 1.07 * dorPct) + ((toppstats[TAbbrT.TOS] - tstats[TAbbrT.STL]) / tstats[TAbbrT.MINS]))
                                 * pstats[PAbbrT.MINS]
                                 + (pstats[PAbbrT.PTS] / tstats[TAbbrT.PF]) * 0.4 * toppstats[TAbbrT.FTA]
                                 * Math.Pow(1 - (toppstats[TAbbrT.FTM] / toppstats[TAbbrT.FTA]), 2);

                    var stops = stops1 + stops2;

                    var stopPct = (stops * toppstats[TAbbrT.MINS]) / (tempTeamMetricsOwn["Poss"] * pstats[PAbbrT.MINS]);

                    var dPtsPerScPoss = toppstats[TAbbrT.PF]
                                        / (toppstats[TAbbrT.FGM]
                                           + (1 - Math.Pow(1 - (toppstats[TAbbrT.FTM] / toppstats[TAbbrT.FTA]), 2))
                                           * toppstats[TAbbrT.FTA] * 0.4);

                    var drtg = tempTeamMetricsOwn["DRTG"] + 0.2 * (100 * dPtsPerScPoss * (1 - stopPct) - tempTeamMetricsOwn["DRTG"]);

                    var rtgd = ortg - drtg;

                    tempMetrics["DRTG"] = drtg;
                    tempMetrics["RTGd"] = rtgd;

                    #endregion
                }
                else
                {
                    tempMetrics["aPER"] = Double.NaN;
                    tempMetrics["BLK%"] = Double.NaN;
                    tempMetrics["DREB%"] = Double.NaN;
                    tempMetrics["OREB%"] = Double.NaN;
                    tempMetrics["REB%"] = Double.NaN;
                    tempMetrics["PPR"] = Double.NaN;

                    tempMetrics["ORTG"] = Double.NaN;
                    tempMetrics["Floor%"] = Double.NaN;
                    tempMetrics["DRTG"] = Double.NaN;
                    tempMetrics["RTGd"] = Double.NaN;
                }

                #endregion
            }

            var games = (!playoffs) ? ts.GetGames() : ts.GetPlayoffGames();

            var gamesRequired = (int) Math.Ceiling(0.8522 * games);
            if (leagueOv)
            {
                if (pstats[PAbbrT.GP] < gamesRequired)
                {
                    foreach (var name in tempMetrics.Keys.ToList())
                    {
                        tempMetrics[name] = Double.NaN;
                    }
                }
            }

            if (!playoffs)
            {
                Metrics = new Dictionary<string, double>(tempMetrics);
            }
            else
            {
                PlMetrics = new Dictionary<string, double>(tempMetrics);
            }
        }
        public TeamStatsRow(TeamStats ts, bool playoffs = false)
        {
            ID = ts.ID;
            Name = ts.Name;
            DisplayName = ts.DisplayName;
            IsHidden = ts.IsHidden;

            if (!playoffs)
            {
                Games = ts.GetGames();
                Wins = ts.Record[0];
                Losses = ts.Record[1];
                MINS = ts.Totals[TAbbr.MINS];
                PF = ts.Totals[TAbbr.PF];
                PA = ts.Totals[TAbbr.PA];
                FGM = ts.Totals[TAbbr.FGM];
                FGMPG = ((float) FGM/Games);
                FGA = ts.Totals[TAbbr.FGA];
                FGAPG = ((float) FGA/Games);
                TPM = ts.Totals[TAbbr.TPM];
                TPMPG = ((float) TPM/Games);
                TPA = ts.Totals[TAbbr.TPA];
                TPAPG = ((float) TPA/Games);
                FTM = ts.Totals[TAbbr.FTM];
                FTMPG = ((float) FTM/Games);
                FTA = ts.Totals[TAbbr.FTA];
                FTAPG = ((float) FTA/Games);
                OREB = ts.Totals[TAbbr.OREB];
                DREB = ts.Totals[TAbbr.DREB];
                REB = (UInt16) (OREB + DREB);
                STL = ts.Totals[TAbbr.STL];
                TOS = ts.Totals[TAbbr.TOS];
                BLK = ts.Totals[TAbbr.BLK];
                AST = ts.Totals[TAbbr.AST];
                FOUL = ts.Totals[TAbbr.FOUL];

                Wp = ts.PerGame[TAbbr.Wp];
                Weff = ts.PerGame[TAbbr.Weff];
                MPG = ts.PerGame[TAbbr.MPG];
                PPG = ts.PerGame[TAbbr.PPG];
                PAPG = ts.PerGame[TAbbr.PAPG];
                FGp = ts.PerGame[TAbbr.FGp];
                FGeff = ts.PerGame[TAbbr.FGeff];
                TPp = ts.PerGame[TAbbr.TPp];
                TPeff = ts.PerGame[TAbbr.TPeff];
                FTp = ts.PerGame[TAbbr.FTp];
                FTeff = ts.PerGame[TAbbr.FTeff];
                RPG = ts.PerGame[TAbbr.RPG];
                ORPG = ts.PerGame[TAbbr.ORPG];
                DRPG = ts.PerGame[TAbbr.DRPG];
                SPG = ts.PerGame[TAbbr.SPG];
                TPG = ts.PerGame[TAbbr.TPG];
                BPG = ts.PerGame[TAbbr.BPG];
                APG = ts.PerGame[TAbbr.APG];
                FPG = ts.PerGame[TAbbr.FPG];

                Poss = ts.Metrics["PossPG"];
                Pace = ts.Metrics["Pace"];
                ORTG = ts.Metrics["ORTG"];
                DRTG = ts.Metrics["DRTG"];
                ASTp = ts.Metrics["AST%"];
                DREBp = ts.Metrics["DREB%"];
                EFGp = ts.Metrics["EFG%"];
                EFFd = ts.Metrics["EFFd"];
                TOR = ts.Metrics["TOR"];
                OREBp = ts.Metrics["OREB%"];
                FTR = ts.Metrics["FTR"];
                PWp = ts.Metrics["PW%"];
                TSp = ts.Metrics["TS%"];
                TPR = ts.Metrics["3PR"];
                PythW = ts.Metrics["PythW"];
                PythL = ts.Metrics["PythL"];
            }
            else
            {
                Games = ts.GetPlayoffGames();
                Wins = ts.PlRecord[0];
                Losses = ts.PlRecord[1];
                MINS = ts.PlTotals[TAbbr.MINS];
                PF = ts.PlTotals[TAbbr.PF];
                PA = ts.PlTotals[TAbbr.PA];
                FGM = ts.PlTotals[TAbbr.FGM];
                FGMPG = ((float) FGM/Games);
                FGA = ts.PlTotals[TAbbr.FGA];
                FGAPG = ((float) FGA/Games);
                TPM = ts.PlTotals[TAbbr.TPM];
                TPMPG = ((float) TPM/Games);
                TPA = ts.PlTotals[TAbbr.TPA];
                TPAPG = ((float) TPA/Games);
                FTM = ts.PlTotals[TAbbr.FTM];
                FTMPG = ((float) FTM/Games);
                FTA = ts.PlTotals[TAbbr.FTA];
                FTAPG = ((float) FTA/Games);
                OREB = ts.PlTotals[TAbbr.OREB];
                DREB = ts.PlTotals[TAbbr.DREB];
                REB = (UInt16) (OREB + DREB);
                STL = ts.PlTotals[TAbbr.STL];
                TOS = ts.PlTotals[TAbbr.TOS];
                BLK = ts.PlTotals[TAbbr.BLK];
                AST = ts.PlTotals[TAbbr.AST];
                FOUL = ts.PlTotals[TAbbr.FOUL];

                Wp = ts.PlPerGame[TAbbr.Wp];
                Weff = ts.PlPerGame[TAbbr.Weff];
                PPG = ts.PlPerGame[TAbbr.PPG];
                PAPG = ts.PlPerGame[TAbbr.PAPG];
                FGp = ts.PlPerGame[TAbbr.FGp];
                FGeff = ts.PlPerGame[TAbbr.FGeff];
                TPp = ts.PlPerGame[TAbbr.TPp];
                TPeff = ts.PlPerGame[TAbbr.TPeff];
                FTp = ts.PlPerGame[TAbbr.FTp];
                FTeff = ts.PlPerGame[TAbbr.FTeff];
                RPG = ts.PlPerGame[TAbbr.RPG];
                ORPG = ts.PlPerGame[TAbbr.ORPG];
                DRPG = ts.PlPerGame[TAbbr.DRPG];
                SPG = ts.PlPerGame[TAbbr.SPG];
                TPG = ts.PlPerGame[TAbbr.TPG];
                BPG = ts.PlPerGame[TAbbr.BPG];
                APG = ts.PlPerGame[TAbbr.APG];
                FPG = ts.PlPerGame[TAbbr.FPG];

                Poss = ts.PlMetrics["PossPG"];
                Pace = ts.PlMetrics["Pace"];
                ORTG = ts.PlMetrics["ORTG"];
                DRTG = ts.PlMetrics["DRTG"];
                ASTp = ts.PlMetrics["AST%"];
                DREBp = ts.PlMetrics["DREB%"];
                EFGp = ts.PlMetrics["EFG%"];
                EFFd = ts.PlMetrics["EFFd"];
                TOR = ts.PlMetrics["TOR"];
                OREBp = ts.PlMetrics["OREB%"];
                FTR = ts.PlMetrics["FTR"];
                PWp = ts.PlMetrics["PW%"];
                TSp = ts.PlMetrics["TS%"];
                TPR = ts.PlMetrics["3PR"];
                PythW = ts.PlMetrics["PythW"];
                PythL = ts.PlMetrics["PythL"];
            }

            CurStreak = ts.CurStreak;
        }
        /// <summary>
        ///     Calculates the Metric Stats for this Player
        /// </summary>
        /// <param name="ts">The player's team's stats</param>
        /// <param name="tsopp">The player's team's opponents' stats</param>
        /// <param name="ls">The total league stats</param>
        /// <param name="leagueOv">Whether CalcMetrics is being called from the League Overview screen</param>
        public void CalcMetrics(TeamStats ts, TeamStats tsopp, TeamStats ls, bool leagueOv = false, bool GmScOnly = false,
                                bool playoffs = false)
        {
            var pstats = new double[Totals.Length];
            for (int i = 0; i < Totals.Length; i++)
            {
                if (!playoffs)
                {
                    pstats[i] = Totals[i];
                }
                else
                {
                    pstats[i] = PlTotals[i];
                }
            }

            var tstats = new double[ts.Totals.Length];
            for (int i = 0; i < ts.Totals.Length; i++)
            {
                if (!playoffs)
                {
                    tstats[i] = ts.Totals[i];
                }
                else
                {
                    tstats[i] = ts.PlTotals[i];
                }
            }

            var toppstats = new double[tsopp.Totals.Length];
            for (int i = 0; i < tsopp.Totals.Length; i++)
            {
                if (!playoffs)
                {
                    toppstats[i] = tsopp.Totals[i];
                }
                else
                {
                    toppstats[i] = tsopp.PlTotals[i];
                }
            }

            var lstats = new double[ls.Totals.Length];
            for (int i = 0; i < ls.Totals.Length; i++)
            {
                if (!playoffs)
                {
                    lstats[i] = ls.Totals[i];
                }
                else
                {
                    lstats[i] = ls.PlTotals[i];
                }
            }

            double pREB = pstats[PAbbr.OREB] + pstats[PAbbr.DREB];
            double tREB = tstats[TAbbr.OREB] + tstats[TAbbr.DREB];

            var tempMetrics = new Dictionary<string, double>();

            double gmSc = pstats[PAbbr.PTS] + 0.4*pstats[PAbbr.FGM] - 0.7*pstats[PAbbr.FGA] -
                          0.4*(pstats[PAbbr.FTA] - pstats[PAbbr.FTM]) + 0.7*pstats[PAbbr.OREB] + 0.3*pstats[PAbbr.DREB] +
                          pstats[PAbbr.STL] + 0.7*pstats[PAbbr.AST] + 0.7*pstats[PAbbr.BLK] - 0.4*pstats[PAbbr.FOUL] -
                          pstats[PAbbr.TOS];
            tempMetrics.Add("GmSc", gmSc/pstats[PAbbr.GP]);

            double gmScE = 36*(1/pstats[PAbbr.MINS])*gmSc;
            tempMetrics.Add("GmScE", gmScE);

            if (!GmScOnly)
            {
                #region temp_metrics that do not require Opponent Stats

                double ASTp = pstats[PAbbr.AST]/(((pstats[PAbbr.MINS]/(tstats[TAbbr.MINS]))*tstats[TAbbr.FGM]) - pstats[PAbbr.FGM]);
                tempMetrics.Add("AST%", ASTp);

                double EFGp = (pstats[PAbbr.FGM] + 0.5*pstats[PAbbr.TPM])/pstats[PAbbr.FGA];
                tempMetrics.Add("EFG%", EFGp);

                Dictionary<string, double> tempOppMetrics = !playoffs ? tsopp.Metrics : tsopp.PlMetrics;

                double STLp = (pstats[PAbbr.STL]*(tstats[TAbbr.MINS]))/(pstats[PAbbr.MINS]*tempOppMetrics["Poss"]);
                tempMetrics.Add("STL%", STLp);

                double TOp = pstats[PAbbr.TOS]/(pstats[PAbbr.FGA] + 0.44*pstats[PAbbr.FTA] + pstats[PAbbr.TOS]);
                tempMetrics.Add("TO%", TOp);

                double TSp = pstats[PAbbr.PTS]/(2*(pstats[PAbbr.FGA] + 0.44*pstats[PAbbr.FTA]));
                tempMetrics.Add("TS%", TSp);

                double USGp = ((pstats[PAbbr.FGA] + 0.44*pstats[PAbbr.FTA] + pstats[PAbbr.TOS])*(tstats[TAbbr.MINS]))/
                              (pstats[PAbbr.MINS]*(tstats[TAbbr.FGA] + 0.44*tstats[TAbbr.FTA] + tstats[TAbbr.TOS]));
                tempMetrics.Add("USG%", USGp);

                CalculateRates(pstats, ref tempMetrics);
                // PER preparations
                double lREB = lstats[TAbbr.OREB] + lstats[TAbbr.DREB];
                double factor = (2/3) - (0.5*(lstats[TAbbr.AST]/lstats[TAbbr.FGM]))/(2*(lstats[TAbbr.FGM]/lstats[TAbbr.FTM]));
                double VOP = lstats[TAbbr.PF]/(lstats[TAbbr.FGA] - lstats[TAbbr.OREB] + lstats[TAbbr.TOS] + 0.44*lstats[TAbbr.FTA]);
                double lDRBp = lstats[TAbbr.DREB]/lREB;

                double uPER = (1/pstats[PAbbr.MINS])*
                              (pstats[PAbbr.TPM] + (2/3)*pstats[PAbbr.AST] +
                               (2 - factor*(tstats[TAbbr.AST]/tstats[TAbbr.FGM]))*pstats[PAbbr.FGM] +
                               (pstats[PAbbr.FTM]*0.5*
                                (1 + (1 - (tstats[TAbbr.AST]/tstats[TAbbr.FGM])) + (2/3)*(tstats[TAbbr.AST]/tstats[TAbbr.FGM]))) -
                               VOP*pstats[PAbbr.TOS] - VOP*lDRBp*(pstats[PAbbr.FGA] - pstats[PAbbr.FGM]) -
                               VOP*0.44*(0.44 + (0.56*lDRBp))*(pstats[PAbbr.FTA] - pstats[PAbbr.FTM]) +
                               VOP*(1 - lDRBp)*(pREB - pstats[PAbbr.OREB]) + VOP*lDRBp*pstats[PAbbr.OREB] + VOP*pstats[PAbbr.STL] +
                               VOP*lDRBp*pstats[PAbbr.BLK] -
                               pstats[PAbbr.FOUL]*
                               ((lstats[TAbbr.FTM]/lstats[TAbbr.FOUL]) - 0.44*(lstats[TAbbr.FTA]/lstats[TAbbr.FOUL])*VOP));
                tempMetrics.Add("EFF", uPER*100);

                #endregion

                #region temp_metrics that require Opponents stats

                if (ts.GetGames() == tsopp.GetGames())
                {
                    double BLKp = (pstats[PAbbr.BLK]*(tstats[TAbbr.MINS]))/
                                  (pstats[PAbbr.MINS]*(toppstats[TAbbr.FGA] - toppstats[TAbbr.TPA]));

                    double DRBp = (pstats[PAbbr.DREB]*(tstats[TAbbr.MINS]))/
                                  (pstats[PAbbr.MINS]*(tstats[TAbbr.DREB] + toppstats[TAbbr.OREB]));

                    double ORBp = (pstats[PAbbr.OREB]*(tstats[TAbbr.MINS]))/
                                  (pstats[PAbbr.MINS]*(tstats[TAbbr.OREB] + toppstats[TAbbr.DREB]));

                    double toppREB = toppstats[TAbbr.OREB] + toppstats[TAbbr.DREB];

                    double REBp = (pREB*(tstats[TAbbr.MINS]))/(pstats[PAbbr.MINS]*(tREB + toppREB));

                    #region temp_metrics that require league stats

                    double aPER;
                    double PPR;

                    if (ls.Name != "$$Empty")
                    {
                        //double paceAdj = ls.temp_metrics["Pace"]/ts.temp_metrics["Pace"];
                        double estPaceAdj;
                        if (!playoffs)
                        {
                            estPaceAdj = 2*ls.PerGame[TAbbr.PPG]/(ts.PerGame[TAbbr.PPG] + tsopp.PerGame[TAbbr.PPG]);
                        }
                        else
                        {
                            estPaceAdj = 2*ls.PlPerGame[TAbbr.PPG]/(ts.PlPerGame[TAbbr.PPG] + tsopp.PlPerGame[TAbbr.PPG]);
                        }

                        aPER = estPaceAdj*uPER;

                        PPR = 100*estPaceAdj*(((pstats[PAbbr.AST]*2/3) - pstats[PAbbr.TOS])/pstats[PAbbr.MINS]);
                    }
                    else
                    {
                        aPER = Double.NaN;
                        PPR = Double.NaN;
                    }

                    #endregion

                    tempMetrics.Add("aPER", aPER);
                    tempMetrics.Add("BLK%", BLKp);
                    tempMetrics.Add("DREB%", DRBp);
                    tempMetrics.Add("OREB%", ORBp);
                    tempMetrics.Add("REB%", REBp);
                    tempMetrics.Add("PPR", PPR);
                }
                else
                {
                    tempMetrics.Add("aPER", Double.NaN);
                    tempMetrics.Add("BLK%", Double.NaN);
                    tempMetrics.Add("DREB%", Double.NaN);
                    tempMetrics.Add("OREB%", Double.NaN);
                    tempMetrics.Add("REB%", Double.NaN);
                    tempMetrics.Add("PPR", Double.NaN);
                }

                #endregion
            }

            uint games = (!playoffs) ? ts.GetGames() : ts.GetPlayoffGames();

            var gamesRequired = (int) Math.Ceiling(0.8522*games);
            if (leagueOv)
            {
                if (pstats[PAbbr.GP] < gamesRequired)
                {
                    foreach (string name in tempMetrics.Keys.ToList())
                    {
                        tempMetrics[name] = Double.NaN;
                    }
                }
            }

            if (!playoffs)
            {
                Metrics = new Dictionary<string, double>(tempMetrics);
            }
            else
            {
                PlMetrics = new Dictionary<string, double>(tempMetrics);
            }
        }