示例#1
0
 /// <summary>
 ///     获取所有考试
 /// </summary>
 /// <returns></returns>
 public List <tbExamination> GetAllExamination()
 {
     return(_examinationDb.GetAllList <tbExamination>(false));
 }
示例#2
0
        /// <summary>
        ///     成绩与排名统计
        /// </summary>
        /// <returns></returns>
        public List <ExamGradeRank> GetGradeRank()
        {
            var gradeRanklist = new List <ExamGradeRank>();

            List <tbExamSendStudent> examStudentList =
                _examinationDB.GetAllList <tbExamSendStudent>(Query.And(Query.EQ("Status", 0)));

            Dictionary <int, Sys_User> dicuser = _userDB.GetList().ToDictionary(p => p.UserId, p => p);

            foreach (tbExamination exam in _examinationDB.GetPublishExam())
            {
                List <tbExamSendStudent> StudentList = examStudentList.Where(p => p.RelationID == exam._id).ToList();
                foreach (tbExamSendStudent model in StudentList)
                {
                    if (dicuser.ContainsKey(model.UserID))
                    {
                        int CorrectAnswerNumber = model.StudentAnswerList.Count(p => p.GetScore > 0);                         //答对题数
                        int WrongAnswerNumber   = model.StudentAnswerList.Count(p => p.GetScore == 0 && p.DoneFlag == 1);
                        //答错题数
                        int sumScore      = model.StudentAnswerList.Sum(p => p.GetScore);                    //得分
                        int questionScore = StudentList.Where(p => p.UserID == model.UserID)
                                            .Sum(p => p.StudentAnswerList.Sum(e => e.Score));                //试题的总分数

                        var temp = new ExamGradeRank();

                        temp.examtionID       = exam._id;
                        temp.examinationTitle = exam.ExaminationTitle;
                        temp.PercentFlag      = exam.PercentFlag;
                        if (dicuser.Count == 0 || !dicuser.ContainsKey(model.UserID))
                        {
                            temp.jobnum   = "--";
                            temp.realname = "--";
                            temp.deptcode = "--";
                            temp.postcode = "--";
                            temp.deptID   = 0;
                            temp.postID   = 0;
                        }
                        else
                        {
                            temp.jobnum   = dicuser[model.UserID].JobNum;
                            temp.realname = dicuser[model.UserID].Realname;
                            temp.deptcode = dicuser[model.UserID].DeptCode;
                            temp.postcode = dicuser[model.UserID].PostCode;
                            temp.deptID   = dicuser[model.UserID].DeptId;
                            temp.postID   = dicuser[model.UserID].PostId;
                        }
                        if (model.StudentAnswerList == null || model.StudentAnswerList.Count == 0)
                        {
                            //已答题数
                            temp.hasAnswerNumber = 0;
                            //未答题数
                            temp.NotAnswerNumber = 0;
                        }
                        else
                        {
                            //已答题数
                            temp.hasAnswerNumber = model.StudentAnswerList.Count(p => p.DoneFlag == 1);
                            //未答题数
                            temp.NotAnswerNumber = model.StudentAnswerList.Count(p => p.DoneFlag == 0);
                        }

                        //答对题数
                        temp.CorrectAnswerNumber = CorrectAnswerNumber;
                        //答错题数
                        temp.WrongAnswerNumber = WrongAnswerNumber;
                        //正确率
                        temp.CorrectRate = model.StudentAnswerList.Count == 0
                                                                                           ? 0
                                                                                           : Math.Round(
                            Convert.ToDouble(CorrectAnswerNumber) /
                            Convert.ToDouble(model.StudentAnswerList.Count) * 100, 2);
                        //错误率
                        temp.WrongRate = model.StudentAnswerList.Count == 0
                                                                                         ? 0
                                                                                         : Math.Round(
                            Convert.ToDouble(WrongAnswerNumber) /
                            Convert.ToDouble(model.StudentAnswerList.Count) * 100, 2);
                        //通过状态
                        temp.IsPass = sumScore == 0 ? 0 : (sumScore >= (exam.PassScore / 100) * questionScore ? 1 : 0);
                        //得分
                        temp.sumSocre      = sumScore;
                        temp.questionScore = questionScore;
                        temp.StartDate     = exam.ExamBeginTime.ToLocalTime();
                        temp.EndDate       = exam.ExamEndTime.ToLocalTime();

                        gradeRanklist.Add(temp);
                    }
                }

                List <int> list = gradeRanklist.Where(p => p.examinationTitle == exam.ExaminationTitle).OrderByDescending(p => p.sumSocre).Select(p => p.sumSocre).ToList();
                foreach (var item in gradeRanklist.Where(p => p.examinationTitle == exam.ExaminationTitle))
                {
                    item.Rank = Rank(item.sumSocre, list);
                }
            }


            return(gradeRanklist.Count == 0 ? new List <ExamGradeRank>() : gradeRanklist);
        }