예제 #1
0
 public static void TryChangeTSR(ref TeamStatsRow tsr, Dictionary <string, string> dict)
 {
     tsr.Wins   = tsr.Wins.TrySetValue(dict, "Wins", typeof(UInt16));
     tsr.Losses = tsr.Losses.TrySetValue(dict, "Losses", typeof(UInt16));
     tsr.MINS   = tsr.MINS.TrySetValue(dict, "MINS", typeof(UInt16));
     tsr.PF     = tsr.PF.TrySetValue(dict, "PF", typeof(UInt16));
     tsr.PA     = tsr.PF.TrySetValue(dict, "PA", typeof(UInt16));
     tsr.FGM    = tsr.FGM.TrySetValue(dict, "FGM", typeof(UInt16));
     tsr.FGA    = tsr.FGA.TrySetValue(dict, "FGA", typeof(UInt16));
     tsr.TPM    = tsr.TPM.TrySetValue(dict, "3PM", typeof(UInt16));
     tsr.TPA    = tsr.TPA.TrySetValue(dict, "3PA", typeof(UInt16));
     tsr.FTM    = tsr.FTM.TrySetValue(dict, "FTM", typeof(UInt16));
     tsr.FTA    = tsr.FTA.TrySetValue(dict, "FTA", typeof(UInt16));
     tsr.REB    = tsr.REB.TrySetValue(dict, "REB", typeof(UInt16));
     tsr.OREB   = tsr.OREB.TrySetValue(dict, "OREB", typeof(UInt16));
     tsr.DREB   = tsr.DREB.TrySetValue(dict, "DREB", typeof(UInt16));
     tsr.AST    = tsr.AST.TrySetValue(dict, "AST", typeof(UInt16));
     tsr.TOS    = tsr.TOS.TrySetValue(dict, "TO", typeof(UInt16));
     tsr.STL    = tsr.STL.TrySetValue(dict, "STL", typeof(UInt16));
     tsr.BLK    = tsr.BLK.TrySetValue(dict, "BLK", typeof(UInt16));
     tsr.FOUL   = tsr.FOUL.TrySetValue(dict, "FOUL", typeof(UInt16));
 }
