/// <summary>Updates the box score data grid.</summary>
        /// <param name="teamID">Name of the team.</param>
        /// <param name="playersList">The players list.</param>
        /// <param name="pbsList">The player box score list.</param>
        /// <param name="loading">
        ///     if set to <c>true</c>, it is assumed that a pre-existing box score is being loaded.
        /// </param>
        private static void updateBoxScoreDataGrid(
            int teamID,
            out ObservableCollection<KeyValuePair<int, string>> playersList,
            ref SortableBindingList<PlayerBoxScore> pbsList,
            bool loading)
        {
            var list = MainWindow.PST.Where(ps => ps.Value.TeamF == teamID).ToDictionary(ps => ps.Key, ps => ps.Value);

            playersList = new ObservableCollection<KeyValuePair<int, string>>();
            if (!loading)
            {
                pbsList = new SortableBindingList<PlayerBoxScore>();
            }

            foreach (var ps in list.Values)
            {
                playersList.Add(new KeyValuePair<int, string>(ps.ID, ps.FullName));
                if (!loading)
                {
                    var pbs = new PlayerBoxScore { PlayerID = ps.ID, TeamID = teamID };
                    pbsList.Add(pbs);
                }
            }

            for (var i = 0; i < pbsList.Count; i++)
            {
                var cur = pbsList[i];
                var name = MainWindow.PST[cur.PlayerID].FullName;
                var player = new KeyValuePair<int, string>(cur.PlayerID, name);
                cur.Name = name;
                if (!playersList.Contains(player))
                {
                    playersList.Add(player);
                }
                pbsList[i] = cur;
            }
            playersList = new ObservableCollection<KeyValuePair<int, string>>(playersList.OrderBy(item => item.Value));
        }
