public PlayerInjuryWindow(PlayerInjury injury)
     : this()
 {
     if (injury.InjuryType != -1)
     {
         cmbInjuryType.SelectedItem = injury.InjuryName;
     }
     else
     {
         cmbInjuryType.SelectedItem = "Custom";
         txtCustomInjuryName.Text = injury.CustomInjuryName;
     }
     cmbTFApproximateAmount.SelectedItem = injury.ApproximateDays;
     cmbTFExactType.SelectedItem = "Days";
     txtTFExactAmount.Text = injury.InjuryDaysLeft.ToString();
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PlayerStats" /> class.
        /// </summary>
        public PlayerStats()
        {
            for (var i = 0; i < Totals.Length; i++)
            {
                Totals[i] = 0;
            }

            for (var i = 0; i < PerGame.Length; i++)
            {
                PerGame[i] = 0;
            }

            for (var i = 0; i < PlTotals.Length; i++)
            {
                PlTotals[i] = 0;
            }

            for (var i = 0; i < PlPerGame.Length; i++)
            {
                PlPerGame[i] = 0;
            }

            for (var i = 0; i < CareerHighs.Length; i++)
            {
                CareerHighs[i] = 0;
            }

            Contract = new PlayerContract();
            IsSigned = false;
            IsHidden = false;
            Injury = new PlayerInjury();
            IsAllStar = false;
            IsNBAChampion = false;
            YearOfBirth = 0;
            YearsPro = 0;
            Height = 0;
            Weight = 0;
            TeamF = -1;
            TeamS = -1;

            Metrics = new Dictionary<string, double>(PlayerStatsHelper.MetricsDict);
            PlMetrics = new Dictionary<string, double>(Metrics);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PlayerStats" /> class.
        /// </summary>
        /// <param name="playerStatsRow">The player stats row.</param>
        /// <param name="playoffs">
        ///     if set to <c>true</c> the row is assumed to contain playoff stats.
        /// </param>
        public PlayerStats(PlayerStatsRow playerStatsRow, bool playoffs = false)
            : this()
        {
            LastName = playerStatsRow.LastName;
            FirstName = playerStatsRow.FirstName;

            if (!playoffs)
            {
                Totals[PAbbrT.GP] = playerStatsRow.GP;
                Totals[PAbbrT.GS] = playerStatsRow.GS;
                Totals[PAbbrT.MINS] = playerStatsRow.MINS;
                Totals[PAbbrT.PTS] = playerStatsRow.PTS;
                Totals[PAbbrT.FGM] = playerStatsRow.FGM;
                Totals[PAbbrT.FGA] = playerStatsRow.FGA;
                Totals[PAbbrT.TPM] = playerStatsRow.TPM;
                Totals[PAbbrT.TPA] = playerStatsRow.TPA;
                Totals[PAbbrT.FTM] = playerStatsRow.FTM;
                Totals[PAbbrT.FTA] = playerStatsRow.FTA;
                Totals[PAbbrT.OREB] = playerStatsRow.OREB;
                Totals[PAbbrT.DREB] = playerStatsRow.DREB;
                Totals[PAbbrT.STL] = playerStatsRow.STL;
                Totals[PAbbrT.TOS] = playerStatsRow.TOS;
                Totals[PAbbrT.BLK] = playerStatsRow.BLK;
                Totals[PAbbrT.AST] = playerStatsRow.AST;
                Totals[PAbbrT.FOUL] = playerStatsRow.FOUL;

                Metrics["GmSc"] = playerStatsRow.GmSc;
                Metrics["GmScE"] = playerStatsRow.GmScE;
                Metrics["EFF"] = playerStatsRow.EFF;
                Metrics["EFG%"] = playerStatsRow.EFGp;
                Metrics["TS%"] = playerStatsRow.TSp;
                Metrics["AST%"] = playerStatsRow.ASTp;
                Metrics["STL%"] = playerStatsRow.STLp;
                Metrics["TO%"] = playerStatsRow.TOp;
                Metrics["USG%"] = playerStatsRow.USGp;
                Metrics["PTSR"] = playerStatsRow.PTSR;
                Metrics["REBR"] = playerStatsRow.REBR;
                Metrics["OREBR"] = playerStatsRow.OREBR;
                Metrics["ASTR"] = playerStatsRow.ASTR;
                Metrics["BLKR"] = playerStatsRow.BLKR;
                Metrics["STLR"] = playerStatsRow.STLR;
                Metrics["TOR"] = playerStatsRow.TOR;
                Metrics["FTR"] = playerStatsRow.FTR;
                Metrics["PER"] = playerStatsRow.PER;
                Metrics["BLK%"] = playerStatsRow.BLKp;
                Metrics["DREB%"] = playerStatsRow.DREBp;
                Metrics["OREB%"] = playerStatsRow.OREBp;
                Metrics["REB%"] = playerStatsRow.REBp;
                Metrics["PPR"] = playerStatsRow.PPR;
            }
            else
            {
                PlTotals[PAbbrT.GP] = playerStatsRow.GP;
                PlTotals[PAbbrT.GS] = playerStatsRow.GS;
                PlTotals[PAbbrT.MINS] = playerStatsRow.MINS;
                PlTotals[PAbbrT.PTS] = playerStatsRow.PTS;
                PlTotals[PAbbrT.FGM] = playerStatsRow.FGM;
                PlTotals[PAbbrT.FGA] = playerStatsRow.FGA;
                PlTotals[PAbbrT.TPM] = playerStatsRow.TPM;
                PlTotals[PAbbrT.TPA] = playerStatsRow.TPA;
                PlTotals[PAbbrT.FTM] = playerStatsRow.FTM;
                PlTotals[PAbbrT.FTA] = playerStatsRow.FTA;
                PlTotals[PAbbrT.OREB] = playerStatsRow.OREB;
                PlTotals[PAbbrT.DREB] = playerStatsRow.DREB;
                PlTotals[PAbbrT.STL] = playerStatsRow.STL;
                PlTotals[PAbbrT.TOS] = playerStatsRow.TOS;
                PlTotals[PAbbrT.BLK] = playerStatsRow.BLK;
                PlTotals[PAbbrT.AST] = playerStatsRow.AST;
                PlTotals[PAbbrT.FOUL] = playerStatsRow.FOUL;

                PlMetrics["GmSc"] = playerStatsRow.GmSc;
                PlMetrics["GmScE"] = playerStatsRow.GmScE;
                PlMetrics["EFF"] = playerStatsRow.EFF;
                PlMetrics["EFG%"] = playerStatsRow.EFGp;
                PlMetrics["TS%"] = playerStatsRow.TSp;
                PlMetrics["AST%"] = playerStatsRow.ASTp;
                PlMetrics["STL%"] = playerStatsRow.STLp;
                PlMetrics["TO%"] = playerStatsRow.TOp;
                PlMetrics["USG%"] = playerStatsRow.USGp;
                PlMetrics["PTSR"] = playerStatsRow.PTSR;
                PlMetrics["REBR"] = playerStatsRow.REBR;
                PlMetrics["OREBR"] = playerStatsRow.OREBR;
                PlMetrics["ASTR"] = playerStatsRow.ASTR;
                PlMetrics["BLKR"] = playerStatsRow.BLKR;
                PlMetrics["STLR"] = playerStatsRow.STLR;
                PlMetrics["TOR"] = playerStatsRow.TOR;
                PlMetrics["FTR"] = playerStatsRow.FTR;
                PlMetrics["PER"] = playerStatsRow.PER;
                PlMetrics["BLK%"] = playerStatsRow.BLKp;
                PlMetrics["DREB%"] = playerStatsRow.DREBp;
                PlMetrics["OREB%"] = playerStatsRow.OREBp;
                PlMetrics["REB%"] = playerStatsRow.REBp;
                PlMetrics["PPR"] = playerStatsRow.PPR;
            }

            ID = playerStatsRow.ID;
            Position1 = playerStatsRow.Position1;
            Position2 = playerStatsRow.Position2;
            TeamF = playerStatsRow.TeamF;
            TeamS = playerStatsRow.TeamS;
            YearOfBirth = playerStatsRow.YearOfBirth;
            YearsPro = playerStatsRow.YearsPro;
            IsSigned = playerStatsRow.IsSigned;
            IsHidden = playerStatsRow.IsHidden;
            IsAllStar = playerStatsRow.IsAllStar;
            Injury = PlayerInjury.InjuryTypes.ContainsValue(playerStatsRow.InjuryName)
                         ? new PlayerInjury(
                               PlayerInjury.InjuryTypes.Single(pi => pi.Value == playerStatsRow.InjuryName).Key,
                               playerStatsRow.InjuryDaysLeft)
                         : new PlayerInjury(playerStatsRow.InjuryName, playerStatsRow.InjuryDaysLeft);
            IsNBAChampion = playerStatsRow.IsNBAChampion;

            Contract.Option = playerStatsRow.ContractOption;
            Contract.ContractSalaryPerYear.Clear();
            for (var i = 1; i <= 7; i++)
            {
                var salary = Convert.ToInt32(typeof(PlayerStatsRow).GetProperty("ContractY" + i).GetValue(playerStatsRow, null));
                if (salary == 0)
                {
                    break;
                }

                Contract.ContractSalaryPerYear.Add(salary);
            }

            Height = playerStatsRow.Height;
            Weight = playerStatsRow.Weight;

            CalcAvg();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PlayerStats" /> class.
        /// </summary>
        /// <param name="id">The ID.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="position1">The primary position.</param>
        /// <param name="position2">The secondary position.</param>
        /// <param name="yearsPro">The amount of years this player has been in the league.</param>
        /// <param name="teamF">The team the player is currently with.</param>
        /// <param name="teamS">The team the player started the season with.</param>
        /// <param name="isActive">
        ///     if set to <c>true</c> the player is currently active (i.e. signed with a team).
        /// </param>
        /// <param name="isHidden">
        ///     if set to <c>true</c> the player is hidden for this season.
        /// </param>
        /// <param name="injury">The PlayerInjury instance containing information about the player's injury, if any.</param>
        /// <param name="isAllStar">
        ///     if set to <c>true</c> is an All-Star this season.
        /// </param>
        /// <param name="isNBAChampion">
        ///     if set to <c>true</c> is a champion this season.
        /// </param>
        /// <param name="dataRow">A row of an SQLite query result containing player information.</param>
        /// <param name="playoffs">
        ///     if set to <c>true</c> the row is assumed to contain playoff stats.
        /// </param>
        /// <param name="yearOfBirth">The year the player was born.</param>
        public PlayerStats(
            int id,
            string lastName,
            string firstName,
            Position position1,
            Position position2,
            int yearOfBirth,
            int yearsPro,
            int teamF,
            int teamS,
            bool isActive,
            bool isHidden,
            PlayerInjury injury,
            bool isAllStar,
            bool isNBAChampion,
            DataRow dataRow,
            bool playoffs = false)
            : this()
        {
            ID = id;
            LastName = lastName;
            FirstName = firstName;
            Position1 = position1;
            Position2 = position2;
            TeamF = teamF;
            TeamS = teamS;
            YearOfBirth = yearOfBirth;
            YearsPro = yearsPro;
            IsSigned = isActive;
            IsHidden = isHidden;
            IsAllStar = isAllStar;
            Injury = injury;
            IsNBAChampion = isNBAChampion;

            try
            {
                if (!playoffs)
                {
                    Totals[PAbbrT.GP] = ParseCell.GetUInt16(dataRow, "GP");
                    Totals[PAbbrT.GS] = ParseCell.GetUInt16(dataRow, "GS");
                    Totals[PAbbrT.MINS] = ParseCell.GetUInt16(dataRow, "MINS");
                    Totals[PAbbrT.PTS] = ParseCell.GetUInt16(dataRow, "PTS");

                    var parts = ParseCell.GetString(dataRow, "FG").Split('-');

                    Totals[PAbbrT.FGM] = Convert.ToUInt16(parts[0]);
                    Totals[PAbbrT.FGA] = Convert.ToUInt16(parts[1]);

                    parts = ParseCell.GetString(dataRow, "3PT").Split('-');

                    Totals[PAbbrT.TPM] = Convert.ToUInt16(parts[0]);
                    Totals[PAbbrT.TPA] = Convert.ToUInt16(parts[1]);

                    parts = ParseCell.GetString(dataRow, "FT").Split('-');

                    Totals[PAbbrT.FTM] = Convert.ToUInt16(parts[0]);
                    Totals[PAbbrT.FTA] = Convert.ToUInt16(parts[1]);

                    Totals[PAbbrT.OREB] = ParseCell.GetUInt16(dataRow, "OREB");
                    Totals[PAbbrT.DREB] = ParseCell.GetUInt16(dataRow, "DREB");
                    Totals[PAbbrT.STL] = ParseCell.GetUInt16(dataRow, "STL");
                    Totals[PAbbrT.TOS] = ParseCell.GetUInt16(dataRow, "TO");
                    Totals[PAbbrT.BLK] = ParseCell.GetUInt16(dataRow, "BLK");
                    Totals[PAbbrT.AST] = ParseCell.GetUInt16(dataRow, "AST");
                    Totals[PAbbrT.FOUL] = ParseCell.GetUInt16(dataRow, "FOUL");
                }
                else
                {
                    PlTotals[PAbbrT.GP] = ParseCell.GetUInt16(dataRow, "GP");
                    PlTotals[PAbbrT.GS] = ParseCell.GetUInt16(dataRow, "GS");
                    PlTotals[PAbbrT.MINS] = ParseCell.GetUInt16(dataRow, "MINS");
                    PlTotals[PAbbrT.PTS] = ParseCell.GetUInt16(dataRow, "PTS");

                    var parts = ParseCell.GetString(dataRow, "FG").Split('-');

                    PlTotals[PAbbrT.FGM] = Convert.ToUInt16(parts[0]);
                    PlTotals[PAbbrT.FGA] = Convert.ToUInt16(parts[1]);

                    parts = ParseCell.GetString(dataRow, "3PT").Split('-');

                    PlTotals[PAbbrT.TPM] = Convert.ToUInt16(parts[0]);
                    PlTotals[PAbbrT.TPA] = Convert.ToUInt16(parts[1]);

                    parts = ParseCell.GetString(dataRow, "FT").Split('-');

                    PlTotals[PAbbrT.FTM] = Convert.ToUInt16(parts[0]);
                    PlTotals[PAbbrT.FTA] = Convert.ToUInt16(parts[1]);

                    PlTotals[PAbbrT.OREB] = ParseCell.GetUInt16(dataRow, "OREB");
                    PlTotals[PAbbrT.DREB] = ParseCell.GetUInt16(dataRow, "DREB");
                    PlTotals[PAbbrT.STL] = ParseCell.GetUInt16(dataRow, "STL");
                    PlTotals[PAbbrT.TOS] = ParseCell.GetUInt16(dataRow, "TO");
                    PlTotals[PAbbrT.BLK] = ParseCell.GetUInt16(dataRow, "BLK");
                    PlTotals[PAbbrT.AST] = ParseCell.GetUInt16(dataRow, "AST");
                    PlTotals[PAbbrT.FOUL] = ParseCell.GetUInt16(dataRow, "FOUL");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    String.Format("{0} {1} ({2}) has some invalid data.\n\nError: {3}", firstName, lastName, teamF, ex.Message));
            }

            CalcAvg();
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PlayerStats" /> class.
        /// </summary>
        /// <param name="dataRow">A row of an SQLite query result containing player information.</param>
        /// <param name="tst">The Team Stats dictionary from which to add additional information.</param>
        /// <param name="playoffs">
        ///     if set to <c>true</c>, the row is assumed to contain playoff stats.
        /// </param>
        public PlayerStats(DataRow dataRow, Dictionary<int, TeamStats> tst, bool playoffs = false)
            : this()
        {
            ID = ParseCell.GetInt32(dataRow, "ID");

            if (!playoffs)
            {
                LastName = ParseCell.GetString(dataRow, "LastName");
                FirstName = ParseCell.GetString(dataRow, "FirstName");
                var p1 = ParseCell.GetString(dataRow, "Position1");
                if (String.IsNullOrWhiteSpace(p1))
                {
                    Position1 = Position.None;
                }
                else
                {
                    Position1 = (Position) Enum.Parse(typeof(Position), p1);
                }
                var p2 = ParseCell.GetString(dataRow, "Position2");
                if (String.IsNullOrWhiteSpace(p2))
                {
                    Position2 = Position.None;
                }
                else
                {
                    Position2 = (Position) Enum.Parse(typeof(Position), p2);
                }
                try
                {
                    TeamF = ParseCell.GetInt32(dataRow, "TeamFin");
                    TeamS = ParseCell.GetInt32(dataRow, "TeamSta");
                }
                catch (FormatException)
                {
                    try
                    {
                        TeamF = tst.Single(ts => ts.Value.Name == ParseCell.GetString(dataRow, "TeamFin")).Value.ID;
                    }
                    catch (InvalidOperationException)
                    {
                        TeamF = -1;
                    }
                    try
                    {
                        TeamS = tst.Single(ts => ts.Value.Name == ParseCell.GetString(dataRow, "TeamSta")).Value.ID;
                    }
                    catch (InvalidOperationException)
                    {
                        TeamS = -1;
                    }
                }
                IsSigned = ParseCell.GetBoolean(dataRow, "isActive");

                // Backwards compatibility with databases that didn't have the field
                try
                {
                    IsHidden = ParseCell.GetBoolean(dataRow, "isHidden");
                }
                catch
                {
                    IsHidden = false;
                }

                try
                {
                    YearOfBirth = ParseCell.GetInt32(dataRow, "YearOfBirth");
                }
                catch
                {
                    try
                    {
                        YearOfBirth = Convert.ToInt32(MainWindow.BaseYear) - ParseCell.GetInt32(dataRow, "Age");
                    }
                    catch
                    {
                        YearOfBirth = 0;
                    }
                }

                try
                {
                    YearsPro = ParseCell.GetInt32(dataRow, "YearsPro");
                }
                catch (Exception)
                {
                    YearsPro = 0;
                }
                //

                try
                {
                    var injType = ParseCell.GetInt32(dataRow, "InjuryType");
                    var days = ParseCell.GetInt32(dataRow, "InjuryDaysLeft");
                    Injury = injType != -1
                                 ? new PlayerInjury(injType, days)
                                 : new PlayerInjury(ParseCell.GetString(dataRow, "CustomInjuryName"), days);
                }
                catch
                {
                    Injury = ParseCell.GetBoolean(dataRow, "isInjured") ? new PlayerInjury("Unknown", -1) : new PlayerInjury();
                }

                IsAllStar = ParseCell.GetBoolean(dataRow, "isAllStar");
                IsNBAChampion = ParseCell.GetBoolean(dataRow, "isNBAChampion");
                Contract = new PlayerContract();
                for (var i = 1; i <= 7; i++)
                {
                    int salary;
                    try
                    {
                        salary = ParseCell.GetInt32(dataRow, "ContractY" + i);
                    }
                    catch (ArgumentException)
                    {
                        break;
                    }
                    if (salary == 0)
                    {
                        break;
                    }

                    Contract.ContractSalaryPerYear.Add(salary);
                }
                try
                {
                    Contract.Option =
                        (PlayerContractOption) Enum.Parse(typeof(PlayerContractOption), ParseCell.GetString(dataRow, "ContractOption"));
                }
                catch (ArgumentException)
                {
                    Contract.Option = PlayerContractOption.None;
                }
                try
                {
                    Height = ParseCell.GetFloat(dataRow, "Height");
                    Weight = ParseCell.GetFloat(dataRow, "Weight");
                }
                catch (ArgumentException)
                {
                    Height = 0;
                    Weight = 0;
                }
            }

            GetStatsFromDataRow(dataRow, playoffs);
        }
Ejemplo n.º 6
0
        /// <summary>Resets the stats.</summary>
        public void ResetStats()
        {
            for (var i = 0; i < Totals.Length; i++)
            {
                Totals[i] = 0;
            }

            for (var i = 0; i < PlTotals.Length; i++)
            {
                PlTotals[i] = 0;
            }

            Metrics.Clear();

            Injury = new PlayerInjury();

            CalcAvg();
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="PlayerStats" /> class.
        /// </summary>
        public PlayerStats()
        {
            for (int i = 0; i < Totals.Length; i++)
            {
                Totals[i] = 0;
            }

            for (int i = 0; i < PerGame.Length; i++)
            {
                PerGame[i] = 0;
            }

            for (int i = 0; i < PlTotals.Length; i++)
            {
                PlTotals[i] = 0;
            }

            for (int i = 0; i < PlPerGame.Length; i++)
            {
                PlPerGame[i] = 0;
            }

            for (int i = 0; i < CareerHighs.Length; i++)
            {
                CareerHighs[i] = 0;
            }

            Contract = new PlayerContract();
            IsActive = false;
            IsHidden = false;
            Injury = new PlayerInjury();
            IsAllStar = false;
            IsNBAChampion = false;
            YearOfBirth = 0;
            YearsPro = 0;
            Height = 0;
            Weight = 0;
            TeamF = -1;
            TeamS = -1;

            Metrics = new Dictionary<string, double>(PAbbr.MetricsDict);
            PlMetrics = new Dictionary<string, double>(Metrics);
            /*
            var metricsNames = PAbbr.MetricsNames;
            for (int i = 0; i < metricsNames.Count; i++)
            {
                var name = metricsNames[i];
                Metrics.Add(name, double.NaN);
                PlMetrics.Add(name, double.NaN);
            }
            */
            /*
            PAbbr.MetricsNames.ForEach(name =>
                                       {
                                           Metrics.Add(name, double.NaN);
                                           PlMetrics.Add(name, double.NaN);
                                       });
            */
        }