コード例 #1
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));
        }
コード例 #2
0
        private void CreateQuestionAnswersLists(InfoForStatisticsModel info)
        {
            AuthorDataAccess tests = new AuthorDataAccess();

            foreach (var question in info.Questions)
            {
                question.Value.AnswersId = new List <int>();
                question.Value.CorrectId = new List <int>();
                var answers = tests.GetAnswerByQuestionId(question.Key);
                foreach (var answer in answers)
                {
                    question.Value.AnswersId.Add(answer.ID);
                    if (answer.Correct == true)
                    {
                        question.Value.CorrectId.Add(answer.ID);
                    }
                }
            }
        }
コード例 #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));
        }