Пример #2
0
        /// <summary>
        ///     Creates a team box score and all the required player box score instances using data from the downloaded DataSet.
        /// </summary>
        /// <param name="ds">The DataSet.</param>
        /// <param name="parts">The parts of the split date string.</param>
        /// <param name="bse">The resulting BoxScoreEntry.</param>
        /// <returns>0 if every required player was found in the database; otherwise, -1.</returns>
        private static int boxScoreFromDataSet(DataSet ds, string[] parts, out BoxScoreEntry bse)
        {
            DataTable awayDT = ds.Tables[0];
            DataTable homeDT = ds.Tables[1];

            var bs = new TeamBoxScore(ds, parts);
            bse = new BoxScoreEntry(bs) {Date = bs.GameDate, PBSList = new List<PlayerBoxScore>()};
            int result = 0;
            for (int i = 0; i < awayDT.Rows.Count - 1; i++)
            {
                if (i == 5)
                {
                    continue;
                }
                var pbs = new PlayerBoxScore(awayDT.Rows[i], bs.Team1ID, bs.ID, (i < 5), MainWindow.PST);
                if (pbs.PlayerID == -1)
                {
                    result = -1;
                    continue;
                }
                bse.PBSList.Add(pbs);
            }
            for (int i = 0; i < homeDT.Rows.Count - 1; i++)
            {
                if (i == 5)
                {
                    continue;
                }
                var pbs = new PlayerBoxScore(homeDT.Rows[i], bs.Team2ID, bs.ID, (i < 5), MainWindow.PST);
                if (pbs.PlayerID == -1)
                {
                    result = -1;
                    continue;
                }
                bse.PBSList.Add(pbs);
            }
            return result;
        }
        /// <summary>Calculates the best performers from each team, and their most significant stats.</summary>
        private void updateBest()
        {
            try
            {
                if (_psrListAway.Count == 0 && _psrListHome.Count == 0)
                {
                    return;
                }

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

                _psrListHome.Sort((pmsr1, pmsr2) => pmsr1.GmSc.CompareTo(pmsr2.GmSc));
                _psrListHome.Reverse();
            }
            catch (Exception)
            {
                return;
            }

            string teamBest;
            int awayid, homeid;
            var pbsBest = new PlayerBoxScore();
            PlayerBoxScore pbsAway1 = new PlayerBoxScore(),
                           pbsAway2 = new PlayerBoxScore(),
                           pbsAway3 = new PlayerBoxScore(),
                           pbsHome1 = new PlayerBoxScore(),
                           pbsHome2 = new PlayerBoxScore(),
                           pbsHome3 = new PlayerBoxScore();

            txbMVP.Text = "";
            txbMVPStats.Text = "";
            txbAway1.Text = "";
            txbAway2.Text = "";
            txbAway3.Text = "";
            txbHome1.Text = "";
            txbHome2.Text = "";
            txbHome3.Text = "";

            var skipaway = _psrListAway.Count == 0;
            var skiphome = _psrListHome.Count == 0;

            //if (skiphome || (!skipaway && pmsrListAway[0].GmSc > pmsrListHome[0].GmSc))
            if (skiphome || (!skipaway && Convert.ToInt32(txtPTS1.Text) > Convert.ToInt32(txtPTS2.Text)))
            {
                var bestID = _psrListAway[0].ID;
                foreach (var pbs in pbsAwayList)
                {
                    if (pbs.PlayerID == bestID)
                    {
                        pbsBest = pbs;
                    }
                }
                teamBest = cmbTeam1.SelectedItem.ToString();
                awayid = 1;
                homeid = 0;
            }
            else
            {
                var bestID = _psrListHome[0].ID;
                foreach (var pbs in pbsHomeList)
                {
                    if (pbs.PlayerID == bestID)
                    {
                        pbsBest = pbs;
                    }
                }
                teamBest = cmbTeam2.SelectedItem.ToString();
                awayid = 0;
                homeid = 1;
            }

            var ps = _pst[pbsBest.PlayerID];
            var text = pbsBest.GetBestStats(5, ps.Position1);
            txbMVP.Text = ps.FirstName + " " + ps.LastName + " (" + ps.Position1 + ")";
            txbMVPStats.Text = teamBest + "\n\n" + text;

            if (_psrListAway.Count > awayid)
            {
                var id2 = _psrListAway[awayid++].ID;
                foreach (var pbs in pbsAwayList)
                {
                    if (pbs.PlayerID == id2)
                    {
                        pbsAway1 = pbs;
                    }
                }

                ps = _pst[pbsAway1.PlayerID];
                text = pbsAway1.GetBestStats(5, ps.Position1);
                txbAway1.Text = ps.FirstName + " " + ps.LastName + " (" + ps.Position1 + ")\n\n" + text;
            }

            if (_psrListAway.Count > awayid)
            {
                var id3 = _psrListAway[awayid++].ID;
                foreach (var pbs in pbsAwayList)
                {
                    if (pbs.PlayerID == id3)
                    {
                        pbsAway2 = pbs;
                    }
                }

                ps = _pst[pbsAway2.PlayerID];
                text = pbsAway2.GetBestStats(5, ps.Position1);
                txbAway2.Text = ps.FirstName + " " + ps.LastName + " (" + ps.Position1 + ")\n\n" + text;
            }

            if (_psrListAway.Count > awayid)
            {
                var id4 = _psrListAway[awayid++].ID;
                foreach (var pbs in pbsAwayList)
                {
                    if (pbs.PlayerID == id4)
                    {
                        pbsAway3 = pbs;
                    }
                }

                ps = _pst[pbsAway3.PlayerID];
                text = pbsAway3.GetBestStats(5, ps.Position1);
                txbAway3.Text = ps.FirstName + " " + ps.LastName + " (" + ps.Position1 + ")\n\n" + text;
            }

            if (_psrListHome.Count > homeid)
            {
                var id2 = _psrListHome[homeid++].ID;
                foreach (var pbs in pbsHomeList)
                {
                    if (pbs.PlayerID == id2)
                    {
                        pbsHome1 = pbs;
                    }
                }

                ps = _pst[pbsHome1.PlayerID];
                text = pbsHome1.GetBestStats(5, ps.Position1);
                txbHome1.Text = ps.FirstName + " " + ps.LastName + " (" + ps.Position1 + ")\n\n" + text;
            }

            if (_psrListHome.Count > homeid)
            {
                var id3 = _psrListHome[homeid++].ID;
                foreach (var pbs in pbsHomeList)
                {
                    if (pbs.PlayerID == id3)
                    {
                        pbsHome2 = pbs;
                    }
                }

                ps = _pst[pbsHome2.PlayerID];
                text = pbsHome2.GetBestStats(5, ps.Position1);
                txbHome2.Text = ps.FirstName + " " + ps.LastName + " (" + ps.Position1 + ")\n\n" + text;
            }

            if (_psrListHome.Count > homeid)
            {
                var id4 = _psrListHome[homeid++].ID;
                foreach (var pbs in pbsHomeList)
                {
                    if (pbs.PlayerID == id4)
                    {
                        pbsHome3 = pbs;
                    }
                }

                ps = _pst[pbsHome3.PlayerID];
                text = pbsHome3.GetBestStats(5, ps.Position1);
                txbHome3.Text = ps.FirstName + " " + ps.LastName + " (" + ps.Position1 + ")\n\n" + text;
            }
        }
