Пример #1
0
        private List <ActivatedSubject.Question> RandomQuestion(ActivatedSubject.ExamSuiteWithQuestion data, int randomCount)
        {
            seed = 0;
            List <ActivatedSubject.Question> QQ = new List <ViewModels.ExamBankModelsBack.ActivatedSubject.Question>();

            int remainQ  = randomCount;
            var shuffleQ = this.RandomData <ActivatedSubject.QuestionPool>(data.Questions);

            for (int i = 0; i < randomCount; i++)
            {
                var pickQ = shuffleQ.FirstOrDefault();
                if (pickQ.GroupCount <= remainQ)
                {
                    if (pickQ.GroupCount > 1)
                    {
                        var grouped = shuffleQ.Where(x => x.GroupId == pickQ.GroupId).OrderBy(x => x.QuestionNumber);
                        QQ.AddRange(grouped);

                        foreach (var qg in grouped)
                        {
                            shuffleQ.Remove(shuffleQ.Where(x => x._id == qg._id).FirstOrDefault());
                        }
                    }
                    else
                    {
                        QQ.Add(pickQ);

                        shuffleQ.Remove(shuffleQ.Where(x => x._id == pickQ._id).FirstOrDefault());
                    }

                    remainQ -= pickQ.GroupCount;
                }
            }

            return(QQ);
        }
Пример #2
0
        public List <ActivatedSubject.ExamSuiteWithQuestion> MapQuestion(List <ActivatedSubject.ExamSuite> examSuiteList)
        {
            var coltn = helper.GetCollection <ActivatedSubject.Question>(ActivatedSubject_Question);
            List <ActivatedSubject.ExamSuiteWithQuestion> examQuestion = new List <ActivatedSubject.ExamSuiteWithQuestion>();

            foreach (var item in examSuiteList)
            {
                ActivatedSubject.ExamSuiteWithQuestion examQ = new ActivatedSubject.ExamSuiteWithQuestion
                {
                    _id            = item._id,
                    TitleName      = item.TitleName,
                    TitleCode      = item.TitleCode,
                    CreateDateTime = item.CreateDateTime
                };

                List <ActivatedSubject.QuestionPool> qlist = new List <ActivatedSubject.QuestionPool>();
                //foreach (var qid in item.QuestionIds)
                //{
                //    var coltn = helper.GetCollection<ActivatedSubject.Question>(ActivatedSubject_Question);
                //    var qResult = coltn.Find(x => x._id == qid).FirstOrDefault();
                //    if (qResult != null)
                //    {
                //        //var qResult = this.helper.GetQuestion(result.ToList(), item.TitleCode).FirstOrDefault();

                //        //mapping
                //        ActivatedSubject.QuestionPool qpool = new ActivatedSubject.QuestionPool
                //        {
                //            QuestionNumber = qResult.QuestionNumber,
                //            isAllowRandomChoice = qResult.isAllowRandomChoice,
                //            Detail = qResult.Detail,
                //            Choices = qResult.Choices,
                //            GroupId = qResult.GroupId,
                //        };

                //        qlist.Add(qpool);
                //    }
                //}

                var qResult = coltn.Find(x => item.QuestionIds.Contains(x._id)).ToList().Select(x => new ActivatedSubject.QuestionPool
                {
                    _id                 = x._id,
                    Assets              = x.Assets,
                    CreateDateTime      = x.CreateDateTime,
                    QuestionNumber      = x.QuestionNumber,
                    IsAllowRandomChoice = !x.IsAllowRandomChoice, //HACK : meaning of word is wrong
                    Detail              = x.Detail,
                    Choices             = x.Choices,
                    GroupId             = x.GroupId,
                    //ExamCode = item.TitleCode,
                    ExamCode = item._id,
                });
                examQ.Questions = qResult.ToList();

                //map qGroup
                //var grouped = examQ.Questions.GroupBy(x => x.GroupId);
                foreach (var group in examQ.Questions.GroupBy(x => x.GroupId))
                {
                    if (group.Key == null)
                    {
                        foreach (var q in group)
                        {
                            q.GroupCount = 1;
                        }
                    }
                    else
                    {
                        int count = group.Count();
                        foreach (var q in group)
                        {
                            q.GroupCount = count;
                        }
                    }
                }
                examQuestion.Add(examQ);
            }


            return(examQuestion);
        }