Esempio n. 1
0
        public void GetPitchingStatsReturnsEnumerablePitchingStatsRecords()
        {
            var firstPerson = new PitchingStats
            {
                PlayerId = "personId"
            };

            var secondPerson = new PitchingStats
            {
                PlayerId = "personId"
            };

            var expectedPeople = new List <PitchingStats>()
            {
                firstPerson,
                secondPerson
            };

            _service.Setup(mockPitchingService => mockPitchingService.GetPitchingStats(firstPerson.PlayerId)).Returns(expectedPeople);

            var actualReturn = _controller.GetPitchingStats(firstPerson.PlayerId);

            Assert.That(actualReturn.ElementAt(0), Is.EqualTo(firstPerson));
            Assert.That(actualReturn.ElementAt(1), Is.EqualTo(secondPerson));
        }
 private static void Compare(PitchingStats expected, PitchingStats actual)
 {
     Assert.Equal(expected.StatsType, actual.StatsType);
     Assert.Equal(expected.Wins, actual.Wins);
     Assert.Equal(expected.Losses, actual.Losses);
     Assert.Equal(expected.QualityStarts, actual.QualityStarts);
     Assert.Equal(expected.Saves, actual.Saves);
     Assert.Equal(expected.BlownSaves, actual.BlownSaves);
     Assert.Equal(expected.Holds, actual.Holds);
     Assert.Equal(expected.InningsPitched, actual.InningsPitched);
     Assert.Equal(expected.HitsAllowed, actual.HitsAllowed);
     Assert.Equal(expected.EarnedRuns, actual.EarnedRuns);
     Assert.Equal(expected.HomeRunsAllowed, actual.HomeRunsAllowed);
     Assert.Equal(expected.BaseOnBallsAllowed, actual.BaseOnBallsAllowed);
     Assert.Equal(expected.StrikeOuts, actual.StrikeOuts);
     Assert.Equal(expected.FlyBallRate, actual.FlyBallRate);
     Assert.Equal(expected.GroundBallRate, actual.GroundBallRate);
     Assert.Equal(expected.EarnedRunAverage, actual.EarnedRunAverage);
     Assert.Equal(expected.WalksAndHitsPerInningPitched, actual.WalksAndHitsPerInningPitched);
     Assert.Equal(expected.BattingAverageOnBallsInPlay, actual.BattingAverageOnBallsInPlay);
     Assert.Equal(expected.StrandRate, actual.StrandRate);
     Assert.Equal(expected.Command, actual.Command);
     Assert.Equal(expected.Dominance, actual.Dominance);
     Assert.Equal(expected.Control, actual.Control);
     Assert.Equal(expected.GroundBallToFlyBallRate, actual.GroundBallToFlyBallRate);
     Assert.Equal(expected.BasePerformanceValue, actual.BasePerformanceValue);
 }
Esempio n. 3
0
        [Fact] public void DefaultsSetTest()
        {
            var obj = new PitchingStats();

            Assert.Equal(StatsType.UNKN, obj.StatsType);
            Assert.Equal(0, obj.Wins);
            Assert.Equal(0, obj.Losses);
            Assert.Equal(0, obj.QualityStarts);
            Assert.Equal(0, obj.Saves);
            Assert.Equal(0, obj.BlownSaves);
            Assert.Equal(0, obj.Holds);
            Assert.Equal(0, obj.InningsPitched);
            Assert.Equal(0, obj.HitsAllowed);
            Assert.Equal(0, obj.EarnedRuns);
            Assert.Equal(0, obj.HomeRunsAllowed);
            Assert.Equal(0, obj.BaseOnBallsAllowed);
            Assert.Equal(0, obj.StrikeOuts);
            Assert.Equal(0, obj.FlyBallRate);
            Assert.Equal(0, obj.GroundBallRate);
            Assert.Equal(0, obj.EarnedRunAverage);
            Assert.Equal(0, obj.WalksAndHitsPerInningPitched);
            Assert.Equal(0, obj.BattingAverageOnBallsInPlay);
            Assert.Equal(0, obj.StrandRate);
            Assert.Equal(0, obj.Command);
            Assert.Equal(0, obj.Dominance);
            Assert.Equal(0, obj.Control);
            Assert.Equal(0, obj.GroundBallToFlyBallRate);
            Assert.Equal(0, obj.BasePerformanceValue);
        }
