Ejemplo n.º 1
0
        public MultiTest CreateNoSameMultiTest(MultiTest test, object classForMultiTest, Dictionary <int, List <Tuple <QuestionLevel, int> > > questionsNo, int copyNos, int totalQuestion, int purpose, double moreTime, out string message)
        {
            test.CreatedBy   = UserService.CurrentUser.CurrentUser.Username;
            test.CreatedDate = DateTime.Now;
            test.UpdatedBy   = test.CreatedBy;
            test.UpdatedDate = DateTime.Now;
            test.IsMixedTest = false;
            if (classForMultiTest != null)
            {
                test.FK_ClassId = (int)classForMultiTest;
            }

            var allQuestions = m_questionService.GetPurposeQuestions(purpose);

            var questionsTmp = new List <Question>();

            for (int i = 0; i < copyNos; i++)
            {
                var questionsPerSubTest = GetRandomQuestionPerSubTest(questionsNo, allQuestions);
                questionsTmp.AddRange(questionsPerSubTest);

                var structure = new XDocument(new XElement("MultiTestCopy"));

                int k = 0;
                foreach (var question in questionsPerSubTest)
                {
                    var answers    = m_questionService.GetAnswerOfQuestion(question.QuestionId);
                    var answerList = new List <XElement>();
                    for (int j = 0; j < answers.Count; j++)
                    {
                        var answerElement = new XElement("A", new XAttribute("aOrder", j + 1), new XAttribute("aId", answers[j].AnswerId));
                        answerList.Add(answerElement);
                    }
                    structure.Element("MultiTestCopy")
                    .Add(new XElement("Q", new XAttribute("qOrder", ++k), new XAttribute("qId", question.QuestionId),
                                      answerList));
                }
                MultiTestCopy tc = new MultiTestCopy();
                //tc.MultiTest = test;
                tc.MultiTestCopyStructure = structure.ToString();
                test.MultiTestCopies.Add(tc);
            }

            foreach (Question question in questionsTmp)
            {
                var mtq = new MultiTestQuestion();
                mtq.Question = question;
                //mtq.MultiTest = test;
                test.MultiTestQuestions.Add(mtq);
            }

            message = string.Empty;
            return(test);
        }
Ejemplo n.º 2
0
        public MultiTest CreateMultiTest(MultiTest test, object classForMultiTest, Dictionary <int, List <Tuple <QuestionLevel, int> > > questionsNo, int copyNos, int totalQuestion, int purpose, double moreTime, out string message)
        {
            List <Question> questions = new List <Question>();

            foreach (int subjectId in questionsNo.Keys)
            {
                foreach (var questionNo in questionsNo[subjectId])
                {
                    questions.AddRange(RandomQuestion(subjectId, questionNo.Item1, questionNo.Item2, purpose));
                }
            }
            test.CreatedBy   = UserService.CurrentUser.CurrentUser.Username;
            test.CreatedDate = DateTime.Now;
            test.UpdatedBy   = test.CreatedBy;
            test.UpdatedDate = DateTime.Now;
            test.IsMixedTest = false;
            if (classForMultiTest != null)
            {
                test.FK_ClassId = (int)classForMultiTest;
            }

            foreach (Question question in questions)
            {
                MultiTestQuestion mtq = new MultiTestQuestion();
                mtq.Question = question;
                //mtq.MultiTest = test;
                test.MultiTestQuestions.Add(mtq);
            }
            // create test copy
            List <long> questionIds = questions.Select(q => q.QuestionId).ToList();
            Random      ran         = new Random();
            int         max         = 1000;

            for (int count = 0; count < copyNos; count++)
            {
                XDocument structure = new XDocument(new XElement("MultiTestCopy"));
                for (int i = 0; i < max; i++)
                {
                    int  index = ran.Next(questionIds.Count - 1);
                    long item  = questionIds[i % questionIds.Count];
                    questionIds[i % questionIds.Count] = questionIds[index];
                    questionIds[index] = item;
                }
                for (int i = 0; i < questionIds.Count; i++)
                {
                    List <Answer>   answers    = m_questionService.GetAnswerOfQuestion(questionIds[i]);
                    List <XElement> answerList = new List <XElement>();
                    for (int j = 0; j < answers.Count; j++)
                    {
                        XElement answerElement = new XElement("A", new XAttribute("aOrder", j + 1), new XAttribute("aId", answers[j].AnswerId));
                        answerList.Add(answerElement);
                    }
                    structure.Element("MultiTestCopy")
                    .Add(new XElement("Q", new XAttribute("qOrder", i + 1), new XAttribute("qId", questionIds[i]),
                                      answerList));
                }
                MultiTestCopy tc = new MultiTestCopy();
                //tc.MultiTest = test;
                tc.MultiTestCopyStructure = structure.ToString();
                test.MultiTestCopies.Add(tc);
            }
            double realTestTime = questions.Sum(q => q.Time);

            if (realTestTime > test.Time + moreTime)
            {
                message = "Thời gian chính xác để hoàn thành bài thi là: " + realTestTime +
                          "\nThời gian thi do người dùng cài đặt là: " + test.Time +
                          ".\nThời gian chênh lệch: " + Math.Abs(realTestTime - test.Time) +
                          "\nBạn có muốn tiếp tục tạo đề thi không?";
            }
            else
            {
                message = "Thời gian chính xác để hoàn thành bài thi là: " + realTestTime +
                          "\nThời gian thi do người dùng cài đặt là: " + test.Time +
                          ".\nThời gian chênh lệch: " + Math.Abs(realTestTime - test.Time) +
                          "\nBạn có muốn tiếp tục tạo đề thi không?";
            }
            return(test);
        }