コード例 #1
0
        /// <summary>
        ///  Generate a Junior Level Test
        /// </summary>
        /// <param name="numberOfQuestions">Number of questions</param>
        /// <param name="category">Test category</param>
        /// <returns>Generated Test</returns>
        public TestModel GetTestWith(int numberOfQuestions, CategoryModel category)
        {
            var juniorTestQuestions = new List<TestQuestionModel>();

            var difficultyEasy = _difficultyLevelRepository.Get(d => d.Difficulty == DifficultyLevelEnum.Easy).SingleOrDefault();

            var difficultyMedium = _difficultyLevelRepository.Get(d => d.Difficulty == DifficultyLevelEnum.Medium).SingleOrDefault();

            var numberOfEasyQuestions   = 70.FloorPercentageOf(numberOfQuestions);
            var numberOfMediumQuestions = 30.FloorPercentageOf(numberOfQuestions);
            numberOfEasyQuestions      += numberOfQuestions - (numberOfEasyQuestions + numberOfMediumQuestions);

            var easyQuestions =
                _questionRepository
                    .Get(q => q.CategoryID == category.Id && q.DifficultyLevelID == difficultyEasy.Id)
                    .Take(numberOfEasyQuestions);

            var mediumQuestions =
                _questionRepository
                    .Get(q => q.CategoryID == category.Id && q.DifficultyLevelID == difficultyMedium.Id)
                    .Take(numberOfMediumQuestions);

            juniorTestQuestions = easyQuestions.Union(mediumQuestions).Shuffle().ToList();

            return new TestModel()
            {
                Id = Guid.NewGuid(),
                Name = string.Format("{0} Test", category.Name),
                Questions = juniorTestQuestions,
            };
        }
コード例 #2
0
 public TestQuestionModel(TestQuestion question)
 {
     this.Id = question.Id;
     CategoryID = question.CategoryID;
     Question = question.Question;
     DifficultyLevelID = question.DifficultyLevelID;
     QuestionAnswerModel = new QuestionAnswerModel(question.QuestionAnswer);
     CategoryModel = new CategoryModel(question.Category);
     DifficultyLevelModel = new DifficultyLevelModel(question.DifficultyLevel);
 }
コード例 #3
0
        /// <summary>
        ///  Generate an Intern Level Test
        /// </summary>
        /// <param name="numberOfQuestions">Number of questions</param>
        /// <param name="category">Test category</param>
        /// <returns>Generated Test</returns>
        public TestModel GetTestWith(int numberOfQuestions, CategoryModel category)
        {
            var difficulty = _difficultyLevelRepository.Get(d => d.Difficulty == DifficultyLevelEnum.Easy).SingleOrDefault();

            var questions =
                _questionRepository
                    .Get(q => q.CategoryID == category.Id && q.DifficultyLevelID == difficulty.Id)
                    .Take(numberOfQuestions).ToList();

            return new TestModel()
            {
                Id = Guid.NewGuid(),
                Name = string.Format("{0} Test", category.Name),
                Questions = questions,
            };
        }
コード例 #4
0
        /// <summary>
        ///  Generate a Senior Level Test
        /// </summary>
        /// <param name="numberOfQuestions">Number of questions</param>
        /// <param name="category">Test category</param>
        /// <returns>Generated Test</returns>
        public TestModel GetTestWith(int numberOfQuestions, CategoryModel category)
        {
            var seniorTestQuestions = new List<TestQuestionModel>();

            var difficultyEasy = _difficultyLevelRepository.Get(d => d.Difficulty == DifficultyLevelEnum.Easy).SingleOrDefault();

            var difficultyMedium = _difficultyLevelRepository.Get(d => d.Difficulty == DifficultyLevelEnum.Medium).SingleOrDefault();

            var difficultyHard = _difficultyLevelRepository.Get(d => d.Difficulty == DifficultyLevelEnum.Hard).SingleOrDefault();

            var difficultyVeryHard = _difficultyLevelRepository.Get(d => d.Difficulty == DifficultyLevelEnum.VeryHard).SingleOrDefault();

            ///TODO: we can refine this more by making a testgenerateRuleEngine so could ask to generate 10% easy, 50% hard, 30% hard, 10% very hard and TestGenerateFactory basically
            /// generates it. Eliminates all these classes
            var numberOfEasyQuestions     = 10.FloorPercentageOf(numberOfQuestions);
            var numberOfMediumQuestions   = 50.FloorPercentageOf(numberOfQuestions);
            var numberOfHardQuestions     = 30.FloorPercentageOf(numberOfQuestions);
            var numberOfVeryHardQuestions = 10.FloorPercentageOf(numberOfQuestions);
            numberOfHardQuestions += numberOfQuestions -
                                     (numberOfEasyQuestions +
                                      numberOfMediumQuestions +
                                      numberOfHardQuestions +
                                      numberOfVeryHardQuestions);

            IList<TestQuestionModel> easyQuestions = new List<TestQuestionModel>();

            if (difficultyEasy != null)
            {
                easyQuestions =
                    _questionRepository
                        .Get(q => q.CategoryID == category.Id && q.DifficultyLevelID == difficultyEasy.Id)
                        .Take(numberOfEasyQuestions)
                        .ToList();
            }

            IList<TestQuestionModel> mediumQuestions = new List<TestQuestionModel>();

            if (difficultyMedium != null)
            {
                mediumQuestions =
                    _questionRepository
                        .Get(q => q.CategoryID == category.Id && q.DifficultyLevelID == difficultyMedium.Id)
                        .Take(numberOfMediumQuestions)
                        .ToList();
            }

            IList<TestQuestionModel> hardQuestions = new List<TestQuestionModel>();

            if (difficultyHard != null)
            {
                hardQuestions =
                    _questionRepository
                        .Get(q => q.CategoryID == category.Id && q.DifficultyLevelID == difficultyHard.Id)
                        .Take(numberOfHardQuestions)
                        .ToList();
            }

            IList<TestQuestionModel> veryHardQuestions = new List<TestQuestionModel>();

            if (difficultyVeryHard != null)
            {
                 veryHardQuestions =
                    _questionRepository
                        .Get(q => q.CategoryID == category.Id && q.DifficultyLevelID == difficultyVeryHard.Id)
                        .Take(numberOfVeryHardQuestions)
                        .ToList();
            }

            seniorTestQuestions =
                easyQuestions
                    .Union(mediumQuestions)
                    .Union(hardQuestions)
                    .Union(veryHardQuestions).Shuffle().ToList();

            return new TestModel()
            {
                Id = Guid.NewGuid(),
                Name = string.Format("{0} Test", category.Name),
                Questions = seniorTestQuestions,
            };
        }