private DtoStudentReport GetSelect(int studyTime)
        {
            DtoStudentReport studentReport = new DtoStudentReport();

            studentReport.StudyTime      = studyTime;                                    //学习时长 2
            studentReport.StudyDate      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //学习时间
            studentReport.TotalCoins     = 0;                                            //总金币数
            studentReport.TotalScore     = 2;                                            //总星数
            studentReport.SubjectCount   = 8;
            studentReport.KnowledgeRates = 0.2;
            studentReport.ExcellentRates = 12;
            List <StudentAnswerBase> answerBase = new List <StudentAnswerBase>()
            {
                new StuSelectAnswer()
                {
                    KnowledgeId = 10003, ResultStars = 2
                },
                new StuSelectAnswer()
                {
                    KnowledgeId = 10005, ResultStars = 0
                },
                new StuSelectAnswer()
                {
                    KnowledgeId = 10007, ResultStars = 1
                },
                new StuSelectAnswer()
                {
                    KnowledgeId = 10009, ResultStars = 0
                }
            };
            var knowledgeShow = answerBase.GroupBy(s => s.KnowledgeId);

            studentReport.Knowledge = GetKnowledge(knowledgeShow);
            return(studentReport);
        }
        private DtoStudentReport GetFillBlank(int studyTime)
        {
            DtoStudentReport studentReport = new DtoStudentReport();

            studentReport.StudyTime      = studyTime;                                    //学习时长 4
            studentReport.StudyDate      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //学习时间
            studentReport.TotalCoins     = 0;                                            //总金币数
            studentReport.TotalScore     = 3;                                            //总星数
            studentReport.SubjectCount   = 3;
            studentReport.KnowledgeRates = 0.34;
            studentReport.ExcellentRates = 25;
            List <StudentAnswerBase> answerBase = new List <StudentAnswerBase>()
            {
                new StuBlankAnswer()
                {
                    KnowledgeId = 10022, ResultStars = 2
                },
                new StuBlankAnswer()
                {
                    KnowledgeId = 10024, ResultStars = 3
                },
                new StuBlankAnswer()
                {
                    KnowledgeId = 10026, ResultStars = 0
                }
            };
            var knowledgeShow = answerBase.GroupBy(s => s.KnowledgeId);

            studentReport.Knowledge = GetKnowledge(knowledgeShow);
            return(studentReport);
        }
        /// <summary>
        /// 获取学生任务报告的统计部分
        /// </summary>
        /// <param name="studentId"></param>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public DtoStudentReport GetByStudentTask(int studentId, int taskId)
        {
            StudentPracticeBll studentPracticeBll = new StudentPracticeBll();
            var result = studentPracticeBll.StudentTaskRepository.IsHasTaskReport(studentId, taskId);

            if (!result)
            {
                throw new AbhsException(ErrorCodeEnum.NotStudyReport, AbhsErrorMsg.ConstNotStudyReport);
            }
            //获取学生答案
            Yw_StudentStudyTaskAnswerExt answer     = studentPracticeBll.StuStudyTaskAnsRepo.GetByStudentTask(studentId, taskId) as Yw_StudentStudyTaskAnswerExt;
            StudentAnswerCard            answerCard = answer.Yta_Answer_Obj;

            DtoStudentReport studentReport = new DtoStudentReport();

            if (answerCard != null)
            {
                studentReport.StudyDate    = answerCard.SubmitTime;
                studentReport.TotalScore   = Convert.ToInt32(Math.Round(answerCard.TotalStars * 1.0 / (answerCard.AnswerCollection.Count() * 5) * 5, MidpointRounding.AwayFromZero));
                studentReport.TotalStars   = answerCard.TotalStars;
                studentReport.StudyTime    = Convert.ToInt32(Math.Ceiling(answerCard.UseTime * 1.0 / 60));
                studentReport.ResultCoins  = answerCard.AnswerCollection.Select(s => s.ResultCoins).Sum();
                studentReport.TotalCoins   = answerCard.TotalCoins;
                studentReport.SubjectCount = answerCard.AnswerCollection.Count();

                double rates = Math.Round((double)(answerCard.AnswerCollection.Where(x => x.ResultStars == 5).Count()) / answerCard.AnswerCollection.Count(), 2) * 100;
                studentReport.ExcellentRates = rates;

                List <Yw_Knowledge> knowledges = new List <Yw_Knowledge>();
                var knowledgeShow = answerCard.AnswerCollection.Where(x => x.KnowledgeId != 0).GroupBy(s => s.KnowledgeId);

                studentReport.Knowledge = GetKnowledge(knowledgeShow);
            }
            return(studentReport);
        }
        public ActionResult ShowStudyReport(int lessonProcessId, string path, int source = 0)
        {
            StudentReportBll studentReportBll = new StudentReportBll();
            DtoStudentReport studyReport      = studentReportBll.GetByStuLesAnswer(GetCurrentUser().StudentId, lessonProcessId);
            StudentBll       studentBll       = new StudentBll();
            var stuName = studentBll.GetStudent(GetCurrentUser().StudentId).Bst_Name;

            studyReport.StudyAdvice = string.Format(StudentStudyReport(studyReport.Evaluate), stuName, studyReport.ImporveCount, studyReport.ImporveKnow, studyReport.GoodKnow);
            SumReportViewModel viewModels = studyReport.ConvertTo <SumReportViewModel>();

            var courseInfo = studentReportBll.GetStuCourseReportById(lessonProcessId);

            viewModels.StudentName   = GetCurrentUser().Name;
            viewModels.ReportType    = courseInfo.ReportType;
            viewModels.ReportTypeStr = courseInfo.ReportTypeStr;
            viewModels.CourseName    = courseInfo.Ycs_Name;
            viewModels.LessonName    = courseInfo.Ycl_Name;
            viewModels.PraticeCount  = courseInfo.PraticeCount;
            viewModels.Source        = source;
            viewModels.Path          = path;
            return(View(viewModels));
        }
        private DtoStudentReport GetMarkCut(int studyTime)
        {
            DtoStudentReport studentReport = new DtoStudentReport();

            studentReport.StudyTime      = studyTime;                                    //学习时长 19
            studentReport.StudyDate      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //学习时间
            studentReport.TotalCoins     = 0;                                            //总金币数
            studentReport.TotalScore     = 2;                                            //总星数
            studentReport.SubjectCount   = 1;
            studentReport.ExcellentRates = 0.4;
            List <StudentAnswerBase> answerBase = new List <StudentAnswerBase>()
            {
                //new StuMarkCutAnswer() {KnowledgeId=10013,ResultStars=0},//闪读训练
                //new StuMarkCutAnswer() {KnowledgeId=10016,ResultStars=0},//古诗词划分节奏
                new StuMarkCutAnswer()
                {
                    KnowledgeId = 10019, ResultStars = 2
                }                                                        //文言文划分朗读节奏
            };
            var knowledgeShow = answerBase.GroupBy(s => s.KnowledgeId);

            studentReport.Knowledge = GetKnowledge(knowledgeShow);
            return(studentReport);
        }
        /// <summary>
        /// 获取学习报告的统计部分
        /// </summary>
        /// <param name="studentId"></param>
        /// <param name="taskId"></param>
        /// <returns></returns>
        public DtoStudentReport GetByStuLesAnswer(int studentId, int lessonProgressId)
        {
            StudentStudyBll studentStudyBll = new StudentStudyBll();
            //var result = studentStudyBll.StuLesProgressRepository.IsHasStudy(lessonProgressId, studentId);
            //if (!result)
            //{
            //    throw new AbhsException(ErrorCodeEnum.NotStudyReport, AbhsErrorMsg.ConstNotStudyReport + " LessonProgressId:" + lessonProgressId);
            //}

            //演示异常使用,正式上线删除
            var lesProgress = studentStudyBll.StuLesProgressRepository.IsHasStudys(lessonProgressId, studentId);

            if (lesProgress == null)
            {
                throw new AbhsException(ErrorCodeEnum.NotStudyReport, AbhsErrorMsg.ConstNotStudyReport + " LessonProgressId:" + lessonProgressId);
            }
            if (!lesProgress.Yle_IsFinished)
            {
                var errorlog = $"操作者:{studentId},操作时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},课程进度Id:{lessonProgressId},原因:课程状态未完成,开始学习时间:{lesProgress.Yle_StartStudyTime.ToString("yyyy-MM-dd HH:mm:ss")},结束学习时间:{lesProgress.Yle_FinishStudyTime.ToString("yyyy-MM-dd HH:mm:ss")},学习时长:{lesProgress.Yle_StudySeconds},已答题目数:{lesProgress.Yle_SubjectCount},数据创建时间:{lesProgress.Yle_CreateTime.ToString("yyyy-MM-dd HH:mm:ss")},数据修改时间:{lesProgress.Yle_UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")}";
                LogHelper.WriteLog(errorlog);

                //查询学习时长
                Yw_StudentLessonProgress lessonProgress = studentStudyBll.StuLesProgressRepository.GetProgressByID(lessonProgressId);
                var studyTime = Convert.ToInt32(Math.Ceiling(lessonProgress.Yle_StudySeconds * 1.0 / 60));
                //病句  选择题
                if (lesProgress.Yle_LessonId == 10000)
                {
                    return(GetSelect(studyTime));
                }
                //断句
                else if (lesProgress.Yle_LessonId == 10001)
                {
                    return(GetMarkCut(studyTime));
                }
                //阅读理解 填空
                else if (lesProgress.Yle_LessonId == 10002)
                {
                    return(GetFillBlank(studyTime));
                }
            }
            //演示结束

            //获取学生答案
            Yw_StudentLessonAnswerExt lessonAnswer  = studentStudyBll.StuLessonAnsRepository.GetStuLesAnswer(studentId, lessonProgressId) as Yw_StudentLessonAnswerExt;
            List <StudentAnswerCard>  answerCard    = lessonAnswer.Yla_Answer_Obj;
            DtoStudentReport          studentReport = new DtoStudentReport();

            if (answerCard != null)
            {
                //查询学习时长
                Yw_StudentLessonProgress lessonProgress = studentStudyBll.StuLesProgressRepository.GetProgressByID(lessonProgressId);
                studentReport.StudyTime = Convert.ToInt32(Math.Ceiling(lessonProgress.Yle_StudySeconds * 1.0 / 60));

                studentReport.StudyDate      = answerCard.OrderBy(s => s.SubmitTime).FirstOrDefault().SubmitTime;
                studentReport.TotalStars     = answerCard.Sum(s => s.TotalStars);
                studentReport.ResultCoins    = answerCard.Sum(s => s.AnswerCollection.Sum(x => x.ResultCoins));
                studentReport.TotalCoins     = answerCard.Sum(s => s.TotalCoins);
                studentReport.TotalScore     = Convert.ToInt32(Math.Round((answerCard.Sum(s => s.TotalStars) * 1.0 / (answerCard.Sum(s => s.AnswerCollection.Count) * 5.0) * 5), MidpointRounding.AwayFromZero));
                studentReport.SubjectCount   = answerCard.Sum(s => s.AnswerCollection.Count());
                studentReport.KnowledgeRates = answerCard.Sum(s => s.TotalStars) * 1.0 / (answerCard.Sum(s => s.AnswerCollection.Count) * 5.0);

                double rates = Math.Round((double)(answerCard.Sum(s => s.AnswerCollection.Where(x => x.ResultStars == 5).Count())) / answerCard.Sum(s => s.AnswerCollection.Count()), 2) * 100;
                studentReport.ExcellentRates = rates;
                var answers = answerCard.Select(s => s.AnswerCollection).ToList();
                List <StudentAnswerBase> answerBase = new List <StudentAnswerBase>();
                foreach (var item in answers)
                {
                    answerBase.AddRange(item.Where(x => x.KnowledgeId != 0).ToList());
                }
                var knowledgeShow = answerBase.GroupBy(s => s.KnowledgeId);
                studentReport.Knowledge = GetKnowledge(knowledgeShow);
            }
            return(studentReport);
        }