Пример #4
0
        /// <summary>Adds a player's box score to their stats.</summary>
        /// <param name="pbs">The Player Box Score.</param>
        /// <param name="isPlayoff">
        ///     if set to <c>true</c>, the stats are added to the playoff stats.
        /// </param>
        /// <exception cref="System.Exception">Occurs when the player IDs from the stats and box score do not match.</exception>
        public void AddBoxScore(PlayerBoxScore pbs, bool isPlayoff = false)
        {
            if (ID != pbs.PlayerID)
            {
                throw new Exception("Tried to update PlayerStats " + ID + " with PlayerBoxScore " + pbs.PlayerID);
            }

            if (!isPlayoff)
            {
                if (pbs.IsStarter)
                {
                    Totals[PAbbrT.GS]++;
                }
                if (pbs.MINS > 0)
                {
                    Totals[PAbbrT.GP]++;
                    Totals[PAbbrT.MINS] += pbs.MINS;
                }
                Totals[PAbbrT.PTS] += pbs.PTS;
                Totals[PAbbrT.FGM] += pbs.FGM;
                Totals[PAbbrT.FGA] += pbs.FGA;
                Totals[PAbbrT.TPM] += pbs.TPM;
                Totals[PAbbrT.TPA] += pbs.TPA;
                Totals[PAbbrT.FTM] += pbs.FTM;
                Totals[PAbbrT.FTA] += pbs.FTA;
                Totals[PAbbrT.OREB] += pbs.OREB;
                Totals[PAbbrT.DREB] += pbs.DREB;
                Totals[PAbbrT.STL] += pbs.STL;
                Totals[PAbbrT.TOS] += pbs.TOS;
                Totals[PAbbrT.BLK] += pbs.BLK;
                Totals[PAbbrT.AST] += pbs.AST;
                Totals[PAbbrT.FOUL] += pbs.FOUL;
            }
            else
            {
                if (pbs.IsStarter)
                {
                    PlTotals[PAbbrT.GS]++;
                }
                if (pbs.MINS > 0)
                {
                    PlTotals[PAbbrT.GP]++;
                    PlTotals[PAbbrT.MINS] += pbs.MINS;
                }
                PlTotals[PAbbrT.PTS] += pbs.PTS;
                PlTotals[PAbbrT.FGM] += pbs.FGM;
                PlTotals[PAbbrT.FGA] += pbs.FGA;
                PlTotals[PAbbrT.TPM] += pbs.TPM;
                PlTotals[PAbbrT.TPA] += pbs.TPA;
                PlTotals[PAbbrT.FTM] += pbs.FTM;
                PlTotals[PAbbrT.FTA] += pbs.FTA;
                PlTotals[PAbbrT.OREB] += pbs.OREB;
                PlTotals[PAbbrT.DREB] += pbs.DREB;
                PlTotals[PAbbrT.STL] += pbs.STL;
                PlTotals[PAbbrT.TOS] += pbs.TOS;
                PlTotals[PAbbrT.BLK] += pbs.BLK;
                PlTotals[PAbbrT.AST] += pbs.AST;
                PlTotals[PAbbrT.FOUL] += pbs.FOUL;
            }

            CalcAvg();
        }
