Example #1
0
 private void CopyPlayerDataIfPlayerExists(Batting batting, BattingStats battingStats)
 {
     if (batting.Player != null)
     {
         battingStats.NameFirst = batting.Player.NameFirst;
         battingStats.NameLast  = batting.Player.NameLast;
         battingStats.NameGiven = batting.Player.NameGiven;
     }
 }
Example #2
0
        public BattingStats Map(Batting batting)
        {
            var battingStats = new BattingStats()
            {
                PlayerId = batting.PlayerId,
                YearId   = batting.YearId,
                Stint    = batting.Stint,
                TeamId   = batting.TeamId,
                LgId     = batting.LgId,
            };

            CopyPlayerDataIfPlayerExists(batting, battingStats);
            CopyNullableStats(batting, battingStats);

            _calculator.CalculateStats(battingStats);

            return(battingStats);
        }
Example #3
0
 private void CopyNullableStats(Batting batting, BattingStats battingStats)
 {
     battingStats.G        = batting.G;
     battingStats.GBatting = batting.GBatting;
     battingStats.Ab       = batting.Ab;
     battingStats.R        = batting.R;
     battingStats.H        = batting.H;
     battingStats.X2b      = batting.X2b;
     battingStats.X3b      = batting.X3b;
     battingStats.Hr       = batting.Hr;
     battingStats.Rbi      = batting.Rbi;
     battingStats.Sb       = batting.Sb;
     battingStats.Cs       = batting.Cs;
     battingStats.Bb       = batting.Bb;
     battingStats.So       = batting.So;
     battingStats.Ibb      = batting.Ibb;
     battingStats.Hbp      = batting.Hbp;
     battingStats.Sh       = batting.Sh;
     battingStats.Sf       = batting.Sf;
     battingStats.Gidp     = batting.Gidp;
 }
        public void CalculateStats(BattingStats batting)
        {
            var calculatorStats = ConvertOptionalParamsToNonNullable(batting);

            batting.Pa = calculatorStats.Pa;

            batting.Singles = calculatorStats.Singles;

            batting.Obp = calculatorStats.Obp;

            batting.Slg = calculatorStats.Slg;

            batting.BbRate = calculatorStats.BbRate;

            batting.KRate = calculatorStats.KRate;

            batting.Avg = CalculateAvg(calculatorStats);

            batting.Ops = CalculateOps(calculatorStats);

            batting.Iso = CalculateIso(calculatorStats);

            batting.Babip = CalculateBabip(calculatorStats);
        }
        private CalculatorStats ConvertOptionalParamsToNonNullable(BattingStats battingStats)
        {
            var calculatorStats = new CalculatorStats
            {
                Ab = battingStats.Ab ?? 0,

                H = battingStats.H ?? 0,

                X2b = battingStats.X2b ?? 0,

                X3b = battingStats.X3b ?? 0,

                Hr = battingStats.Hr ?? 0,

                Bb = battingStats.Bb ?? 0,

                So = battingStats.So ?? 0,

                Ibb = battingStats.Ibb ?? 0,

                Hbp = battingStats.Hbp ?? 0,

                Sh = battingStats.Sh ?? 0,

                Sf = battingStats.Sf ?? 0
            };

            calculatorStats.Pa      = CalulatePa(calculatorStats);
            calculatorStats.Singles = CalculateSingles(calculatorStats);
            calculatorStats.Obp     = CalculateObp(calculatorStats);
            calculatorStats.Slg     = CalculateSlg(calculatorStats);
            calculatorStats.KRate   = CalculateKRate(calculatorStats);
            calculatorStats.BbRate  = CalculateBbRate(calculatorStats);

            return(calculatorStats);
        }