Exemple #1
0
        /// <summary>
        /// 添加试题冗余
        /// </summary>
        /// <param name="question">试题冗余</param>
        /// <returns></returns>
        public List <tbQuestionRedundancy> InsertQuestionRedundancys(IEnumerable <int> questionIds)
        {
            var result = new List <tbQuestionRedundancy>();

            if (!questionIds.Any())
            {
                return(result);
            }
            var questions = GetQuestionList(questionIds.ToArray());

            foreach (var tmp in questions)
            {
                var questionRed = new tbQuestionRedundancy
                {
                    QuestionId         = tmp._id,
                    QuestionSortID     = tmp.QuestionSortID,
                    QuestionOpen       = tmp.QuestionOpen,
                    UserID             = tmp.UserID,
                    CreateTime         = tmp.CreateTime,
                    FileUpload         = tmp.FileUpload,
                    LastUpdateTime     = tmp.LastUpdateTime,
                    QuestionAnalysis   = tmp.QuestionAnalysis,
                    QuestionAnswer     = tmp.QuestionAnswer,
                    QuestionAnswerKeys = tmp.QuestionAnswerKeys,
                    QuestionAvailable  = tmp.QuestionAvailable,
                    QuestionContent    = tmp.QuestionContent,
                    QuestionKey        = tmp.QuestionKey,
                    QuestionLevel      = tmp.QuestionLevel,
                    QuestionType       = tmp.QuestionType,
                    Status             = tmp.Status,
                    TenantId           = tmp.TenantId
                };
                questionRed._id = InsertQuestionRedundancy(questionRed);

                result.Add(questionRed);
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        ///     单题得分
        /// </summary>
        /// <param name="qu">试题信息</param>
        /// <param name="userAnswer">学员答案</param>
        /// <param name="score">本题分值</param>
        /// <returns></returns>
        private int GetScore(tbQuestionRedundancy qu, string userAnswer, int score, int sourseType)
        {
            int getScore = 0; //是否得分(0:未得分;1:得分)

            switch (qu.QuestionType)
            {
            case 1:     //问答
            {
                //目前需求,直接考试,问答、填空,不给分,全部手动批阅
                //课程中的考试,问答、填空,是直接给分
                if (sourseType == 1)
                {
                    //正确答案关键字
                    string[] rightKeys = qu.QuestionAnswerKeys.Split(' ');
                    int      count     = 0; //答对个数
                    rightKeys.ToList().ForEach(p => { count += userAnswer.Contains(p) ? 1 : 0; });
                    getScore = score * count / rightKeys.Count();
                }
            }
            break;

            case 2:     //单选
            case 3:     //多选
            {
                string rightAnswer = "";
                qu.QuestionAnswer.ForEach(
                    p =>
                    {
                        rightAnswer += p.AnswerFlag == 1
                                                   ? (rightAnswer == "" ? (p.Order + "") : ("," + p.Order))
                                                   : "";
                    });
                string tmpUseranswer  = userAnswer.GetArray().OrderBy(p => p).GetString();
                string tmpRightanswer = rightAnswer.GetArray().OrderBy(p => p).GetString();
                getScore = tmpUseranswer == tmpRightanswer ? score : 0;
            }
            break;

            case 4:     //判断
            {
                string rightAnswer = qu.QuestionAnswer.FirstOrDefault(p => p.AnswerFlag == 1).Answer;
                getScore = userAnswer == rightAnswer ? score : 0;
            }
            break;

            case 5:     //填空
            {
                //目前需求,直接考试,问答、填空,不给分,全部手动批阅
                //课程中的考试,问答、填空,是直接给分
                if (sourseType == 1)
                {
                    //正确答案关键字
                    string[] rightKeys = qu.QuestionAnswerKeys.Split(' ');
                    //学员答案关键字
                    string[] uanswer = userAnswer.Split(new[] { "##**##" }, StringSplitOptions.None);
                    int      count   = 0;  //答对个数
                    for (int i = 0; i < rightKeys.Count(); i++)
                    {
                        if (uanswer.Count() > i && rightKeys[i] == uanswer[i])
                        {
                            count++;
                        }
                    }
                    getScore = score * count / rightKeys.Count();
                }
            }
            break;

            case 6:     //情景
            {
                switch (qu.QuestionAnswer[0].AnswerType)
                {
                case 0:
                {
                    //目前需求,直接考试,问答、填空,不给分,全部手动批阅
                    //课程中的考试,问答、填空,是直接给分
                    if (sourseType == 1)
                    {
                        //正确答案关键字
                        string[] rightKeys = qu.QuestionAnswerKeys.Split(' ');
                        int      count     = 0;        //答对个数
                        rightKeys.ToList().ForEach(p => { count += userAnswer.Contains(p) ? 1 : 0; });
                        getScore = score * count / rightKeys.Count();
                    }
                }
                break;

                case 1:
                case 2:
                {
                    string rightAnswer = "";
                    qu.QuestionAnswer.ForEach(
                        p =>
                            {
                                rightAnswer += p.AnswerFlag == 1
                                                               ? (rightAnswer == ""
                                                                      ? (p.Order + "")
                                                                      : ("," + p.Order))
                                                               : "";
                            });
                    string tmpUseranswer  = userAnswer.GetArray().OrderBy(p => p).GetString();
                    string tmpRightanswer = rightAnswer.GetArray().OrderBy(p => p).GetString();
                    getScore = tmpUseranswer == tmpRightanswer ? score : 0;
                }
                break;
                }
            }
            break;
            }
            return(getScore);
        }
Exemple #3
0
 /// <summary>
 /// 修改试题
 /// </summary>
 /// <param name="question">试题</param>
 /// <returns></returns>
 public int ModifyQuestionRedundancy(tbQuestionRedundancy question)
 {
     Qdb.Modify(question);
     return(question._id);
 }
Exemple #4
0
 /// <summary>
 /// 添加试题冗余
 /// </summary>
 /// <param name="question">试题冗余</param>
 /// <returns></returns>
 public int InsertQuestionRedundancy(tbQuestionRedundancy question)
 {
     return(Qdb.Insert <tbQuestionRedundancy>(question));
 }
Exemple #5
0
        /// <summary>
        /// 获取试卷的试题
        /// </summary>
        /// <param name="exampaper">试卷信息</param>
        /// <param name="exam">试卷信息</param>
        /// <param name="examuser">学员答案</param>
        /// <param name="examination">考试信息</param>
        private void GetExampaper(ExampaperShow exampaper, tbExampaperRedundancy exam, tbExamSendStudent examuser, tbExamination examination)
        {
            var radomOrder = string.IsNullOrWhiteSpace(examination.RadomOrderFlag) ? new string[0] : examination.RadomOrderFlag.Split(',');

            //IMongoQuery query = Query.In("_id", new BsonArray(exam.QuestionList.Select(p => p.Qid)));
            IMongoQuery query = Query.In("_id", new BsonArray(examuser.StudentAnswerList.Select(p => p.Qid)));

            if (!examuser.StudentAnswerList.Any())
            {
                //如果没有试题,则加入试题
                if (exam.ExamType == 0)
                {
                    exam.QuestionList.ForEach(p =>
                    {
                        examuser.StudentAnswerList.Add(new ReStudentExamAnswer
                        {
                            Qid               = p.Qid,
                            Questionid        = p.Questionid,
                            Order             = p.QOrder,
                            QType             = p.QType,
                            Score             = p.QScore,
                            DoneFlag          = 0,
                            Answer            = "",
                            Evlution          = "",
                            GetScore          = 0,
                            WrongQuestionFlag = 0
                        });
                    });
                }
                else
                {
                    examuser = new RetechWing.BusinessCommon.Examination.GenerateExampaper().RandomGenerate(examuser, exam.QuestionRule);
                    var questionIds = examuser.StudentAnswerList.Select(p => p.Questionid);
                    var questions   = Etdb.GetAllList <tbQuestion>(Query.In("_id", new BsonArray(questionIds)));
                    int i           = 1;
                    foreach (var item in examuser.StudentAnswerList)
                    {
                        var tmp         = questions.FirstOrDefault(p => p._id == item.Questionid);
                        var questionRed = new tbQuestionRedundancy
                        {
                            QuestionId         = tmp._id,
                            QuestionSortID     = tmp.QuestionSortID,
                            QuestionOpen       = tmp.QuestionOpen,
                            UserID             = tmp.UserID,
                            CreateTime         = tmp.CreateTime,
                            FileUpload         = tmp.FileUpload,
                            LastUpdateTime     = tmp.LastUpdateTime,
                            QuestionAnalysis   = tmp.QuestionAnalysis,
                            QuestionAnswer     = tmp.QuestionAnswer,
                            QuestionAnswerKeys = tmp.QuestionAnswerKeys,
                            QuestionAvailable  = tmp.QuestionAvailable,
                            QuestionContent    = tmp.QuestionContent,
                            QuestionKey        = tmp.QuestionKey,
                            QuestionLevel      = tmp.QuestionLevel,
                            QuestionType       = tmp.QuestionType,
                            Status             = tmp.Status,
                            TenantId           = tmp.TenantId
                        };
                        item.Qid   = Etdb.Insert <tbQuestionRedundancy>(questionRed);
                        item.Order = i;
                        i++;
                    }
                }
                Etdb.Modify <tbExamSendStudent>(examuser);

                query = Query.In("_id", new BsonArray(examuser.StudentAnswerList.Select(p => p.Qid)));
            }

            ////从缓存中读取所有问题
            //List<tbQuestionRedundancy> quList; //获取试题
            //var cachekey = "examquestions:tenant:" + exam.TenantId;
            //quList = _cacheService.Get<List<tbQuestionRedundancy>>(cachekey);
            //if (quList == null || quList.Count == 0)
            //{
            //    quList = Etdb.GetAllList<tbQuestionRedundancy>(query);
            //    _cacheService.Set(cachekey, quList, CachingExpirationType.Stable);
            //}

            var quList = Etdb.GetAllList <tbQuestionRedundancy>(query);

            //题目随机
            if (radomOrder.Contains("1"))
            {
                var radomList = new List <int>();
                var next      = 0;
                var length    = examuser.StudentAnswerList.Count;
                for (int i = 0; i < length; i++)
                {
                    do
                    {
                        next = new Random().Next();
                        if (!radomList.Contains(next))
                        {
                            examuser.StudentAnswerList[i].Order = next;
                            radomList.Add(next);
                            break;
                        }
                    } while (true);
                }
            }

            var m = 0;

            examuser.StudentAnswerList.OrderBy(p => p.Order).ToList().ForEach(p =>
            {
                p.Order = ++m;
                tbQuestionRedundancy qu = quList.FirstOrDefault(q => q._id == p.Qid);
                if (qu != null)
                {
                    ReStudentExamAnswer an = examuser == null
                                                     ? null
                                                     : examuser.StudentAnswerList.FirstOrDefault(
                        pa => pa.Qid == p.Qid);
                    var newqu = new MQuestion
                    {
                        QAnswerType = qu.QuestionType == 6 ? qu.QuestionAnswer[0].AnswerType : 0,
                        QType       = qu.QuestionType,
                        //QuestionContent = qu.QuestionContent,
                        QuestionContent   = qu.QuestionContent.NoHtml().HtmlDecode(),
                        QuestionID        = qu._id,
                        QuestionLevel     = EnumsLanguage.GetString(((QuestionLevel)qu.QuestionLevel).ToString()),
                        QuestionOrder     = p.Order,
                        Score             = p.Score,
                        UserAnswer        = an == null ? "" : (an.Answer),
                        UserAnswerScore   = an == null ? 0 : an.GetScore,
                        FillBlankCount    = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Length - 1,
                        WrongQuestionFlag = an == null ? 0 : an.WrongQuestionFlag,
                        QuestionAnalysis  = qu.QuestionAnalysis
                    };

                    //记录选项随机前的原有序号
                    var tmpquestionlist = new List <MQuestionAnswer>();

                    //选择随机
                    if (radomOrder.Contains("2"))
                    {
                        var radomList = new List <int>();
                        var next      = 0;
                        var length    = qu.QuestionAnswer.Count;
                        for (int i = 0; i < length; i++)
                        {
                            do
                            {
                                next = new Random().Next();
                                if (!radomList.Contains(next))
                                {
                                    tmpquestionlist.Add(new MQuestionAnswer
                                    {
                                        Order    = next,
                                        oldOrder = qu.QuestionAnswer[i].Order
                                    });
                                    qu.QuestionAnswer[i].Order = next;
                                    radomList.Add(next);
                                    break;
                                }
                            } while (true);
                        }
                    }

                    var n = 0;
                    qu.QuestionAnswer.OrderBy(o => o.Order).ToList().ForEach(pa =>
                    {
                        var tmp  = tmpquestionlist.FirstOrDefault(t => t.Order == pa.Order);
                        pa.Order = ++n;
                        newqu.QuestionAnswer.Add(new MQuestionAnswer
                        {
                            AnswerContent = pa.Answer,
                            AnswerFlag    = pa.AnswerFlag,
                            AnswerType    = pa.AnswerType,
                            Order         = pa.Order,
                            QuID          = newqu.QuestionID,
                            QType         = newqu.QType,
                            oldOrder      = tmp == null ? pa.Order : tmp.oldOrder
                        });
                    });

                    qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile
                    {
                        _fileName = pa.FileName,
                        _fileType = pa.FileType,
                        _realName = pa.RealName
                    }));
                    exampaper.QuestionList.Add(newqu);
                }
            });

            exampaper.QuestionList = exampaper.QuestionList.OrderBy(p => p.QuestionOrder).ToList();
        }