Пример #1
0
        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 = Convert.ToString(values[22]);

            return(mlbBaseballBatter);
        }
Пример #2
0
        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);
        }