/// <summary>Calculates the metrics of a player's performance.</summary>
        /// <param name="r">
        ///     The SQLite DataRow containing the player's box score. Should be the result of an INNER JOIN'ed query between
        ///     PlayerResults and GameResults.
        /// </param>
        public void CalcMetrics(DataRow r)
        {
            var bs = new TeamBoxScore(r, null);

            var ts = new TeamStats(TeamID);
            var tsopp = new TeamStats(OppTeamID);

            var team1ID = ParseCell.GetInt32(r, "Team1ID");
            var team2ID = ParseCell.GetInt32(r, "Team2ID");

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

            var ps = new PlayerStats { ID = PlayerID };
            ps.AddBoxScore(this, bs.IsPlayoff);
            ps.CalcMetrics(ts, tsopp, new TeamStats(-1), GmScOnly: true);

            GmSc = ps.Metrics["GmSc"];
            GmScE = ps.Metrics["GmScE"];
        }
        /// <summary>Calculates the metrics of a player's performance.</summary>
        /// <param name="bs">The game's box score from which to calculate the metrics.</param>
        public void CalcMetrics(TeamBoxScore bs)
        {
            var ts = new TeamStats(TeamID);
            var tsopp = new TeamStats(OppTeamID);

            var team1ID = bs.Team1ID;

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

            var ps = new PlayerStats { ID = PlayerID };
            ps.AddBoxScore(this, bs.IsPlayoff);
            ps.CalcMetrics(ts, tsopp, new TeamStats(-1), GmScOnly: true);

            GmSc = ps.Metrics["GmSc"];
            GmScE = ps.Metrics["GmScE"];
        }
        /// <summary>
        ///     Calculates the league PerGame.
        /// </summary>
        /// <param name="playerStats">The player stats.</param>
        /// <param name="teamStats">The team stats.</param>
        /// <returns></returns>
        public static PlayerStats CalculateLeagueAverages(Dictionary<int, PlayerStats> playerStats,
                                                          Dictionary<int, TeamStats> teamStats)
        {
            var lps = new PlayerStats(new Player(-1, -1, "League", "Averages", Position.None, Position.None));
            foreach (int key in playerStats.Keys)
            {
                lps.AddPlayerStats(playerStats[key]);
            }

            var ls = new TeamStats(-2, "League");
            for (int i = 0; i < teamStats.Count; i++)
            {
                ls.AddTeamStats(teamStats[i], Span.Season);
                ls.AddTeamStats(teamStats[i], Span.Playoffs);
            }
            ls.CalcMetrics(ls);
            ls.CalcMetrics(ls, true);
            lps.CalcMetrics(ls, ls, ls, true);
            lps.CalcMetrics(ls, ls, ls, true, playoffs: true);

            var playerCount = (uint) playerStats.Count;
            for (int i = 0; i < lps.Totals.Length; i++)
            {
                lps.Totals[i] /= playerCount;
                lps.PlTotals[i] /= playerCount;
            }
            //ps.CalcAvg();
            return lps;
        }