Пример #5
0
        /// <summary>
        ///     Calculates the box score by comparing the participating team's current and previous team and player stats.
        /// </summary>
        /// <param name="tst">The team stats dictionary.</param>
        /// <param name="oldTST">The old team stats dictionary.</param>
        /// <param name="pst">The player stats dictionary.</param>
        /// <param name="oldPST">The old player stats dictionary.</param>
        /// <param name="t1">The away team ID.</param>
        /// <param name="t2">The home team ID.</param>
        /// <returns></returns>
        private static BoxScoreEntry prepareBoxScore(Dictionary<int, TeamStats> tst, Dictionary<int, TeamStats> oldTST,
                                                     Dictionary<int, PlayerStats> pst, Dictionary<int, PlayerStats> oldPST, int t1,
                                                     int t2)
        {
            bool isPlayoff = (tst[t1].GetPlayoffGames() > 0);
            var bs = new TeamBoxScore
                {
                    IsPlayoff = isPlayoff,
                    Team1ID = t1,
                    MINS1 = getDiff(tst, oldTST, t1, TAbbr.MINS, isPlayoff),
                    Team2ID = t2,
                    MINS2 = getDiff(tst, oldTST, t2, TAbbr.MINS, isPlayoff)
                };

            var bse = new BoxScoreEntry(bs) {PBSList = new List<PlayerBoxScore>()};

            /*
                        var team1Players = pst.Where(pair => pair.Value.TeamF == bs.Team1);
                        var team2Players = pst.Where(pair => pair.Value.TeamF == bs.Team2);
                        */

            IEnumerable<KeyValuePair<int, PlayerStats>> bothTeamsPlayers =
                pst.Where(pair => pair.Value.TeamF == bs.Team1ID || pair.Value.TeamF == bs.Team2ID);
            foreach (var playerKVP in bothTeamsPlayers)
            {
                KeyValuePair<int, PlayerStats> oldplayerKVP = oldPST.Single(pair => pair.Value.ID == playerKVP.Value.ID);

                PlayerStats newPlayer = playerKVP.Value;
                PlayerStats oldPlayer = oldplayerKVP.Value;

                PlayerBoxScore pbs;
                if (getDiff(newPlayer, oldPlayer, PAbbr.GP) == 1)
                {
                    pbs = new PlayerBoxScore
                        {
                            PlayerID = newPlayer.ID,
                            TeamID = newPlayer.TeamF,
                            IsStarter = (getDiff(newPlayer, oldPlayer, PAbbr.GS) == 1),
                            PlayedInjured = newPlayer.Injury.IsInjured,
                            MINS = getDiff(newPlayer, oldPlayer, PAbbr.MINS),
                            PTS = getDiff(newPlayer, oldPlayer, PAbbr.PTS),
                            OREB = getDiff(newPlayer, oldPlayer, PAbbr.OREB),
                            DREB = getDiff(newPlayer, oldPlayer, PAbbr.DREB),
                            AST = getDiff(newPlayer, oldPlayer, PAbbr.AST),
                            STL = getDiff(newPlayer, oldPlayer, PAbbr.STL),
                            BLK = getDiff(newPlayer, oldPlayer, PAbbr.BLK),
                            TOS = getDiff(newPlayer, oldPlayer, PAbbr.TOS),
                            FGM = getDiff(newPlayer, oldPlayer, PAbbr.FGM),
                            FGA = getDiff(newPlayer, oldPlayer, PAbbr.FGA),
                            TPM = getDiff(newPlayer, oldPlayer, PAbbr.TPM),
                            TPA = getDiff(newPlayer, oldPlayer, PAbbr.TPA),
                            FTM = getDiff(newPlayer, oldPlayer, PAbbr.FTM),
                            FTA = getDiff(newPlayer, oldPlayer, PAbbr.FTA),
                            FOUL = getDiff(newPlayer, oldPlayer, PAbbr.FOUL)
                        };
                    pbs.REB = (ushort) (pbs.OREB + pbs.DREB);
                    pbs.FGp = (float) pbs.FGM/pbs.FGA;
                    pbs.TPp = (float) pbs.TPM/pbs.TPA;
                    pbs.FTp = (float) pbs.FTM/pbs.FTA;
                }
                else
                {
                    pbs = new PlayerBoxScore {PlayerID = newPlayer.ID, TeamID = newPlayer.TeamF, IsOut = true};
                }

                bse.PBSList.Add(pbs);
            }
            bse.Date = DateTime.Today;
            bse.BS.GameDate = bse.Date;
            bse.BS.SeasonNum = MainWindow.CurSeason;

            return bse;
        }
        /// <summary>
        ///     Updates the overview tab and prepares the available box scores for the current timeframe.
        /// </summary>
        private void updateOverviewAndBoxScores()
        {
            TeamStats ts = _psr.IsActive ? MainWindow.TST[_psr.TeamF] : new TeamStats();
            var tsopp = new TeamStats(ts.ID, "Opponents");

            grdOverview.DataContext = _psr;

            _playersSamePosition =
                MainWindow.PST.Where(ps => ps.Value.Position1 == _psr.Position1 && ps.Value.IsActive)
                          .ToDictionary(ps => ps.Value.ID, ps => ps.Value);

            _rankingsPosition = new PlayerRankings(_playersSamePosition);
            _plRankingsPosition = new PlayerRankings(_playersSamePosition, true);

            foreach (
                BoxScoreEntry bse in
                    MainWindow.BSHist.Where(bse => bse.PBSList.Any(pbs => pbs.PlayerID == _psr.ID && !pbs.IsOut)).ToList())
            {
                var pbs = new PlayerBoxScore();
                pbs = bse.PBSList.Single(pbs1 => pbs1.PlayerID == _psr.ID);
                pbs.AddInfoFromTeamBoxScore(bse.BS, MainWindow.TST);
                pbs.CalcMetrics(bse.BS);
                _pbsList.Add(pbs);
            }

            cmbPosition1.SelectedItem = _psr.Position1.ToString();
            cmbPosition2.SelectedItem = _psr.Position2.ToString();

            _dtOv.Clear();

            DataRow dr = _dtOv.NewRow();

            dr["Type"] = "Stats";
            dr["GP"] = _psr.GP.ToString();
            dr["GS"] = _psr.GS.ToString();
            dr["MINS"] = _psr.MINS.ToString();
            dr["PTS"] = _psr.PTS.ToString();
            dr["FG"] = _psr.FGM.ToString() + "-" + _psr.FGA.ToString();
            dr["3PT"] = _psr.TPM.ToString() + "-" + _psr.TPA.ToString();
            dr["FT"] = _psr.FTM.ToString() + "-" + _psr.FTA.ToString();
            dr["REB"] = (_psr.DREB + _psr.OREB).ToString();
            dr["OREB"] = _psr.OREB.ToString();
            dr["DREB"] = _psr.DREB.ToString();
            dr["AST"] = _psr.AST.ToString();
            dr["TO"] = _psr.TOS.ToString();
            dr["STL"] = _psr.STL.ToString();
            dr["BLK"] = _psr.BLK.ToString();
            dr["FOUL"] = _psr.FOUL.ToString();

            _dtOv.Rows.Add(dr);

            dr = _dtOv.NewRow();

            dr["Type"] = "Averages";
            dr["MINS"] = String.Format("{0:F1}", _psr.MPG);
            dr["PTS"] = String.Format("{0:F1}", _psr.PPG);
            dr["FG"] = String.Format("{0:F3}", _psr.FGp);
            dr["FGeff"] = String.Format("{0:F2}", _psr.FGeff);
            dr["3PT"] = String.Format("{0:F3}", _psr.TPp);
            dr["3Peff"] = String.Format("{0:F2}", _psr.TPeff);
            dr["FT"] = String.Format("{0:F3}", _psr.FTp);
            dr["FTeff"] = String.Format("{0:F2}", _psr.FTeff);
            dr["REB"] = String.Format("{0:F1}", _psr.RPG);
            dr["OREB"] = String.Format("{0:F1}", _psr.ORPG);
            dr["DREB"] = String.Format("{0:F1}", _psr.DRPG);
            dr["AST"] = String.Format("{0:F1}", _psr.APG);
            dr["TO"] = String.Format("{0:F1}", _psr.TPG);
            dr["STL"] = String.Format("{0:F1}", _psr.SPG);
            dr["BLK"] = String.Format("{0:F1}", _psr.BPG);
            dr["FOUL"] = String.Format("{0:F1}", _psr.FPG);

            _dtOv.Rows.Add(dr);

            #region Rankings

            if (_psr.IsActive)
            {
                int id = _selectedPlayerID;

                dr = _dtOv.NewRow();

                dr["Type"] = "Rankings";
                dr["MINS"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.MPG]);
                dr["PTS"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.PPG]);
                dr["FG"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.FGp]);
                dr["FGeff"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.FGeff]);
                dr["3PT"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.TPp]);
                dr["3Peff"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.TPeff]);
                dr["FT"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.FTp]);
                dr["FTeff"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.FTeff]);
                dr["REB"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.RPG]);
                dr["OREB"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.ORPG]);
                dr["DREB"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.DRPG]);
                dr["AST"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][TAbbr.PAPG]);
                dr["TO"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.TPG]);
                dr["STL"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.SPG]);
                dr["BLK"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.BPG]);
                dr["FOUL"] = String.Format("{0}", _rankingsActive.RankingsPerGame[id][PAbbr.FPG]);

                _dtOv.Rows.Add(dr);

                dr = _dtOv.NewRow();

                dr["Type"] = "In-team Rankings";
                dr["MINS"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.MPG]);
                dr["PTS"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.PPG]);
                dr["FG"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.FGp]);
                dr["FGeff"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.FGeff]);
                dr["3PT"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.TPp]);
                dr["3Peff"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.TPeff]);
                dr["FT"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.FTp]);
                dr["FTeff"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.FTeff]);
                dr["REB"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.RPG]);
                dr["OREB"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.ORPG]);
                dr["DREB"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.DRPG]);
                dr["AST"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][TAbbr.PAPG]);
                dr["TO"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.TPG]);
                dr["STL"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.SPG]);
                dr["BLK"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.BPG]);
                dr["FOUL"] = String.Format("{0}", _rankingsTeam.RankingsPerGame[id][PAbbr.FPG]);

                _dtOv.Rows.Add(dr);

                dr = _dtOv.NewRow();

                dr["Type"] = "Position Rankings";
                dr["MINS"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.MPG]);
                dr["PTS"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.PPG]);
                dr["FG"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.FGp]);
                dr["FGeff"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.FGeff]);
                dr["3PT"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.TPp]);
                dr["3Peff"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.TPeff]);
                dr["FT"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.FTp]);
                dr["FTeff"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.FTeff]);
                dr["REB"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.RPG]);
                dr["OREB"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.ORPG]);
                dr["DREB"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.DRPG]);
                dr["AST"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][TAbbr.PAPG]);
                dr["TO"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.TPG]);
                dr["STL"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.SPG]);
                dr["BLK"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.BPG]);
                dr["FOUL"] = String.Format("{0}", _rankingsPosition.RankingsPerGame[id][PAbbr.FPG]);

                _dtOv.Rows.Add(dr);

                dr = _dtOv.NewRow();

                dr["Type"] = "Team Avg";
                dr["PTS"] = String.Format("{0:F1}", ts.PerGame[TAbbr.PPG]);
                dr["FG"] = String.Format("{0:F3}", ts.PerGame[TAbbr.FGp]);
                dr["FGeff"] = String.Format("{0:F2}", ts.PerGame[TAbbr.FGeff]);
                dr["3PT"] = String.Format("{0:F3}", ts.PerGame[TAbbr.TPp]);
                dr["3Peff"] = String.Format("{0:F2}", ts.PerGame[TAbbr.TPeff]);
                dr["FT"] = String.Format("{0:F3}", ts.PerGame[TAbbr.FTp]);
                dr["FTeff"] = String.Format("{0:F2}", ts.PerGame[TAbbr.FTeff]);
                dr["REB"] = String.Format("{0:F1}", ts.PerGame[TAbbr.RPG]);
                dr["OREB"] = String.Format("{0:F1}", ts.PerGame[TAbbr.ORPG]);
                dr["DREB"] = String.Format("{0:F1}", ts.PerGame[TAbbr.DRPG]);
                dr["AST"] = String.Format("{0:F1}", ts.PerGame[TAbbr.APG]);
                dr["TO"] = String.Format("{0:F1}", ts.PerGame[TAbbr.TPG]);
                dr["STL"] = String.Format("{0:F1}", ts.PerGame[TAbbr.SPG]);
                dr["BLK"] = String.Format("{0:F1}", ts.PerGame[TAbbr.BPG]);
                dr["FOUL"] = String.Format("{0:F1}", ts.PerGame[TAbbr.FPG]);

                _dtOv.Rows.Add(dr);
            }

            #endregion

            dr = _dtOv.NewRow();

            dr["Type"] = " ";

            _dtOv.Rows.Add(dr);

            #region Playoffs

            dr = _dtOv.NewRow();

            dr["Type"] = "Pl Stats";
            dr["GP"] = _plPSR.GP.ToString();
            dr["GS"] = _plPSR.GS.ToString();
            dr["MINS"] = _plPSR.MINS.ToString();
            dr["PTS"] = _plPSR.PTS.ToString();
            dr["FG"] = _plPSR.FGM.ToString() + "-" + _plPSR.FGA.ToString();
            dr["3PT"] = _plPSR.TPM.ToString() + "-" + _plPSR.TPA.ToString();
            dr["FT"] = _plPSR.FTM.ToString() + "-" + _plPSR.FTA.ToString();
            dr["REB"] = (_plPSR.DREB + _plPSR.OREB).ToString();
            dr["OREB"] = _plPSR.OREB.ToString();
            dr["DREB"] = _plPSR.DREB.ToString();
            dr["AST"] = _plPSR.AST.ToString();
            dr["TO"] = _plPSR.TOS.ToString();
            dr["STL"] = _plPSR.STL.ToString();
            dr["BLK"] = _plPSR.BLK.ToString();
            dr["FOUL"] = _plPSR.FOUL.ToString();

            _dtOv.Rows.Add(dr);

            dr = _dtOv.NewRow();

            dr["Type"] = "Pl Avg";
            dr["MINS"] = String.Format("{0:F1}", _plPSR.MPG);
            dr["PTS"] = String.Format("{0:F1}", _plPSR.PPG);
            dr["FG"] = String.Format("{0:F3}", _plPSR.FGp);
            dr["FGeff"] = String.Format("{0:F2}", _plPSR.FGeff);
            dr["3PT"] = String.Format("{0:F3}", _plPSR.TPp);
            dr["3Peff"] = String.Format("{0:F2}", _plPSR.TPeff);
            dr["FT"] = String.Format("{0:F3}", _plPSR.FTp);
            dr["FTeff"] = String.Format("{0:F2}", _plPSR.FTeff);
            dr["REB"] = String.Format("{0:F1}", _plPSR.RPG);
            dr["OREB"] = String.Format("{0:F1}", _plPSR.ORPG);
            dr["DREB"] = String.Format("{0:F1}", _plPSR.DRPG);
            dr["AST"] = String.Format("{0:F1}", _plPSR.APG);
            dr["TO"] = String.Format("{0:F1}", _plPSR.TPG);
            dr["STL"] = String.Format("{0:F1}", _plPSR.SPG);
            dr["BLK"] = String.Format("{0:F1}", _plPSR.BPG);
            dr["FOUL"] = String.Format("{0:F1}", _plPSR.FPG);

            _dtOv.Rows.Add(dr);

            #region Rankings

            if (_psr.IsActive)
            {
                int id = Convert.ToInt32(_selectedPlayerID);

                dr = _dtOv.NewRow();

                dr["Type"] = "Pl Rank";
                dr["MINS"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.MPG]);
                dr["PTS"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.PPG]);
                dr["FG"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.FGp]);
                dr["FGeff"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.FGeff]);
                dr["3PT"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.TPp]);
                dr["3Peff"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.TPeff]);
                dr["FT"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.FTp]);
                dr["FTeff"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.FTeff]);
                dr["REB"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.RPG]);
                dr["OREB"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.ORPG]);
                dr["DREB"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.DRPG]);
                dr["AST"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][TAbbr.PAPG]);
                dr["TO"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.TPG]);
                dr["STL"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.SPG]);
                dr["BLK"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.BPG]);
                dr["FOUL"] = String.Format("{0}", _plRankingsActive.RankingsPerGame[id][PAbbr.FPG]);

                _dtOv.Rows.Add(dr);

                dr = _dtOv.NewRow();

                dr["Type"] = "Pl In-Team";
                dr["MINS"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.MPG]);
                dr["PTS"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.PPG]);
                dr["FG"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.FGp]);
                dr["FGeff"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.FGeff]);
                dr["3PT"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.TPp]);
                dr["3Peff"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.TPeff]);
                dr["FT"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.FTp]);
                dr["FTeff"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.FTeff]);
                dr["REB"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.RPG]);
                dr["OREB"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.ORPG]);
                dr["DREB"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.DRPG]);
                dr["AST"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][TAbbr.PAPG]);
                dr["TO"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.TPG]);
                dr["STL"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.SPG]);
                dr["BLK"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.BPG]);
                dr["FOUL"] = String.Format("{0}", _plRankingsTeam.RankingsPerGame[id][PAbbr.FPG]);

                _dtOv.Rows.Add(dr);

                dr = _dtOv.NewRow();

                dr["Type"] = "Pl Position";
                dr["MINS"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.MPG]);
                dr["PTS"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.PPG]);
                dr["FG"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.FGp]);
                dr["FGeff"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.FGeff]);
                dr["3PT"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.TPp]);
                dr["3Peff"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.TPeff]);
                dr["FT"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.FTp]);
                dr["FTeff"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.FTeff]);
                dr["REB"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.RPG]);
                dr["OREB"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.ORPG]);
                dr["DREB"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.DRPG]);
                dr["AST"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][TAbbr.PAPG]);
                dr["TO"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.TPG]);
                dr["STL"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.SPG]);
                dr["BLK"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.BPG]);
                dr["FOUL"] = String.Format("{0}", _plRankingsPosition.RankingsPerGame[id][PAbbr.FPG]);

                _dtOv.Rows.Add(dr);

                dr = _dtOv.NewRow();

                dr["Type"] = "Pl Team Avg";
                dr["PTS"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.PPG]);
                dr["FG"] = String.Format("{0:F3}", ts.PlPerGame[TAbbr.FGp]);
                dr["FGeff"] = String.Format("{0:F2}", ts.PlPerGame[TAbbr.FGeff]);
                dr["3PT"] = String.Format("{0:F3}", ts.PlPerGame[TAbbr.TPp]);
                dr["3Peff"] = String.Format("{0:F2}", ts.PlPerGame[TAbbr.TPeff]);
                dr["FT"] = String.Format("{0:F3}", ts.PlPerGame[TAbbr.FTp]);
                dr["FTeff"] = String.Format("{0:F2}", ts.PlPerGame[TAbbr.FTeff]);
                dr["REB"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.RPG]);
                dr["OREB"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.ORPG]);
                dr["DREB"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.DRPG]);
                dr["AST"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.APG]);
                dr["TO"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.TPG]);
                dr["STL"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.SPG]);
                dr["BLK"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.BPG]);
                dr["FOUL"] = String.Format("{0:F1}", ts.PlPerGame[TAbbr.FPG]);

                _dtOv.Rows.Add(dr);
            }

            #endregion

            #endregion

            var dvOv = new DataView(_dtOv) {AllowNew = false};

            dgvOverviewStats.DataContext = dvOv;

            #region Prepare Box Scores

            dgvBoxScores.ItemsSource = _pbsList;
            updateBest();
            cmbGraphStat_SelectionChanged(null, null);

            #endregion
        }
        /// <summary>
        ///     Updates the box score data grid.
        /// </summary>
        /// <param name="teamID">Name of the team.</param>
        /// <param name="playersList">The players list.</param>
        /// <param name="pbsList">The player box score list.</param>
        /// <param name="playersT">The players' SQLite table name.</param>
        /// <param name="loading">
        ///     if set to <c>true</c>, it is assumed that a pre-existing box score is being loaded.
        /// </param>
        private static void updateBoxScoreDataGrid(int teamID, out ObservableCollection<KeyValuePair<int, string>> playersList,
                                                   ref SortableBindingList<PlayerBoxScore> pbsList, string playersT, bool loading)
        {
            var db = new SQLiteDatabase(MainWindow.CurrentDB);
            string q = "select * from " + playersT + " where TeamFin = " + teamID + "";
            q += " ORDER BY LastName ASC";
            DataTable res = db.GetDataTable(q);

            playersList = new ObservableCollection<KeyValuePair<int, string>>();
            if (!loading)
            {
                pbsList = new SortableBindingList<PlayerBoxScore>();
            }

            foreach (DataRow r in res.Rows)
            {
                var ps = new PlayerStats(r, MainWindow.TST);
                playersList.Add(new KeyValuePair<int, string>(ps.ID, ps.LastName + ", " + ps.FirstName));
                if (!loading)
                {
                    var pbs = new PlayerBoxScore {PlayerID = ps.ID, TeamID = teamID};
                    pbsList.Add(pbs);
                }
            }

            for (int i = 0; i < pbsList.Count; i++)
            {
                PlayerBoxScore cur = pbsList[i];
                string name = MainWindow.PST[cur.PlayerID].LastName + ", " + MainWindow.PST[cur.PlayerID].FirstName;
                var player = new KeyValuePair<int, string>(cur.PlayerID, name);
                cur.Name = name;
                if (!playersList.Contains(player))
                {
                    playersList.Add(player);
                }
                pbsList[i] = cur;
            }
            playersList = new ObservableCollection<KeyValuePair<int, string>>(playersList.OrderBy(item => item.Value));
        }