Пример #1
0
 protected AbsResponseQuestion(Question question, List<int> checkIds)
 {
     if (checkIds.Count == 1)
     {
         isOneIdChecked = true;
     }
     QuestionID = question.QuestionID;
     ImageUrl = question.ImageUrl;
     Type = question.QuestionType.Type;
     LabelOrder = question.LabelOrder;
     QuestionTitle = question.QuestionTitle;
     NonChoiceScore = question.RealNoneChoiceScore().RoundTwo();
     var score = question.Answers.Sum(k => {
                 var point = k.RealScore();
                 if (!point.HasValue || point < 0) {
                     point = 0;
                 }
                 return point;
             });
     var calculateScore = (!score.HasValue || score < 0) ? 0 : score;
     ChoiceScore = calculateScore.RoundTwo();
     CheckedUserIds = checkIds;
     InTests = question.Test.UserInTests.FilterInTestsOnAttempSetting();
     InTestDetails = InTests.SelectMany(i => i.UserInTestDetails).Where(i => i.QuestionID == question.QuestionID);
 }
Пример #2
0
 public ResponseQuestionText(Question question, List<int> checkIds)
     : base(question, checkIds)
 {
 }
Пример #3
0
        public ResponseQuestionShort(Question question, List<int> checkIds)
            : base(question, checkIds)
        {
            var count = InTestDetails.Count();
            var point = InTestDetails.Sum(i => i.RealNonChoiceScore());
            decimal? averagePoint = decimal.Zero;
            if (count != 0) { averagePoint = point / count; }
            if (checkIds.Count == 0)
            {
                var id = checkIds.FirstOrDefault();
                if (id != 0)
                {
                    var detail = InTestDetails.FirstOrDefault(k => k.UserInTest.UserID == id);
                    if (detail != null)
                    {
                        averagePoint = detail.RealNonChoiceScore() ?? 0;
                    }
                }
            }
            var maxPoint = question.RealNoneChoiceScore().RoundTwo();
            _correctPraction = String.Format("{0:0.00} pt (of {1} pt)", averagePoint, maxPoint);

            if (checkIds.Count == 1)
            {
                var id = checkIds.FirstOrDefault();
                var detail = InTestDetails.FirstOrDefault(i => i.UserInTest.UserID == id);
                if (detail != null)
                {
                    _nonChoiceText = detail.AnswerContent;
                    _userNonScore = detail.RealNonChoiceScore();
                    _userNonScore = _userNonScore.RoundTwo();
                }
            }
        }
Пример #4
0
        public ResponseQuestionRadio(Question question, List<int> checkids)
            : base(question, checkids)
        {
            _totalUsersInTest = InTests.Count();
            _ids = InTestDetails.Where(k => checkids.Contains(k.UserInTest.UserID)).Select(i =>
            {
                var listid = new List<int>();
                if (i.AnswerIDs != null)
                {
                    var idStrings = i.AnswerIDs.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    idStrings.ForEach(k =>
                    {
                        var tempid = 0;
                        if (int.TryParse(k, out tempid))
                        {
                            listid.Add(tempid);
                        }
                    });
                }
                return listid;
            });
            var rightAnsId = 0;
            var rightAns = question.Answers.FirstOrDefault(k => k.IsRight);
            if (rightAns != null) { rightAnsId = rightAns.AnswerID; }

            var userRightCount = Ids.Count(k => k.Contains(rightAnsId));
            var correctPer = ExtensionModel.SafeDivide(userRightCount, TotalUsersInTest);
            _correctPercent = correctPer.ToPercent();
            _correctPraction = TotalUsersInTest == 0 ? "0" : userRightCount + "/" + TotalUsersInTest;
            var answers = question.Answers.ToList();
            _responseAnswers = new List<ResponseAnswer>();
            answers.ForEach(k =>
            {
                var ans = new ResponseAnswer(this, k);
                _responseAnswers.Add(ans);
            });
        }
Пример #5
0
        public ResponseQuestionMatching(Question question, List<int> checkids)
            : base(question, checkids)
        {
            _totalUsersInTest = InTests.Count();
            _ids = InTestDetails.Where(t => checkids.Contains(t.UserInTest.UserID)).Select(i =>
            {
                var listid = new List<List<int>>();
                if (i.AnswerIDs != null)
                {
                    var idStrings = i.AnswerIDs.Split(';').ToList();
                    idStrings.ForEach(k =>
                    {
                        var twoIdString = k.Split(',').ToList();
                        var twoIds = new List<int>();
                        twoIdString.ForEach(j =>
                        {
                            var tempid = 0;
                            if (int.TryParse(j, out tempid))
                            {
                                twoIds.Add(tempid);
                            }
                        });
                        listid.Add(twoIds);
                    });
                }
                return listid;
            });

            var userRightCount = ListCoupleIds.Count(k => k.All(i =>
            {
                var result = false;
                var firstId = i.ElementAtOrDefault(0);
                var secondId = i.ElementAtOrDefault(1);
                if (firstId != 0)
                {
                    var answer = question.Answers.FirstOrDefault(o => o.AnswerID == firstId);
                    if (answer != null && secondId != 0)
                    {
                        var dependAns = answer.AnswerChilds.FirstOrDefault(q => q.AnswerID == secondId);
                        if (dependAns != null)
                        {
                            result = true;
                        }
                    }
                }
                return result;
            }));
            var correctPer = ExtensionModel.SafeDivide(userRightCount, TotalUsersInTest);
            _correctPercent = correctPer.ToPercent();
            _correctPraction = TotalUsersInTest == 0 ? "0" : userRightCount + "/" + TotalUsersInTest;
            var answers = question.Answers.Where(i => !i.DependencyAnswerID.HasValue).ToList();
            _responseAnswers = new List<ResponseAnswer>();
            answers.ForEach(k =>
            {
                var ans = new ResponseAnswer(this, k);
                _responseAnswers.Add(ans);
            });
        }