예제 #2
0
        public TeamStats(TeamStatsRow tsr, bool playoffs = false)
        {
            Name = tsr.Name;
            DisplayName = tsr.DisplayName;

            if (!playoffs)
            {
                Record[0] = tsr.Wins;
                Record[1] = tsr.Losses;

                Totals[TAbbrT.MINS] = tsr.MINS;
                Totals[TAbbrT.PF] = tsr.PF;
                Totals[TAbbrT.PA] = tsr.PA;
                Totals[TAbbrT.FGM] = tsr.FGM;
                Totals[TAbbrT.FGA] = tsr.FGA;
                Totals[TAbbrT.TPM] = tsr.TPM;
                Totals[TAbbrT.TPA] = tsr.TPA;
                Totals[TAbbrT.FTM] = tsr.FTM;
                Totals[TAbbrT.FTA] = tsr.FTA;
                Totals[TAbbrT.OREB] = tsr.OREB;
                Totals[TAbbrT.DREB] = tsr.DREB;
                Totals[TAbbrT.STL] = tsr.STL;
                Totals[TAbbrT.TOS] = tsr.TOS;
                Totals[TAbbrT.BLK] = tsr.BLK;
                Totals[TAbbrT.AST] = tsr.AST;
                Totals[TAbbrT.FOUL] = tsr.FOUL;

                Metrics["PossPG"] = tsr.Poss;
                Metrics["Pace"] = tsr.Pace;
                Metrics["ORTG"] = tsr.ORTG;
                Metrics["DRTG"] = tsr.DRTG;
                Metrics["AST%"] = tsr.ASTp;
                Metrics["DREB%"] = tsr.DREBp;
                Metrics["EFG%"] = tsr.EFGp;
                Metrics["EFFd"] = tsr.EFFd;
                Metrics["TOR"] = tsr.TOR;
                Metrics["OREB%"] = tsr.OREBp;
                Metrics["FTR"] = tsr.FTR;
                Metrics["PW%"] = tsr.PWp;
                Metrics["TS%"] = tsr.TSp;
                Metrics["3PR"] = tsr.TPR;
                Metrics["PythW"] = tsr.PythW;
                Metrics["PythL"] = tsr.PythL;
            }
            else
            {
                PlRecord[0] = tsr.Wins;
                PlRecord[1] = tsr.Losses;

                PlTotals[TAbbrT.MINS] = tsr.MINS;
                PlTotals[TAbbrT.PF] = tsr.PF;
                PlTotals[TAbbrT.PA] = tsr.PA;
                PlTotals[TAbbrT.FGM] = tsr.FGM;
                PlTotals[TAbbrT.FGA] = tsr.FGA;
                PlTotals[TAbbrT.TPM] = tsr.TPM;
                PlTotals[TAbbrT.TPA] = tsr.TPA;
                PlTotals[TAbbrT.FTM] = tsr.FTM;
                PlTotals[TAbbrT.FTA] = tsr.FTA;
                PlTotals[TAbbrT.OREB] = tsr.OREB;
                PlTotals[TAbbrT.DREB] = tsr.DREB;
                PlTotals[TAbbrT.STL] = tsr.STL;
                PlTotals[TAbbrT.TOS] = tsr.TOS;
                PlTotals[TAbbrT.BLK] = tsr.BLK;
                PlTotals[TAbbrT.AST] = tsr.AST;
                PlTotals[TAbbrT.FOUL] = tsr.FOUL;

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

            ID = tsr.ID;
            IsHidden = tsr.IsHidden;

            CalcAvg();
        }
예제 #3
0
 public static void Refresh(ref TeamStatsRow tsr)
 {
     tsr = new TeamStatsRow(new TeamStats(tsr));
 }
        private void updateGraph()
        {
            if (cmbGraphStat.SelectedIndex == -1 || cmbTeam.SelectedIndex == -1 || cmbGraphInterval.SelectedIndex == -1)
            {
                clearGraph();
                return;
            }
            var intervalItem = cmbGraphInterval.SelectedItem.ToString();
            var yearlyRows = _dtYea.Rows.Cast<DataRow>().Where(dr => dr[0].ToString().StartsWith("Season")).ToList();
            var monthlyStats = MainWindow.SplitTeamStats[_curts.ID].Where(pair => pair.Key.StartsWith("M ")).ToList();
            var orderedBSEList = _bseList.OrderBy(bse => bse.BS.GameDate).ToList();
            Intervals interval;
            int count;
            switch (intervalItem)
            {
                case "Every Game":
                    interval = Intervals.EveryGame;
                    count = orderedBSEList.Count;
                    break;
                case "Monthly":
                    interval = Intervals.Monthly;
                    count = monthlyStats.Count;
                    break;
                case "Yearly":
                    interval = Intervals.Yearly;
                    count = yearlyRows.Count;
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            if (count < 2)
            {
                clearGraph();
                return;
            }

            var propToGet = cmbGraphStat.SelectedItem.ToString();
            propToGet = propToGet.Replace('3', 'T');
            propToGet = propToGet.Replace('%', 'p');
            propToGet = propToGet.Replace("TO", "TOS");

            double sum = 0;
            double games = 0;

            chart.Primitives.Clear();
            var cp = new ChartPrimitive { Label = cmbGraphStat.SelectedItem.ToString(), ShowInLegend = false };

            switch (interval)
            {
                case Intervals.EveryGame:
                    for (var i = 0; i < count; i++)
                    {
                        var bse = orderedBSEList[i];
                        bse.BS.PrepareForDisplay(_tst, _curts.ID);

                        var isTeamAway = bse.BS.Team1ID == _curts.ID;
                        var propToGetFinal = propToGet;
                        if (propToGet == "PF")
                        {
                            propToGetFinal = isTeamAway ? "PTS1" : "PTS2";
                        }
                        else if (propToGet == "PA")
                        {
                            propToGetFinal = isTeamAway ? "PTS2" : "PTS1";
                        }
                        else
                        {
                            propToGetFinal += (isTeamAway ? 1 : 2).ToString();
                        }
                        var value = bse.BS.GetValue<TeamBoxScore, double>(propToGetFinal);
                        if (double.IsNaN(value))
                        {
                            continue;
                        }
                        if (propToGet.Contains("p"))
                        {
                            value = Convert.ToDouble(Convert.ToInt32(value * 1000)) / 1000;
                        }
                        cp.AddPoint(i + 1, value);
                        games++;
                        sum += value;
                    }
                    break;
                case Intervals.Monthly:
                    monthlyStats = monthlyStats.OrderBy(ms => ms.Key).ToList();
                    if (TeamStatsHelper.TotalsToPerGame.ContainsKey(propToGet))
                    {
                        propToGet = TeamStatsHelper.TotalsToPerGame[propToGet];
                    }
                    for (var i = 0; i < count; i++)
                    {
                        var ts = monthlyStats[i].Value;
                        ts.CalcMetrics(new TeamStats());
                        var tsr = new TeamStatsRow(ts);
                        var value = tsr.GetValue<double>(propToGet);
                        if (double.IsNaN(value))
                        {
                            continue;
                        }
                        if (propToGet.Contains("p"))
                        {
                            value = Convert.ToDouble(Convert.ToInt32(value * 1000)) / 1000;
                        }
                        cp.AddPoint(i + 1, value);
                        games++;
                        sum += value;
                    }
                    break;
                case Intervals.Yearly:
                    if (TeamStatsHelper.TotalsToPerGame.ContainsKey(propToGet))
                    {
                        propToGet = TeamStatsHelper.TotalsToPerGame[propToGet];
                    }
                    for (var i = 0; i < count; i++)
                    {
                        var ts = new TeamStats();
                        createTeamStatsFromDataRow(ref ts, _dtYea.Rows.Cast<DataRow>().ToList()[i]);
                        ts.CalcMetrics(new TeamStats());
                        var tsr = new TeamStatsRow(ts);
                        var value = tsr.GetValue<TeamStatsRow, double>(propToGet);
                        if (double.IsNaN(value))
                        {
                            continue;
                        }
                        if (propToGet.Contains("p"))
                        {
                            value = Convert.ToDouble(Convert.ToInt32(value * 1000)) / 1000;
                        }
                        cp.AddPoint(i + 1, value);
                        games++;
                        sum += value;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            if (cp.Points.Count > 0)
            {
                chart.Primitives.Add(cp);
            }
            if (chart.Primitives.Count > 0 && chart.Primitives.Sum(p => p.Points.Count) > 1)
            {
                //var average = sum / games;
                if (TeamStatsHelper.TotalsToPerGame.ContainsKey(propToGet))
                {
                    propToGet = TeamStatsHelper.TotalsToPerGame[propToGet];
                }
                double average;
                switch (interval)
                {
                    case Intervals.EveryGame:
                    case Intervals.Monthly:
                        average = _curTSR.GetValue<double>(propToGet);
                        break;
                    case Intervals.Yearly:
                        var ts = new TeamStats();
                        createTeamStatsFromDataRow(ref ts, _dtYea.Rows.Cast<DataRow>().ToList().Last());
                        ts.CalcMetrics(new TeamStats());
                        var tsr = new TeamStatsRow(ts);
                        average = tsr.GetValue<double>(propToGet);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
                var cpavg = new ChartPrimitive();
                for (var i = 0; i < count; i++)
                {
                    cpavg.AddPoint(i + 1, average);
                }
                cpavg.Color = Color.FromRgb(0, 0, 100);
                cpavg.Dashed = true;
                cpavg.ShowInLegend = false;
                var cp2 = new ChartPrimitive();
                cp2.AddPoint(chart.Primitives.First().Points.First().X, 0);
                cp2.AddPoint(chart.Primitives.Last().Points.Last().X, 1);

                chart.Primitives.Add(cpavg);
                chart.RedrawPlotLines();
                chart.Primitives.Add(cp2);
            }
            else
            {
                chart.RedrawPlotLines();
                var cp2 = new ChartPrimitive();
                cp2.AddPoint(1, 0);
                cp2.AddPoint(2, 1);
                chart.Primitives.Add(cp2);
            }
            chart.ResetPanAndZoom();
        }
 private void highlightAndAddTeams(KeyValuePair<int, TeamStats> pair, ref ObservableCollection<TeamStatsRow> tsrObservable)
 {
     var tsr = new TeamStatsRow(pair.Value);
     if (_teamsToHighlight.Contains(tsr.ID))
     {
         tsr.Highlight = true;
     }
     tsrObservable.Add(tsr);
 }
 private void prepareMatchupPreviewStrengths(
     Dictionary<int, int> dict,
     ref string msgDesc,
     TeamStatsRow tsr,
     int iTeam,
     TeamStatsRow tsropp,
     int iOpp,
     List<int> used,
     ref string msgTeam,
     ref string msgOpp)
 {
     var strengths = (from entry in dict orderby entry.Value ascending select entry.Key).ToList();
     var m = 0;
     var j = 2;
     while (true)
     {
         if (m == j)
         {
             break;
         }
         if (used.Contains(strengths[m]))
         {
             m++;
             j++;
             continue;
         }
         var def = false;
         switch (strengths[m])
         {
             case TAbbrPG.APG:
                 msgDesc += "Assists";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.APG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.APG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.APG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.APG]);
                 break;
             case TAbbrPG.BPG:
                 msgDesc += "Blocks";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.BPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.BPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.BPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.BPG]);
                 break;
             case TAbbrPG.DRPG:
                 msgDesc += "Def. Rebounds";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.DRPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.DRPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.DRPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.DRPG]);
                 break;
             case TAbbrPG.FPG:
                 msgDesc += "Fouls";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.FPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.FPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.FPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.FPG]);
                 break;
             case TAbbrPG.ORPG:
                 msgDesc += "Off. Rebounds";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.ORPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.ORPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.ORPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.ORPG]);
                 break;
             case TAbbrPG.PAPG:
                 msgDesc += "Points Against";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.PAPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.PAPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.PAPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.PAPG]);
                 break;
             case TAbbrPG.PPG:
                 msgDesc += "Points For";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.PPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.PPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.PPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.PPG]);
                 break;
             case TAbbrPG.RPG:
                 msgDesc += "Rebounds";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.RPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.RPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.RPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.RPG]);
                 break;
             case TAbbrPG.SPG:
                 msgDesc += "Steals";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.SPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.SPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.SPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.SPG]);
                 break;
             case TAbbrPG.TPG:
                 msgDesc += "Turnovers";
                 msgTeam += string.Format("{0:F1} ({1})", tsr.TPG, _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.TPG]);
                 msgOpp += string.Format("{0:F1} ({1})", tsropp.TPG, _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.TPG]);
                 break;
             case TAbbrPG.FGeff:
                 msgDesc += "Field Goals";
                 msgTeam += string.Format(
                     "{0:F1}-{1:F1} ({2:F3}) ({3})",
                     tsr.FGMPG,
                     tsr.FGAPG,
                     tsr.FGp,
                     _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.FGeff]);
                 msgOpp += string.Format(
                     "{0:F1}-{1:F1} ({2:F3}) ({3})",
                     tsropp.FGMPG,
                     tsropp.FGAPG,
                     tsropp.FGp,
                     _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.FGeff]);
                 break;
             case TAbbrPG.TPeff:
                 msgDesc += "3 Pointers";
                 msgTeam += string.Format(
                     "{0:F1}-{1:F1} ({2:F3}) ({3})",
                     tsr.TPMPG,
                     tsr.TPAPG,
                     tsr.TPp,
                     _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.TPeff]);
                 msgOpp += string.Format(
                     "{0:F1}-{1:F1} ({2:F3}) ({3})",
                     tsropp.TPMPG,
                     tsropp.TPAPG,
                     tsropp.TPp,
                     _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.TPeff]);
                 break;
             case TAbbrPG.FTeff:
                 msgDesc += "Free Throws";
                 msgTeam += string.Format(
                     "{0:F1}-{1:F1} ({2:F3}) ({3})",
                     tsr.FTMPG,
                     tsr.FTAPG,
                     tsr.FTp,
                     _seasonRankings.RankingsPerGame[iTeam][TAbbrPG.FTeff]);
                 msgOpp += string.Format(
                     "{0:F1}-{1:F1} ({2:F3}) ({3})",
                     tsropp.FTMPG,
                     tsropp.FTAPG,
                     tsropp.FTp,
                     _seasonRankings.RankingsPerGame[iOpp][TAbbrPG.FTeff]);
                 break;
             default:
                 j++;
                 def = true;
                 break;
         }
         if (!def)
         {
             used.Add(strengths[m]);
             msgDesc += "\n";
             msgTeam += "\n";
             msgOpp += "\n";
         }
         m++;
     }
 }
        /// <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 prepareMatchupPreview(List<PlayerStatsRow> teamPMSRList, List<PlayerStatsRow> oppPMSRList)
        {
            var iTeam = _curTeam;
            var iOpp = _curOpp;
            txbMPDescHeader.Text = "vs\n";
            txbMPTeamHeader.Text = string.Format(
                "{0}\n{1}-{2}", _tst[_curTeam].DisplayName, _tst[iTeam].Record[0], _tst[iTeam].Record[1]);
            txbMPOppHeader.Text = string.Format("{0}\n{1}-{2}", _tst[_curOpp].DisplayName, _tst[iOpp].Record[0], _tst[iOpp].Record[1]);

            var tsr = new TeamStatsRow(_tst[iTeam]);
            var tsropp = new TeamStatsRow(_tst[iOpp]);
            var msgDesc = "";
            var msgTeam = "";
            var msgOpp = "";

            var used = new List<int>();
            var dict = new Dictionary<int, int>();
            for (var k = 0; k < _seasonRankings.RankingsPerGame[iTeam].Length; k++)
            {
                dict.Add(k, _seasonRankings.RankingsPerGame[iTeam][k]);
            }
            prepareMatchupPreviewStrengths(dict, ref msgDesc, tsr, iTeam, tsropp, iOpp, used, ref msgTeam, ref msgOpp);

            dict = new Dictionary<int, int>();
            for (var k = 0; k < _seasonRankings.RankingsPerGame[iOpp].Length; k++)
            {
                dict.Add(k, _seasonRankings.RankingsPerGame[iOpp][k]);
            }
            prepareMatchupPreviewStrengths(dict, ref msgDesc, tsr, iTeam, tsropp, iOpp, used, ref msgTeam, ref msgOpp);

            var descParts = msgDesc.Split('\n');
            var teamParts = msgTeam.Split('\n');
            var oppParts = msgOpp.Split('\n');
            var s0 = teamParts[0] + "\t" + descParts[0] + "\t" + oppParts[0];
            var s1 = teamParts[1] + "\t" + descParts[1] + "\t" + oppParts[1];
            var s2 = teamParts[2] + "\t" + descParts[2] + "\t" + oppParts[2];
            var s3 = teamParts[3] + "\t" + descParts[3] + "\t" + oppParts[3];
            var list = new List<string> { s0, s1, s2, s3 };
            list.Shuffle();
            list.ForEach(
                item =>
                    {
                        var parts = item.Split('\t');
                        txbMPTeam.Text += parts[0] + "\n";
                        txbMPDesc.Text += parts[1] + "\n";
                        txbMPOpp.Text += parts[2] + "\n";
                    });

            txbMPDesc.Text += "\nG\n\n\nF\n\n\nC\n\n";
            txbMPTeam.Text += "\n" + _teamBestG + "\n" + _teamBestF + "\n" + _teamBestC;
            txbMPOpp.Text += "\n" + _oppBestG + "\n" + _oppBestF + "\n" + _oppBestC;
        }
        private void prepareMatchupPreview(List<PlayerStatsRow> teamPMSRList, List<PlayerStatsRow> oppPMSRList)
        {
            int iTeam = _curTeam;
            int iOpp = _curOpp;
            txbMPDescHeader.Text = "vs\n";
            txbMPTeamHeader.Text = string.Format("{0}\n{1}-{2}", _tst[_curTeam].DisplayName, _tst[iTeam].Record[0],
                                                 _tst[iTeam].Record[1]);
            txbMPOppHeader.Text = string.Format("{0}\n{1}-{2}", _tst[_curOpp].DisplayName, _tst[iOpp].Record[0], _tst[iOpp].Record[1]);

            var tsr = new TeamStatsRow(_tst[iTeam]);
            var tsropp = new TeamStatsRow(_tst[iOpp]);
            string msgDesc = "";
            string msgTeam = "";
            string msgOpp = "";

            var used = new List<int>();
            var dict = new Dictionary<int, int>();
            for (int k = 0; k < _seasonRankings.RankingsPerGame[iTeam].Length; k++)
            {
                dict.Add(k, _seasonRankings.RankingsPerGame[iTeam][k]);
            }
            dict[TAbbr.FPG] = _tst.Count + 1 - dict[TAbbr.FPG];
            dict[TAbbr.TPG] = _tst.Count + 1 - dict[TAbbr.TPG];
            dict[TAbbr.PAPG] = _tst.Count + 1 - dict[TAbbr.PAPG];
            List<int> strengths = (from entry in dict
                                   orderby entry.Value ascending
                                   select entry.Key).ToList();
            int m = 0;
            int j = 2;
            while (true)
            {
                if (m == j)
                {
                    break;
                }
                bool def = false;
                switch (strengths[m])
                {
                    case TAbbr.APG:
                        msgDesc += "Assists";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.APG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.APG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.APG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.APG]);
                        break;
                    case TAbbr.BPG:
                        msgDesc += "Blocks";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.BPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.BPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.BPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.BPG]);
                        break;
                    case TAbbr.DRPG:
                        msgDesc += "Def. Rebounds";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.DRPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.DRPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.DRPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.DRPG]);
                        break;
                    case TAbbr.FPG:
                        msgDesc += "Fouls";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.FPG,
                                                 _tst.Count - _seasonRankings.RankingsPerGame[iTeam][TAbbr.FPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.FPG,
                                                _tst.Count - _seasonRankings.RankingsPerGame[iOpp][TAbbr.FPG]);
                        break;
                    case TAbbr.ORPG:
                        msgDesc += "Off. Rebounds";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.ORPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.ORPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.ORPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.ORPG]);
                        break;
                    case TAbbr.PAPG:
                        msgDesc += "Points Against";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.PAPG,
                                                 _tst.Count - _seasonRankings.RankingsPerGame[iTeam][TAbbr.PAPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.PAPG,
                                                _tst.Count - _seasonRankings.RankingsPerGame[iOpp][TAbbr.PAPG]);
                        break;
                    case TAbbr.PPG:
                        msgDesc += "Points For";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.PPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.PPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.PPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.PPG]);
                        break;
                    case TAbbr.RPG:
                        msgDesc += "Rebounds";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.RPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.RPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.RPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.RPG]);
                        break;
                    case TAbbr.SPG:
                        msgDesc += "Steals";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.SPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.SPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.SPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.SPG]);
                        break;
                    case TAbbr.TPG:
                        msgDesc += "Turnovers";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.TPG,
                                                 _tst.Count - _seasonRankings.RankingsPerGame[iTeam][TAbbr.TPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.TPG,
                                                _tst.Count - _seasonRankings.RankingsPerGame[iOpp][TAbbr.TPG]);
                        break;
                    case TAbbr.FGeff:
                        msgDesc += "Field Goals";
                        msgTeam += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsr.FGMPG, tsr.FGAPG, tsr.FGp,
                                                 _seasonRankings.RankingsPerGame[iTeam][TAbbr.FGeff]);
                        msgOpp += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsropp.FGMPG, tsropp.FGAPG, tsropp.FGp,
                                                _seasonRankings.RankingsPerGame[iOpp][TAbbr.FGeff]);
                        break;
                    case TAbbr.TPeff:
                        msgDesc += "3 Pointers";
                        msgTeam += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsr.TPMPG, tsr.TPAPG, tsr.TPp,
                                                 _seasonRankings.RankingsPerGame[iTeam][TAbbr.TPeff]);
                        msgOpp += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsropp.TPMPG, tsropp.TPAPG, tsropp.TPp,
                                                _seasonRankings.RankingsPerGame[iOpp][TAbbr.TPeff]);
                        break;
                    case TAbbr.FTeff:
                        msgDesc += "Free Throws";
                        msgTeam += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsr.FTMPG, tsr.FTAPG, tsr.FTp,
                                                 _seasonRankings.RankingsPerGame[iTeam][TAbbr.FTeff]);
                        msgOpp += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsropp.FTMPG, tsropp.FTAPG, tsropp.FTp,
                                                _seasonRankings.RankingsPerGame[iOpp][TAbbr.FTeff]);
                        break;
                    default:
                        j++;
                        def = true;
                        break;
                }
                if (!def)
                {
                    used.Add(strengths[m]);
                    msgDesc += "\n";
                    msgTeam += "\n";
                    msgOpp += "\n";
                }
                m++;
            }

            dict = new Dictionary<int, int>();
            for (int k = 0; k < _seasonRankings.RankingsPerGame[iOpp].Length; k++)
            {
                dict.Add(k, _seasonRankings.RankingsPerGame[iOpp][k]);
            }
            dict[TAbbr.FPG] = _tst.Count + 1 - dict[TAbbr.FPG];
            dict[TAbbr.TPG] = _tst.Count + 1 - dict[TAbbr.TPG];
            dict[TAbbr.PAPG] = _tst.Count + 1 - dict[TAbbr.PAPG];
            strengths = (from entry in dict
                         orderby entry.Value ascending
                         select entry.Key).ToList();
            m = 0;
            j = 2;
            while (true)
            {
                if (m == j)
                {
                    break;
                }
                if (used.Contains(strengths[m]))
                {
                    m++;
                    j++;
                    continue;
                }
                bool def = false;
                switch (strengths[m])
                {
                    case TAbbr.APG:
                        msgDesc += "Assists";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.APG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.APG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.APG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.APG]);
                        break;
                    case TAbbr.BPG:
                        msgDesc += "Blocks";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.BPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.BPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.BPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.BPG]);
                        break;
                    case TAbbr.DRPG:
                        msgDesc += "Def. Rebounds";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.DRPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.DRPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.DRPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.DRPG]);
                        break;
                    case TAbbr.FPG:
                        msgDesc += "Fouls";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.FPG,
                                                 _tst.Count - _seasonRankings.RankingsPerGame[iTeam][TAbbr.FPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.FPG,
                                                _tst.Count - _seasonRankings.RankingsPerGame[iOpp][TAbbr.FPG]);
                        break;
                    case TAbbr.ORPG:
                        msgDesc += "Off. Rebounds";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.ORPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.ORPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.ORPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.ORPG]);
                        break;
                    case TAbbr.PAPG:
                        msgDesc += "Points Against";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.PAPG,
                                                 _tst.Count - _seasonRankings.RankingsPerGame[iTeam][TAbbr.PAPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.PAPG,
                                                _tst.Count - _seasonRankings.RankingsPerGame[iOpp][TAbbr.PAPG]);
                        break;
                    case TAbbr.PPG:
                        msgDesc += "Points For";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.PPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.PPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.PPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.PPG]);
                        break;
                    case TAbbr.RPG:
                        msgDesc += "Rebounds";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.RPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.RPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.RPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.RPG]);
                        break;
                    case TAbbr.SPG:
                        msgDesc += "Steals";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.SPG, _seasonRankings.RankingsPerGame[iTeam][TAbbr.SPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.SPG, _seasonRankings.RankingsPerGame[iOpp][TAbbr.SPG]);
                        break;
                    case TAbbr.TPG:
                        msgDesc += "Turnovers";
                        msgTeam += string.Format("{0:F1} ({1})", tsr.TPG,
                                                 _tst.Count - _seasonRankings.RankingsPerGame[iTeam][TAbbr.TPG]);
                        msgOpp += string.Format("{0:F1} ({1})", tsropp.TPG,
                                                _tst.Count - _seasonRankings.RankingsPerGame[iOpp][TAbbr.TPG]);
                        break;
                    case TAbbr.FGeff:
                        msgDesc += "Field Goals";
                        msgTeam += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsr.FGMPG, tsr.FGAPG, tsr.FGp,
                                                 _seasonRankings.RankingsPerGame[iTeam][TAbbr.FGeff]);
                        msgOpp += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsropp.FGMPG, tsropp.FGAPG, tsropp.FGp,
                                                _seasonRankings.RankingsPerGame[iOpp][TAbbr.FGeff]);
                        break;
                    case TAbbr.TPeff:
                        msgDesc += "3 Pointers";
                        msgTeam += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsr.TPMPG, tsr.TPAPG, tsr.TPp,
                                                 _seasonRankings.RankingsPerGame[iTeam][TAbbr.TPeff]);
                        msgOpp += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsropp.TPMPG, tsropp.TPAPG, tsropp.TPp,
                                                _seasonRankings.RankingsPerGame[iOpp][TAbbr.TPeff]);
                        break;
                    case TAbbr.FTeff:
                        msgDesc += "Free Throws";
                        msgTeam += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsr.FTMPG, tsr.FTAPG, tsr.FTp,
                                                 _seasonRankings.RankingsPerGame[iTeam][TAbbr.FTeff]);
                        msgOpp += string.Format("{0:F1}-{1:F1} ({2:F3}) ({3})", tsropp.FTMPG, tsropp.FTAPG, tsropp.FTp,
                                                _seasonRankings.RankingsPerGame[iOpp][TAbbr.FTeff]);
                        break;
                    default:
                        j++;
                        def = true;
                        break;
                }
                if (!def)
                {
                    used.Add(strengths[m]);
                    msgDesc += "\n";
                    msgTeam += "\n";
                    msgOpp += "\n";
                }
                m++;
            }
            string[] descParts = msgDesc.Split('\n');
            string[] teamParts = msgTeam.Split('\n');
            string[] oppParts = msgOpp.Split('\n');
            string s0 = teamParts[0] + "\t" + descParts[0] + "\t" + oppParts[0];
            string s1 = teamParts[1] + "\t" + descParts[1] + "\t" + oppParts[1];
            string s2 = teamParts[2] + "\t" + descParts[2] + "\t" + oppParts[2];
            string s3 = teamParts[3] + "\t" + descParts[3] + "\t" + oppParts[3];
            var list = new List<string> {s0, s1, s2, s3};
            list.Shuffle();
            list.ForEach(item =>
                {
                    string[] parts = item.Split('\t');
                    txbMPTeam.Text += parts[0] + "\n";
                    txbMPDesc.Text += parts[1] + "\n";
                    txbMPOpp.Text += parts[2] + "\n";
                });

            txbMPDesc.Text += "\nG\n\n\nF\n\n\nC\n\n";
            txbMPTeam.Text += "\n" + _teamBestG + "\n" + _teamBestF + "\n" + _teamBestC;
            txbMPOpp.Text += "\n" + _oppBestG + "\n" + _oppBestF + "\n" + _oppBestC;
        }
        /// <summary>Updates the metric stats for the specified team's players.</summary>
        /// <param name="team">1 if the away team's players' metric stats should be updated; anything else for the home team.</param>
        private void updateMetric(int team)
        {
            var ts = new TeamStats(-1, team == 1 ? cmbTeam1.SelectedItem.ToString() : cmbTeam2.SelectedItem.ToString());
            var tsopp = new TeamStats(-1, team == 1 ? cmbTeam2.SelectedItem.ToString() : cmbTeam1.SelectedItem.ToString());

            tryParseBS();
            if (!MainWindow.TempBSE_BS.Done)
            {
                return;
            }

            var bs = MainWindow.TempBSE_BS;

            if (team == 1)
            {
                TeamStats.AddTeamStatsFromBoxScore(bs, ref ts, ref tsopp);
            }
            else
            {
                TeamStats.AddTeamStatsFromBoxScore(bs, ref tsopp, ref ts);
            }

            ts.CalcMetrics(tsopp);
            tsopp.CalcMetrics(ts);
            var ls = new TeamStats(-1);
            ls.AddTeamStats(ts, Span.SeasonAndPlayoffsToSeason);
            ls.AddTeamStats(tsopp, Span.SeasonAndPlayoffsToSeason);

            var pmsrList = new List<PlayerStatsRow>();

            var pbsList = team == 1 ? pbsAwayList : pbsHomeList;

            foreach (var pbs in pbsList)
            {
                if (pbs.PlayerID == -1)
                {
                    continue;
                }

                var ps = _pst[pbs.PlayerID].BinarySerializationClone();
                ps.ResetStats();
                ps.AddBoxScore(pbs, bs.IsPlayoff);
                ps.CalcMetrics(ts, tsopp, ls);
                pmsrList.Add(new PlayerStatsRow(ps));
            }

            pmsrList.Sort((pmsr1, pmsr2) => pmsr1.GmSc.CompareTo(pmsr2.GmSc));
            pmsrList.Reverse();

            var tsr = new TeamStatsRow(ts);

            if (team == 1)
            {
                _psrListAway = new List<PlayerStatsRow>(pmsrList);
                dgvAwayPlayerMetricStats.ItemsSource = _psrListAway;
                dgvAwayTeamMetricStats.ItemsSource = new[] { tsr };
            }
            else
            {
                _psrListHome = new List<PlayerStatsRow>(pmsrList);
                dgvHomePlayerMetricStats.ItemsSource = _psrListHome;
                dgvHomeTeamMetricStats.ItemsSource = new[] { tsr };
            }
        }
 public static void TryChangeTSR(ref TeamStatsRow tsr, Dictionary<string, string> dict)
 {
     tsr.Wins = tsr.Wins.TrySetValue(dict, "Wins", typeof (UInt16));
     tsr.Losses = tsr.Losses.TrySetValue(dict, "Losses", typeof (UInt16));
     tsr.MINS = tsr.MINS.TrySetValue(dict, "MINS", typeof (UInt16));
     tsr.PF = tsr.PF.TrySetValue(dict, "PF", typeof (UInt16));
     tsr.PA = tsr.PF.TrySetValue(dict, "PA", typeof (UInt16));
     tsr.FGM = tsr.FGM.TrySetValue(dict, "FGM", typeof (UInt16));
     tsr.FGA = tsr.FGA.TrySetValue(dict, "FGA", typeof (UInt16));
     tsr.TPM = tsr.TPM.TrySetValue(dict, "3PM", typeof (UInt16));
     tsr.TPA = tsr.TPA.TrySetValue(dict, "3PA", typeof (UInt16));
     tsr.FTM = tsr.FTM.TrySetValue(dict, "FTM", typeof (UInt16));
     tsr.FTA = tsr.FTA.TrySetValue(dict, "FTA", typeof (UInt16));
     tsr.REB = tsr.REB.TrySetValue(dict, "REB", typeof (UInt16));
     tsr.OREB = tsr.OREB.TrySetValue(dict, "OREB", typeof (UInt16));
     tsr.DREB = tsr.DREB.TrySetValue(dict, "DREB", typeof (UInt16));
     tsr.AST = tsr.AST.TrySetValue(dict, "AST", typeof (UInt16));
     tsr.TOS = tsr.TOS.TrySetValue(dict, "TO", typeof (UInt16));
     tsr.STL = tsr.STL.TrySetValue(dict, "STL", typeof (UInt16));
     tsr.BLK = tsr.BLK.TrySetValue(dict, "BLK", typeof (UInt16));
     tsr.FOUL = tsr.FOUL.TrySetValue(dict, "FOUL", typeof (UInt16));
 }
 public static void Refresh(ref TeamStatsRow tsr)
 {
     tsr = new TeamStatsRow(new TeamStats(tsr));
 }