コード例 #1
0
        public void GetPercentageOfPeopleChoosingAnswerTest(int questionId)
        {
            QuestionStatistics       statistic = new QuestionStatistics(questionId);
            Dictionary <int, double> actual    = statistic.GetPercentageOfPeopleChoosingAnswer(questionId);
            QuestionExpectedMock     mock      = new QuestionExpectedMock();

            Assert.AreEqual(mock.GetPercentageOfPeopleChoosingAnswer(questionId), actual);
        }
コード例 #2
0
        public ActionResult <TestOutputModel> GetTestAllInfoById(int testId)
        {
            Mapper           mapper       = new Mapper();
            AuthorDataAccess tests        = new AuthorDataAccess();
            var            test           = tests.GetTestById(testId);
            TestStatistics testStatistics = new TestStatistics(testId);

            if (test == null)
            {
                return(BadRequest("Теста не существует"));
            }
            TestOutputModel   model = mapper.ConvertTestDTOToTestOutputModel(tests.GetTestById(testId));
            PassedFailedModel pfs   = testStatistics.GetPassedFailedStats(testId);

            model.Questions     = mapper.ConvertQuestionDTOToQuestionModelList(tests.GetQuestionsByTestID(testId));
            model.Tags          = mapper.ConvertTagDTOToTagModelList(tests.GetTagsInTest(testId));
            model.AverageResult = testStatistics.GetAverageResults(testId);
            model.Passed        = pfs.Passed;
            model.Failed        = pfs.Failed;
            model.SuccessRate   = pfs.SuccessRate;
            foreach (QuestionOutputModel qModel in model.Questions)
            {
                qModel.Answers = mapper.ConvertAnswerDTOToAnswerModelList(tests.GetAnswerByQuestionId(qModel.ID));
                QuestionStatistics statistics = new QuestionStatistics(qModel.ID);
                qModel.PercentageOfCorrectlyAnswered = statistics.GetPercentageOfCorrectlyAnswered(qModel.ID);
                Dictionary <int, double> answersPercent = new Dictionary <int, double>();
                answersPercent = statistics.GetPercentageOfPeopleChoosingAnswer(qModel.ID);
                foreach (var answer in qModel.Answers)
                {
                    foreach (var i in answersPercent)
                    {
                        if (answer.ID == i.Key)
                        {
                            answer.PercentageOfPeopleChoosingAnswer = i.Value;
                        }
                        else
                        {
                            answer.PercentageOfPeopleChoosingAnswer = 0;
                        }
                    }
                }
            }
            return(Ok(model));
        }
コード例 #3
0
        public ActionResult <List <AnswerOutputModel> > GetAnswersByQuestionId(int questionId)
        {
            Mapper                   mapper         = new Mapper();
            AuthorDataAccess         answers        = new AuthorDataAccess();
            List <AnswerOutputModel> listOfModels   = mapper.ConvertAnswerDTOToAnswerModelList(answers.GetAnswerByQuestionId(questionId));
            QuestionStatistics       statistics     = new QuestionStatistics(questionId);
            Dictionary <int, double> answersPercent = statistics.GetPercentageOfPeopleChoosingAnswer(questionId);

            foreach (var model in listOfModels)
            {
                foreach (var i in answersPercent)
                {
                    if (model.ID == i.Key)
                    {
                        model.PercentageOfPeopleChoosingAnswer = i.Value;
                    }
                    else
                    {
                        model.PercentageOfPeopleChoosingAnswer = 0;
                    }
                }
            }
            return(Ok(listOfModels));
        }