public static MLBBaseballBatter FromCsv(string csvLine) { string[] values = csvLine.Split(','); MLBBaseballBatter mlbBaseballBatter = new MLBBaseballBatter(); mlbBaseballBatter.InductedToHallOfFame = Convert.ToBoolean(values[0]); mlbBaseballBatter.OnHallOfFameBallot = Convert.ToBoolean(values[1]); mlbBaseballBatter.FullPlayerName = Convert.ToString(values[2]); mlbBaseballBatter.YearsPlayed = float.Parse(values[3], System.Globalization.NumberStyles.Any); mlbBaseballBatter.AB = float.Parse(values[4], System.Globalization.NumberStyles.Any); mlbBaseballBatter.R = float.Parse(values[5], System.Globalization.NumberStyles.Any); mlbBaseballBatter.H = float.Parse(values[6], System.Globalization.NumberStyles.Any); mlbBaseballBatter.Doubles = float.Parse(values[7], System.Globalization.NumberStyles.Any); mlbBaseballBatter.Triples = float.Parse(values[8], System.Globalization.NumberStyles.Any); mlbBaseballBatter.HR = float.Parse(values[9], System.Globalization.NumberStyles.Any); mlbBaseballBatter.RBI = float.Parse(values[10], System.Globalization.NumberStyles.Any); mlbBaseballBatter.SB = float.Parse(values[11], System.Globalization.NumberStyles.Any); mlbBaseballBatter.BattingAverage = float.Parse(values[12], System.Globalization.NumberStyles.Any); mlbBaseballBatter.SluggingPct = float.Parse(values[13], System.Globalization.NumberStyles.Any); mlbBaseballBatter.AllStarAppearances = float.Parse(values[14]); mlbBaseballBatter.MVPs = float.Parse(values[15], System.Globalization.NumberStyles.Any); mlbBaseballBatter.TripleCrowns = float.Parse(values[16], System.Globalization.NumberStyles.Any); mlbBaseballBatter.GoldGloves = float.Parse(values[17], System.Globalization.NumberStyles.Any); mlbBaseballBatter.MajorLeaguePlayerOfTheYearAwards = float.Parse(values[18], System.Globalization.NumberStyles.Any); mlbBaseballBatter.TB = float.Parse(values[19], System.Globalization.NumberStyles.Any); mlbBaseballBatter.TotalPlayerAwards = float.Parse(values[20], System.Globalization.NumberStyles.Any); mlbBaseballBatter.LastYearPlayed = float.Parse(values[21], System.Globalization.NumberStyles.Any); mlbBaseballBatter.ID = float.Parse(values[22], System.Globalization.NumberStyles.Any); return(mlbBaseballBatter); }
public MLBBaseballBatter CalculateStatisticsProratedBySeason(int numberOfSeasons) { var batter = new MLBBaseballBatter { FullPlayerName = this.FullPlayerName, ID = this.ID, InductedToHallOfFame = false, LastYearPlayed = this.LastYearPlayed, OnHallOfFameBallot = false, YearsPlayed = numberOfSeasons * 1f, AB = (this.AB / this.YearsPlayed) * numberOfSeasons, R = (this.R / this.YearsPlayed) * numberOfSeasons, H = (this.H / this.YearsPlayed) * numberOfSeasons, Doubles = (this.Doubles / this.YearsPlayed) * numberOfSeasons, Triples = (this.Triples / this.YearsPlayed) * numberOfSeasons, HR = (float)Math.Round( ((this.HR / this.YearsPlayed) * numberOfSeasons), 0, MidpointRounding.AwayFromZero), RBI = (this.RBI / this.YearsPlayed) * numberOfSeasons, SB = (this.SB / this.YearsPlayed) * numberOfSeasons, BattingAverage = (float) ( ((this.H / this.YearsPlayed) * numberOfSeasons) / ((this.AB / this.YearsPlayed) * numberOfSeasons) ), AllStarAppearances = (float)Math.Round( (Decimal)(this.AllStarAppearances / this.YearsPlayed) * numberOfSeasons, 0, MidpointRounding.AwayFromZero), MVPs = (this.MVPs / this.YearsPlayed) * numberOfSeasons, TripleCrowns = (this.TripleCrowns / this.YearsPlayed) * numberOfSeasons, GoldGloves = (float)Math.Round( ((this.GoldGloves / this.YearsPlayed) * numberOfSeasons), 0, MidpointRounding.AwayFromZero), MajorLeaguePlayerOfTheYearAwards = (this.MajorLeaguePlayerOfTheYearAwards / this.YearsPlayed) * numberOfSeasons, TB = (float)Math.Round( ((this.TB / this.YearsPlayed) * numberOfSeasons), 0, MidpointRounding.AwayFromZero), TotalPlayerAwards = (float)Math.Round( (this.TotalPlayerAwards / this.YearsPlayed) * numberOfSeasons, 0, MidpointRounding.AwayFromZero), SluggingPct = TB / AB }; return(batter); }
public Task <List <MLBBaseballBatter> > GetSampleBaseballData() { MLBBaseballBatter badMLBBatter = new MLBBaseballBatter { FullPlayerName = "Barry Badd (fictitious)", ID = 100f, InductedToHallOfFame = false, LastYearPlayed = 0f, OnHallOfFameBallot = false, YearsPlayed = 2f, AB = 100f, R = 10f, H = 30f, Doubles = 1f, Triples = 1f, HR = 1f, RBI = 10f, SB = 10f, BattingAverage = 0.3f, SluggingPct = 0.15f, AllStarAppearances = 0f, MVPs = 0f, TripleCrowns = 0f, GoldGloves = 0f, MajorLeaguePlayerOfTheYearAwards = 0f, TB = 200f, TotalPlayerAwards = 0 }; MLBBaseballBatter averageMLBBatter = new MLBBaseballBatter { FullPlayerName = "Andy Average (fictitious)", ID = 200f, InductedToHallOfFame = false, LastYearPlayed = 0f, OnHallOfFameBallot = false, YearsPlayed = 17f, AB = 8393f, R = 1162f, H = 2300f, Doubles = 410f, Triples = 8f, HR = 400f, RBI = 1312f, SB = 9f, BattingAverage = 0.278f, SluggingPct = 0.476f, AllStarAppearances = 5f, MVPs = 0f, TripleCrowns = 0f, GoldGloves = 0f, MajorLeaguePlayerOfTheYearAwards = 0f, TB = 3910f, TotalPlayerAwards = 4 }; MLBBaseballBatter greatMLBBatter = new MLBBaseballBatter { FullPlayerName = "Gary The Great (fictitious)", ID = 300f, InductedToHallOfFame = false, LastYearPlayed = 0f, OnHallOfFameBallot = false, YearsPlayed = 20f, AB = 10000f, R = 1900f, H = 3500f, Doubles = 500f, Triples = 150f, HR = 600f, RBI = 1800f, SB = 400f, BattingAverage = 0.350f, SluggingPct = 0.65f, AllStarAppearances = 14f, MVPs = 2f, TripleCrowns = 1f, GoldGloves = 4f, MajorLeaguePlayerOfTheYearAwards = 2f, TB = 7000f, TotalPlayerAwards = 30 }; MLBBaseballBatter babeRuth = new MLBBaseballBatter { FullPlayerName = "Babe Ruth", ID = 400f, InductedToHallOfFame = true, LastYearPlayed = 1935f, OnHallOfFameBallot = true, YearsPlayed = 22f, AB = 8399f, R = 2174f, H = 2873f, Doubles = 506f, Triples = 136f, HR = 714f, RBI = 2214f, SB = 123f, BattingAverage = 0.342f, SluggingPct = 0.690f, AllStarAppearances = 2f, MVPs = 1f, TripleCrowns = 0f, GoldGloves = 0f, MajorLeaguePlayerOfTheYearAwards = 0f, TB = 5793f, TotalPlayerAwards = 33 }; MLBBaseballBatter mikeTrout = new MLBBaseballBatter { FullPlayerName = "Mike Trout", ID = 500f, InductedToHallOfFame = false, LastYearPlayed = 2019f, OnHallOfFameBallot = false, YearsPlayed = 9f, AB = 4340f, R = 903f, H = 1324f, Doubles = 251f, Triples = 46f, HR = 285f, RBI = 752f, SB = 200f, BattingAverage = 0.305f, SluggingPct = 0.581f, AllStarAppearances = 8f, MVPs = 2f, TripleCrowns = 0f, GoldGloves = 0f, MajorLeaguePlayerOfTheYearAwards = 0f, TB = 2522f, TotalPlayerAwards = 13 }; MLBBaseballBatter haroldBaines = new MLBBaseballBatter { FullPlayerName = "Harold Baines", ID = 600f, InductedToHallOfFame = false, LastYearPlayed = 2001f, OnHallOfFameBallot = false, YearsPlayed = 22f, AB = 9908f, R = 1299f, H = 2866f, Doubles = 488f, Triples = 49f, HR = 384f, RBI = 1628f, SB = 34f, BattingAverage = 0.289f, SluggingPct = 0.289f, AllStarAppearances = 6f, MVPs = 0f, TripleCrowns = 0f, GoldGloves = 0f, MajorLeaguePlayerOfTheYearAwards = 0f, TB = 5525f, TotalPlayerAwards = 4 }; List <MLBBaseballBatter> batters = new List <MLBBaseballBatter>() { badMLBBatter, averageMLBBatter, greatMLBBatter, babeRuth, mikeTrout, haroldBaines }; return(Task.FromResult( batters )); }