Esempio n. 4
0
        /// <summary>
        /// Handle a pitching change.
        /// </summary>
        /// <param name="pitcher">The pitcher.</param>
        /// <param name="stats">The stats.</param>
        /// <param name="scoreboard">The scoreboard.</param>
        /// <param name="isHome">if set to <c>true</c> [is home].</param>
        /// <returns>True if a pitching change was made otherwise false.</returns>
        public Boolean PitchingChange(Player pitcher, PitchingStats stats, ScoreBoard scoreboard, Boolean isHome)
        {
            Boolean newPitcher = false;

            if (this.bullpen.Count > 0)
            {
                // Has the pitcher already been removed?
                if (this.lineup.Pitcher == null)
                {
                    var reliefPitcher = this.SelectReliefPitcher(scoreboard, isHome);
                    this.RelievePitcher(reliefPitcher);
                    this.lineup.BattingOrder[8] = reliefPitcher;
                    newPitcher = true;
                }
                else
                {
                    var pitchCount         = Utilities.GetPitchCount(stats);
                    var expectedPitchCount = Utilities.CalculateExpectedPitchCount(pitcher.PitchingStats, this.startingPitcher);

                    if (pitchCount > expectedPitchCount)
                    {
                        // Pitcher is out of gas - select reliever
                        var reliefPitcher = this.SelectReliefPitcher(scoreboard, isHome);

                        this.RelievePitcher(reliefPitcher);
                        newPitcher = true;
                    }
                }
            }

            return(newPitcher);
        }
Esempio n. 5
0
        public void MapYearCopiesDataFromPitchingPostAndPlayerToPitchingPostStats()
        {
            Pitching      pitching = GeneratePitchingWithPlayer();
            PitchingStats pitchingLeaderBoardStats = _mapper.Map(pitching);

            AssertThatEachElementIsEqualWithPlayerValues(pitching, pitchingLeaderBoardStats);
        }
Esempio n. 6
0
        public void GetPitchingStatsByYearReturnsEnumerablePitchingStats()

        {
            var firstPerson = new PitchingStats
            {
                PlayerId = "personId",
                NameLast = "last",
                YearId   = 2000
            };

            var secondPerson = new PitchingStats
            {
                PlayerId = "secondPersonId",
                NameLast = "secondLast",
                YearId   = 2000
            };

            var expectedRecord = new List <PitchingStats>()
            {
                firstPerson,
                secondPerson
            };

            _service.Setup(mockPlayerService => mockPlayerService.GetPitchingStatsByYear(firstPerson.YearId)).Returns(expectedRecord);

            var actualReturn = _controller.GetPitchingStatsByYear(firstPerson.YearId);

            Assert.That(actualReturn.ElementAt(0), Is.EqualTo(firstPerson));
            Assert.That(actualReturn.ElementAt(1), Is.EqualTo(secondPerson));
        }
 /// <summary>Adds another instance of <c>PitchingStats</c> to the list.</summary>
 /// <param name="stats">The <c>PitchingStats</c> to add to the list.</param>
 /// <returns>The instance of the builder.</returns>
 public PitchingStatsBuilder AddStats(PitchingStats stats)
 {
     if (stats != null)
     {
         statsList.Add(stats);
     }
     return(this);
 }
