Esempio n. 1
0
        private PlayerViewModel ConvertToViewModel(NFLPlayer player)
        {
            int    points               = 0;
            int    games                = 0;
            int    por                  = 0;
            int    wpor                 = 0;
            int    cpor                 = 0;
            double mean                 = 0;
            double standardDeviation    = 0;
            double variationCoefficient = 0;

            points = player.FanastyPoints();
            games  = player.GamesPlayed();

            if (games > 0)
            {
                int replacementScore = _replacementScores[player.Position];

                por  = (points / games) - replacementScore;
                wpor = (player.FanastyPointsInRecentGames(3) / 3) - replacementScore;

                mean = player.FanastyPointsPerGame().Mean();
                if (mean > 0)
                {
                    standardDeviation    = player.FanastyPointsPerGame().StandardDeviation();
                    variationCoefficient = standardDeviation / mean;


                    double multiplier = 1 - Math.Min(variationCoefficient, 1);

                    cpor = (RoundToInt(points * multiplier) / games) - replacementScore;
                }
            }

            PlayerViewModel vm = new PlayerViewModel(player);

            vm.PointsOverReplacement           = por;
            vm.WeightedPointsOverReplacement   = wpor;
            vm.ConsistentPointsOverReplacement = cpor;
            vm.FanastyPoints          = points;
            vm.TotalBonuses           = player.TotalBonuses();
            vm.Mean                   = RoundToInt(mean);
            vm.StandardDeviation      = RoundToInt(standardDeviation);
            vm.CoefficientOfVariation = RoundToInt(variationCoefficient * 100);
            return(vm);
        }