Ejemplo n.º 1
0
        private double GetPointsOfMultipleChoiceQuestion(MultipleChoiceQuestion question)
        {
            var answers = Answers
                          .Where(x => x is MultipleChoiceAnswer)
                          .Select(y => y as MultipleChoiceAnswer)
                          .Where(z => z.GetQuestion().Id == question.Id)
                          .ToList();

            return(CalculatePointsExactly(question, answers));
        }
Ejemplo n.º 2
0
        private double CalculatePointsExactly(MultipleChoiceQuestion question, List <MultipleChoiceAnswer> answers)
        {
            var rightUserChoices = 0;
            var correctChoices   = question.Choices.Where(x => x.Correct);

            foreach (var choice in question.Choices)
            {
                var userChecked = answers.Any(x => x.ChoiceId == choice.Id);
                if (userChecked && choice.Correct)
                {
                    rightUserChoices++;
                }
                else if (userChecked && !choice.Correct)
                {
                    rightUserChoices--;
                }
            }
            double pointsPerRightChoice = (double)question.Points / (double)correctChoices.Count();
            double allPoints            = (double)rightUserChoices * (double)pointsPerRightChoice;
            double wholePoints          = Math.Floor(allPoints);
            double commaPortion         = allPoints - wholePoints;
            double points = wholePoints;

            if (commaPortion > 0 && commaPortion <= 0.5)
            {
                points += 0.5;
            }
            else if (commaPortion > 0.5 && commaPortion <= 1.0)
            {
                points += 1.0;
            }

            if (points > question.Points)
            {
                return(question.Points);
            }
            if (points < 0)
            {
                return(0);
            }
            return(points);
        }