Esempio n. 8
0
        /// <summary>
        /// Gets the pitchers stats.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>The pitching stats.</returns>
        public PitchingStats GetPitchersStats(String id)
        {
            PitchingStats stats = null;

            this.pitcherStatsDictionary.TryGetValue(id, out stats);

            return(stats);
        }
        public void AssertGetPitchingStatsReturnsStats(Pitching expectedPitching)
        {
            var expectedPitchingStats = new PitchingStats();

            _mockMapper.Setup(mockPitchingMapper => mockPitchingMapper.Map(expectedPitching)).Returns(expectedPitchingStats);

            var actualPitching = _service.GetPitchingStats(expectedPitching.PlayerId);

            Assert.That(actualPitching.ElementAt(0), Is.EqualTo(expectedPitchingStats));
        }
        private void AssertGetPitchingLeaderboardStatsByYearReturnsStats(Pitching expectedPitching)
        {
            var expectedPitchingLeaderboardStats = new PitchingStats();

            _mockMapper.Setup(mockPitchingMapper => mockPitchingMapper.Map(expectedPitching)).Returns(expectedPitchingLeaderboardStats);

            var actualPitchingLeaderboardStats = _service.GetPitchingStatsByYear(expectedPitching.YearId);

            Assert.That(actualPitchingLeaderboardStats.ElementAt(0), Is.EqualTo(expectedPitchingLeaderboardStats));
        }
Esempio n. 11
0
        public static Int32 GetPitchCount(PitchingStats stats)
        {
            Double pitchCount = (Double)stats.Strikeouts * 4.81;

            pitchCount += (Double)stats.Walks * 5.14;
            pitchCount += (Double)stats.Hits * 3.27;
            pitchCount += (Double)(stats.TotalOuts - stats.Strikeouts) * 3.16;

            return((Int32)Math.Round(pitchCount));
        }
 private PitchingStats GetPitchingStats(StatsType statsType)
 {
     if (!PitchingStats.Any(s => s.StatsType == statsType))
     {
         PitchingStats.Add(new PitchingStats {
             StatsType = statsType
         });
     }
     return(PitchingStats.FirstOrDefault(s => s.StatsType == statsType));
 }
Esempio n. 13
0
        public void MapCopiesDataFromPitchingToPitchingStats()
        {
            Pitching      pitching      = GeneratePitchingWithoutNullValues();
            PitchingStats pitchingStats = _mapper.Map(pitching);

            AssertThatEachElementIsEqual(pitching, pitchingStats);

            Pitching      pitchingWithNull      = GeneratePitchingWithNullValues();
            PitchingStats pitchingStatsWithNull = _mapper.Map(pitchingWithNull);

            AssertThatEachElementIsEqual(pitchingWithNull, pitchingStatsWithNull);
        }
        public void AssertGetPitchingStatsReturnsStatsWithDuplicateId(Pitching firstEntry, Pitching secondEntry)
        {
            var firstEntryStats  = new PitchingStats();
            var secondEntryStats = new PitchingStats();

            _mockMapper.Setup(mockBattingMapper => mockBattingMapper.Map(firstEntry)).Returns(firstEntryStats);
            _mockMapper.Setup(mockBattingMapper => mockBattingMapper.Map(secondEntry)).Returns(secondEntryStats);

            var actualPeople = _service.GetPitchingStats(firstEntry.PlayerId);

            Assert.That(actualPeople.ElementAt(0), Is.EqualTo(firstEntryStats));
            Assert.That(actualPeople.ElementAt(1), Is.EqualTo(secondEntryStats));
        }
        private void AddPitchingStats(PitchingStats value, StatsType statsType)
        {
            if (value == null)
            {
                return;
            }
            value.StatsType = statsType;
            var existing = GetPitchingStats(statsType);

            if (existing != null)
            {
                PitchingStats.Remove(existing);
            }
            PitchingStats.Add(value);
        }
Esempio n. 16
0
 /// <summary>
 /// Loads the pitching stats.
 /// </summary>
 /// <param name="roster">Player[]</param>
 /// <param name="directory">string</param>
 private static void LoadPitchingStats(ref Player[] roster, string directory)
 {
     PitchingStats[] pStats = PitchingStats.LoadPitchingStats(TextUtilities.FormFilePathName(directory, "Pitching", ".dat"));
     foreach (Player player in roster)
     {
         foreach (PitchingStats pStat in pStats)
         {
             if (player.FullName.Equals(pStat.Name))
             {
                 player.PitchingStats      = pStat;
                 player.PitchingStatistics = new PitchingStatisticsContainer(player);
             }
         }
     }
 }
Esempio n. 17
0
        public void TestLoadPitchingStatsFromFile()
        {
            string path = @"./Data/BaseballReference/Arizona Diamondbacks_(2001)/Arizona Diamondbacks_(2001) Pitching.dat";

            PitchingStats[] pstats = null;
            Assert.IsTrue(File.Exists(path));
            try
            {
                int EXPECTED_LENGTH = 21;
                pstats = PitchingStats.LoadPitchingStats(path);
                pstats.ToList().ForEach(Console.WriteLine);
                Assert.IsTrue(pstats.Length == EXPECTED_LENGTH);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
 private PitchingStats Calculate(PitchingStats stats)
 {
     stats.FlyBallRate                  = Divide(statsList.Select(s => s.InningsPitched * s.FlyBallRate).Sum(), stats.InningsPitched);
     stats.GroundBallRate               = Divide(statsList.Select(s => s.InningsPitched * s.GroundBallRate).Sum(), stats.InningsPitched);
     stats.EarnedRunAverage             = Divide(stats.EarnedRuns, stats.InningsPitched / 9);
     stats.WalksAndHitsPerInningPitched = Divide(stats.HitsAllowed + stats.BaseOnBallsAllowed, stats.InningsPitched);
     stats.BattingAverageOnBallsInPlay  = Divide(stats.HitsAllowed - stats.HomeRunsAllowed,
                                                 stats.InningsPitched * BabipMultiplier + stats.HitsAllowed - stats.StrikeOuts - stats.HomeRunsAllowed);
     stats.StrandRate = Divide(stats.HitsAllowed + stats.BaseOnBallsAllowed - stats.EarnedRuns,
                               stats.HitsAllowed + stats.BaseOnBallsAllowed - stats.HomeRunsAllowed);
     stats.Dominance = Divide(stats.StrikeOuts, stats.InningsPitched / 9);
     stats.Control   = Divide(stats.BaseOnBallsAllowed, stats.InningsPitched / 9);
     stats.Command   = Divide(stats.Dominance, stats.Control);
     stats.GroundBallToFlyBallRate = Divide(stats.GroundBallRate, stats.FlyBallRate);
     stats.BasePerformanceValue    = stats.InningsPitched > 0
         ? (stats.Dominance - MinimumDominance) * WeightDominance
                                     + (MaxiumumControl - stats.Control) * WeightControl
                                     + (stats.GroundBallRate - MinimumGroundBallRate) * WeightGroundBallRate
         : 0;
     return(stats);
 }
Esempio n. 19
0
        private void AssertThatEachElementIsEqualWithPlayerValues(Pitching pitching, PitchingStats pitchingStats)
        {
            Assert.That(pitchingStats.NameFirst, Is.EqualTo(pitching.Player.NameFirst));
            Assert.That(pitchingStats.NameGiven, Is.EqualTo(pitching.Player.NameGiven));
            Assert.That(pitchingStats.NameLast, Is.EqualTo(pitching.Player.NameLast));
            Assert.That(pitchingStats.PlayerId, Is.EqualTo(pitching.PlayerId));
            Assert.That(pitchingStats.YearId, Is.EqualTo(pitching.YearId));
            Assert.That(pitchingStats.Stint, Is.EqualTo(pitching.Stint));
            Assert.That(pitchingStats.TeamId, Is.EqualTo(pitching.TeamId));
            Assert.That(pitchingStats.LgId, Is.EqualTo(pitching.LgId));
            Assert.That(pitchingStats.W, Is.EqualTo(pitching.W));
            Assert.That(pitchingStats.L, Is.EqualTo(pitching.L));
            Assert.That(pitchingStats.G, Is.EqualTo(pitching.G));
            Assert.That(pitchingStats.Gs, Is.EqualTo(pitching.Gs));
            Assert.That(pitchingStats.Cg, Is.EqualTo(pitching.Cg));
            Assert.That(pitchingStats.Sho, Is.EqualTo(pitching.Sho));
            Assert.That(pitchingStats.Sv, Is.EqualTo(pitching.Sv));
            Assert.That(pitchingStats.Ipouts, Is.EqualTo(pitching.Ipouts));
            Assert.That(pitchingStats.H, Is.EqualTo(pitching.H));
            Assert.That(pitchingStats.Er, Is.EqualTo(pitching.Er));
            Assert.That(pitchingStats.Hr, Is.EqualTo(pitching.Hr));
            Assert.That(pitchingStats.Bb, Is.EqualTo(pitching.Bb));
            Assert.That(pitchingStats.So, Is.EqualTo(pitching.So));
            var localBaopp = pitching.Baopp / 100 ?? 0;

            Assert.That(pitchingStats.Baopp, Is.EqualTo(Math.Round(localBaopp, 2)));
            var localEra = pitching.Era / 100 ?? 0;

            Assert.That(pitchingStats.Era, Is.EqualTo(Math.Round(localEra, 2)));
            Assert.That(pitchingStats.Ibb, Is.EqualTo(pitching.Ibb));
            Assert.That(pitchingStats.Wp, Is.EqualTo(pitching.Wp));
            Assert.That(pitchingStats.Hbp, Is.EqualTo(pitching.Hbp));
            Assert.That(pitchingStats.Bk, Is.EqualTo(pitching.Bk));
            Assert.That(pitchingStats.Bfp, Is.EqualTo(pitching.Bfp));
            Assert.That(pitchingStats.Gf, Is.EqualTo(pitching.Gf));
            Assert.That(pitchingStats.R, Is.EqualTo(pitching.R));
            Assert.That(pitchingStats.Sh, Is.EqualTo(pitching.Sh));
            Assert.That(pitchingStats.Sf, Is.EqualTo(pitching.Sf));
            Assert.That(pitchingStats.Gidp, Is.EqualTo(pitching.Gidp));
        }
Esempio n. 20
0
        public static Int32 CalculateExpectedPitchCount(PitchingStats stats, Boolean isStarter)
        {
            Int32 expectedPitchCount = 0;

            Int32 totalOuts    = (stats.Innings * 3) - stats.Strikeouts;
            Int32 totalPitches = (Int32)((Double)stats.Strikeouts * 5.0);

            totalPitches += (Int32)((Double)stats.Walks * 5.3);
            totalPitches += (Int32)((Double)stats.Hits * 3.4);
            totalPitches += (Int32)((Double)totalOuts * 3.3);

            Double  startPercent  = stats.GamesStarted / stats.Games;
            Boolean mostlyStarter = false;

            if (startPercent > 0.66)
            {
                mostlyStarter = true;
            }

            if (isStarter)
            {
                if (mostlyStarter == false)
                {
                    expectedPitchCount = 105;
                }
                else
                {
                    Double reliefInnings = 0;
                    Double startInnings  = 0;
                    if (stats.GamesStarted == 0)
                    {
                        reliefInnings = stats.Innings;
                    }
                    else if (stats.GamesStarted == stats.Games)
                    {
                        startInnings = stats.Innings;
                    }
                    else
                    {
                        reliefInnings = (stats.Games - stats.GamesStarted) * 1.7;
                        startInnings  = stats.Innings - reliefInnings;
                    }

                    Double startPitches = totalPitches * (startInnings / stats.Innings);
                    expectedPitchCount = (Int32)Math.Ceiling(startPitches / stats.GamesStarted);

                    if (expectedPitchCount < 64)
                    {
                        expectedPitchCount = 64;
                    }

                    if (expectedPitchCount > 145)
                    {
                        expectedPitchCount = 145;
                    }
                }
            }
            else
            {
                if (mostlyStarter)
                {
                    expectedPitchCount = 50;
                }
                else
                {
                    Double startInnings  = stats.GamesStarted * 5.7;
                    Double reliefInnings = stats.Innings - startInnings;

                    Double reliefPitches = totalPitches * (reliefInnings / stats.Innings);
                    expectedPitchCount = (Int32)Math.Ceiling(reliefPitches / (stats.Games - stats.GamesStarted));
                }
            }

            return(expectedPitchCount);
        }
        [Fact] public void BuildWithCollectionAdd()
        {
            var stats1 = new PitchingStats
            {
                Wins               = 12,
                Losses             = 6,
                QualityStarts      = 18,
                Saves              = 9,
                BlownSaves         = 3,
                Holds              = 15,
                InningsPitched     = 60,
                HitsAllowed        = 45,
                EarnedRuns         = 24,
                HomeRunsAllowed    = 1,
                BaseOnBallsAllowed = 30,
                StrikeOuts         = 120,
                FlyBallRate        = 0.2,
                GroundBallRate     = 0.31
            };
            var stats2 = new PitchingStats
            {
                Wins               = 8,
                Losses             = 4,
                QualityStarts      = 12,
                Saves              = 6,
                BlownSaves         = 2,
                Holds              = 10,
                InningsPitched     = 40,
                HitsAllowed        = 30,
                EarnedRuns         = 16,
                HomeRunsAllowed    = 0,
                BaseOnBallsAllowed = 20,
                StrikeOuts         = 80,
                FlyBallRate        = 0.45,
                GroundBallRate     = 0.66
            };
            var expected = new PitchingStats
            {
                Wins                         = 20,
                Losses                       = 10,
                QualityStarts                = 30,
                Saves                        = 15,
                BlownSaves                   = 5,
                Holds                        = 25,
                InningsPitched               = 100,
                HitsAllowed                  = 75,
                EarnedRuns                   = 40,
                HomeRunsAllowed              = 1,
                BaseOnBallsAllowed           = 50,
                StrikeOuts                   = 200,
                FlyBallRate                  = .30,
                GroundBallRate               = .45,
                EarnedRunAverage             = 3.6,
                WalksAndHitsPerInningPitched = 1.25,
                BattingAverageOnBallsInPlay  = 74 / 156d,
                StrandRate                   = 85 / 124d,
                Command                      = 4,
                Dominance                    = 18,
                Control                      = 4.5,
                GroundBallToFlyBallRate      = 1.5,
                BasePerformanceValue         = 225.5
            };

            Compare(expected, new PitchingStatsBuilder().AddStats(new PitchingStats[] { stats1, stats2 }).Build());
        }
Esempio n. 22
0
        /// <summary>
        /// Loads PitchingStats[] array from database.
        /// </summary>
        /// <returns>GameStats[]</returns>
        /// <param name="dataTable">DataTable</param>
        protected override GameStats[] LoadStatsFromDatabase(DataTable dataTable)
        {
            List <PitchingStats> pitchingStats = new List <PitchingStats>();

            foreach (DataRow row in dataTable.Rows)
            {
                string        name   = string.Empty;
                string        id     = string.Empty;
                PitchingStats pStats = null;
                PitchingStatisticsContainer theStats = null;
                int    stamina      = 0;
                double startPct     = 0;
                int    originalHits = Convert.ToInt32(row["H"]);
                try
                {
                    theStats = new PitchingStatisticsContainer(null);

                    name = String.Concat(row["nameFirst"].ToString(), " ", row["nameLast"].ToString());
                    int battersFaced = (int)Convert.ToDouble(row["BFP"]);
                    theStats.BattersFaced = battersFaced;

                    double inningsPitched = (Convert.ToDouble(row["IPouts"]) / 3);
                    theStats.TotalOuts = (int)Convert.ToDouble(row["IPouts"]);

                    int completeGames = (int)Convert.ToDouble(row["CG"]);
                    theStats.CompleteGames = completeGames;

                    theStats.Saves       = Convert.ToInt32(row["SV"]);
                    theStats.RunsAllowed = Convert.ToInt32(row["R"]);

                    int hits = Constants.GetValueFromDouble(originalHits, battersFaced);

                    int totalGamesPitched = Convert.ToInt32(row["G"]);
                    theStats.PitchingTotalGamesAppeared = totalGamesPitched;

                    int gamesStarted = Convert.ToInt32(row["GS"]);
                    theStats.PitchingGamesStarted = gamesStarted;

                    int wins = Convert.ToInt32(row["W"]);
                    theStats.Wins = wins;

                    int losses = Convert.ToInt32(row["L"]);
                    theStats.Losses = losses;

                    int totalDecisions = wins + losses;
                    startPct = Constants.GetValueFromDouble(gamesStarted, totalGamesPitched);
                    double winLossPct = Constants.GetValueFromDouble(wins, totalDecisions);

                    int control = PitchingStats.CalculateControl(battersFaced, originalHits, wins, theStats.Saves);

                    stamina = PitchingStats.CalculateStamina(startPct, wins, completeGames, gamesStarted, totalGamesPitched, inningsPitched);

                    int balks = Constants.GetValueFromDouble(Convert.ToDouble(row["BK"]), battersFaced);
                    if (balks == 0)
                    {
                        balks = 1;
                    }
                    theStats.Balks = Convert.ToInt32(row["BK"]);

                    int hitByPitch = Constants.GetValueFromDouble(Convert.ToDouble(row["HBP"]), battersFaced);
                    if (hitByPitch == 0)
                    {
                        hitByPitch = 1;
                    }
                    theStats.HitByPitches = Convert.ToInt32(row["HBP"]);

                    int walks = Constants.GetValueFromDouble(Convert.ToDouble(row["BB"]), battersFaced);
                    if (walks == 0)
                    {
                        walks = 1;
                    }
                    theStats.Walks = Convert.ToInt32(row["BB"]);

                    int strikeouts = Constants.GetValueFromDouble(Convert.ToDouble(row["SO"]), battersFaced);
                    if (strikeouts == 0)
                    {
                        strikeouts = 1;
                    }
                    theStats.Strikeouts = Convert.ToInt32(row["SO"]);

                    int otherOuts  = Constants.GetValueFromDouble(Convert.ToDouble(row["BFP"]) - Convert.ToDouble(row["H"]) - Convert.ToDouble(row["BB"]) - Convert.ToDouble(row["HBP"]) - Convert.ToDouble(row["SO"]), Convert.ToDouble(row["BFP"]));
                    int groundOuts = (int)(otherOuts * 0.5);
                    if (groundOuts == 0)
                    {
                        groundOuts = 1;
                    }
                    int flyouts = (int)(otherOuts * 0.5);
                    if (flyouts == 0)
                    {
                        flyouts = 1;
                    }

                    int homeRuns = Constants.GetValueFromDouble(Convert.ToDouble(row["HR"]), battersFaced);
                    if (homeRuns == 0)
                    {
                        homeRuns = 1;
                    }
                    theStats.Homeruns = Convert.ToInt32(row["HR"]);

                    int otherHits = hits - homeRuns;

                    //since singles, doubles and triples are not given, we'll use a generic distribution
                    int singles = (int)(otherHits * 0.6); // singles will be 60% of other hits
                    if (singles == 0)
                    {
                        singles = 1;
                    }

                    int doubles = (int)(otherHits * 0.3);
                    if (doubles == 0)
                    {
                        doubles = 1;
                    }

                    int triples = (int)(otherHits * 0.1);
                    if (triples == 0)
                    {
                        triples = 1;
                    }

                    //Reverse engineer ERA to get earned runs
                    double ERA = Convert.ToDouble(row["ERA"]);
                    theStats.EarnedRunsAllowed = (int)(((inningsPitched) / 9) * ERA);

                    pStats                    = PitchingStats.LoadResultRanges(control, balks, hitByPitch, walks, strikeouts, groundOuts, flyouts, singles, doubles, triples, homeRuns);
                    id                        = row["playerID"].ToString();
                    pStats.Name               = name;
                    pStats.Stamina            = stamina;
                    pStats.StartPct           = (int)startPct;
                    pStats.PitchingStatistics = theStats;
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    pStats                    = PitchingStats.GeneratePitchingStats(PitcherTypes.Average);
                    pStats.Name               = name;
                    pStats.Stamina            = Dice.Roll(25, 50);
                    pStats.StartPct           = 0;
                    pStats.PitchingStatistics = theStats;
                }
                pitchingStats.Add(pStats);
            }
            return(pitchingStats.ToArray());
        }
 private static void AssertStats(PitchingStats PitchingStats, int ips, int ers, int ks)
 {
     Assert.Equal(ips, PitchingStats.InningsPitched);
     Assert.Equal(ers, PitchingStats.EarnedRuns);
     Assert.Equal(ks, PitchingStats.StrikeOuts);
 }