|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
using NPOI.SS.UserModel; |
|
|
|
|
using MathNet.Numerics.Distributions; |
|
|
|
|
using NPOI.SS.UserModel; |
|
|
|
|
using System.Net; |
|
|
|
|
using static Tiobon.Core.Model.Consts; |
|
|
|
|
|
|
|
|
@ -1475,6 +1476,8 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<dynamic> QueryStatistic(long id) |
|
|
|
|
{ |
|
|
|
|
if (!await AnyAsync(x => x.Id == id)) |
|
|
|
|
return await QuerySceneStatistic(id); |
|
|
|
|
|
|
|
|
|
dynamic obj = new ExpandoObject(); |
|
|
|
|
dynamic data = new ExpandoObject(); |
|
|
|
@ -1691,4 +1694,238 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
return obj; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 课程场景统计 |
|
|
|
|
/// <summary> |
|
|
|
|
/// 课程场景统计 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="id"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<dynamic> QuerySceneStatistic(long id) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
dynamic obj = new ExpandoObject(); |
|
|
|
|
dynamic data = new ExpandoObject(); |
|
|
|
|
var entity = await Db.Queryable<Ghre_CourseScene>().Where(x => x.Id == id).FirstAsync(); |
|
|
|
|
|
|
|
|
|
var Courses = await Db.Queryable<Ghre_Course>() |
|
|
|
|
.Where(x => x.CourseSceneId == id || x.CourseSceneIds.Contains(id.ToString())) |
|
|
|
|
.Select(x => new { x.Id, x.CourseNo, x.CourseName }) |
|
|
|
|
.ToListAsync(); |
|
|
|
|
var courseIds = Courses.Select(x => x.Id).ToList(); |
|
|
|
|
data.Courses = Courses; |
|
|
|
|
data.StandardHour = entity.StandardHour; |
|
|
|
|
data.CreditPoints = entity.CreditPoints; |
|
|
|
|
|
|
|
|
|
//必修人数 |
|
|
|
|
var RequiredCount = await Db.Queryable<Ghre_StudyRecord>() |
|
|
|
|
.Where(x => x.CourseSceneId == id && (x.CourseType == "ManualRequired" || x.CourseType == "Required")) |
|
|
|
|
.CountAsync(); |
|
|
|
|
data.RequiredCount = RequiredCount; |
|
|
|
|
|
|
|
|
|
//选修人次 |
|
|
|
|
var ElectiveCount = await Db.Queryable<Ghre_StudyRecord>() |
|
|
|
|
.Where(x => x.CourseSceneId == id && (x.CourseType == "ManualElective" || x.CourseType == "Elective")).CountAsync(); |
|
|
|
|
data.ElectiveCount = ElectiveCount; |
|
|
|
|
|
|
|
|
|
var CompleteCount = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseSceneId == id && x.CompleteStatus == DIC_STUDY_RECORD_STUDY_COMPLETE_STATUS.FINISHED && (x.CourseType == "ManualElective" || x.CourseType == "Elective" || x.CourseType == "ManualElective" || x.CourseType == "Elective")).CountAsync(); |
|
|
|
|
//完成人数 |
|
|
|
|
data.CompleteCount = CompleteCount; |
|
|
|
|
//开班人数 |
|
|
|
|
var OpenClassCount = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseSceneId == id && x.OpenClassId != null).CountAsync(); |
|
|
|
|
data.OpenClassCount = OpenClassCount; |
|
|
|
|
|
|
|
|
|
var studyRecordIds = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseSceneId == id).Select(x => x.Id).ToListAsync(); |
|
|
|
|
//总学习时长 |
|
|
|
|
data.TotalStudyDuration = await Db.Queryable<Ghre_StudyRecordDetail>().Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)).SumAsync(x => x.StudyDuration); |
|
|
|
|
|
|
|
|
|
var AvgStudyDuration = await Db.Queryable<Ghre_StudyRecordDetail>().Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)).GroupBy(x => x.StaffId) |
|
|
|
|
.Select(m => new { m.StaffId, StudyDuration = SqlFunc.AggregateSum(m.StudyDuration) }).ToListAsync(); |
|
|
|
|
//平均学习时长 |
|
|
|
|
data.AvgStudyDuration = AvgStudyDuration.Average(x => x.StudyDuration); |
|
|
|
|
//平均分 |
|
|
|
|
var AvgScore = await Db.Queryable<Ghre_ExamRecord>().Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)).AvgAsync(x => x.FinallyScore ?? (x.Score + x.AdjustScore)); |
|
|
|
|
data.AvgScore = AvgScore ?? 0; |
|
|
|
|
|
|
|
|
|
//通过率 |
|
|
|
|
var passPercent = 0; |
|
|
|
|
|
|
|
|
|
if (CompleteCount > 0 && (RequiredCount + ElectiveCount + OpenClassCount) > 0) |
|
|
|
|
passPercent = CompleteCount / (RequiredCount + ElectiveCount + OpenClassCount); |
|
|
|
|
data.PassPercent = passPercent; |
|
|
|
|
|
|
|
|
|
//考试安排次数 |
|
|
|
|
data.ExamScheduleCount = await Db.Queryable<Ghre_Exam>().Where(x => x.CourseSceneId == id).CountAsync(); |
|
|
|
|
|
|
|
|
|
//考试人数 |
|
|
|
|
data.ExamCount = await Db.Queryable<Ghre_ExamRecord>().Where(x => x.CourseSceneId == id).CountAsync(); |
|
|
|
|
|
|
|
|
|
//考试人次 |
|
|
|
|
data.ExamGroupCount = await Db.Queryable<Ghre_ExamRecordGroup>() |
|
|
|
|
.Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)) |
|
|
|
|
.CountAsync(); |
|
|
|
|
|
|
|
|
|
//反馈人数 |
|
|
|
|
data.FeedbackCount = 0; |
|
|
|
|
|
|
|
|
|
#region 课件学习时长 |
|
|
|
|
var courseWareStudyDuration = await Db.Queryable<Ghre_StudyRecordDetail>() |
|
|
|
|
.Where(a => a.StudyRecordId != null && studyRecordIds.Contains(a.StudyRecordId.Value)) |
|
|
|
|
|
|
|
|
|
.GroupBy(a => new { a.CourseWareId, a.CourseWareAttachmentId }) |
|
|
|
|
.Select(a => new |
|
|
|
|
{ |
|
|
|
|
a.CourseWareId, |
|
|
|
|
a.CourseWareAttachmentId, |
|
|
|
|
StudyDuration = SqlFunc.AggregateSum(a.StudyDuration) |
|
|
|
|
}) |
|
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
|
|
var courseWareStudyDurations = new JArray(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < courseWareStudyDuration.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var courseWare = await Db.Queryable<Ghre_CourseWare>().Where(x => x.Id == courseWareStudyDuration[i].CourseWareId).FirstAsync(); |
|
|
|
|
var courseWareAttachment = await Db.Queryable<Ghre_CourseWareAttachment>().Where(x => x.Id == courseWareStudyDuration[i].CourseWareAttachmentId).FirstAsync(); |
|
|
|
|
var item = new JObject |
|
|
|
|
{ |
|
|
|
|
new JProperty("CourseWareId", courseWareStudyDuration[i].CourseWareAttachmentId), |
|
|
|
|
new JProperty("CourseWareAttachmentId", courseWareStudyDuration[i].CourseWareAttachmentId), |
|
|
|
|
new JProperty("StudyDuration", courseWareStudyDuration[i].StudyDuration), |
|
|
|
|
new JProperty("CourseWareName", courseWare?.CourseWareNo+courseWare?.CourseWareName+courseWare?.VersionNo+courseWareAttachment.AttachmentName), |
|
|
|
|
}; |
|
|
|
|
courseWareStudyDurations.Add(item); |
|
|
|
|
} |
|
|
|
|
data.CourseWareStudyDurations = courseWareStudyDurations; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 课件学习人数占比 |
|
|
|
|
var courseWareStudyCount1 = await Db.Queryable<Ghre_StudyRecordDetail>() |
|
|
|
|
.Where(a => a.StudyRecordId != null && studyRecordIds.Contains(a.StudyRecordId.Value)) |
|
|
|
|
.Select(a => new { a.CourseWareAttachmentId, a.StaffId }) |
|
|
|
|
.Distinct().ToListAsync(); |
|
|
|
|
var courseWareStudyCount = courseWareStudyCount1 |
|
|
|
|
.GroupBy(a => a.CourseWareAttachmentId) |
|
|
|
|
.Select(a => new |
|
|
|
|
{ |
|
|
|
|
CourseWareAttachmentId = a.Key, |
|
|
|
|
Count = a.Count() |
|
|
|
|
}) |
|
|
|
|
.ToList(); |
|
|
|
|
|
|
|
|
|
var courseWareStudyCounts = new JArray(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < courseWareStudyCount.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var courseWareAttachment = await Db.Queryable<Ghre_CourseWareAttachment>().Where(x => x.Id == courseWareStudyCount[i].CourseWareAttachmentId).FirstAsync(); |
|
|
|
|
var item = new JObject |
|
|
|
|
{ |
|
|
|
|
new JProperty("CourseWareAttachmentId", courseWareStudyCount[i].CourseWareAttachmentId), |
|
|
|
|
new JProperty("CourseWareName", courseWareAttachment.AttachmentName), |
|
|
|
|
new JProperty("Count", courseWareStudyCount[i].Count), |
|
|
|
|
}; |
|
|
|
|
courseWareStudyCounts.Add(item); |
|
|
|
|
} |
|
|
|
|
data.CourseWareStudyCounts = courseWareStudyCounts; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 关联的考试排行 |
|
|
|
|
var exams = await Db.Queryable<Ghre_Exam>() |
|
|
|
|
.LeftJoin<Ghre_ExamPaper>((a, b) => a.ExamPaperId == b.Id)//多个条件用&& |
|
|
|
|
.Where(a => a.CourseSceneId == id && a.Status != "Draft") |
|
|
|
|
.Select((a, b) => new |
|
|
|
|
{ |
|
|
|
|
a.Id, |
|
|
|
|
a.ExamNo, |
|
|
|
|
a.ExamName, |
|
|
|
|
b.PaperName |
|
|
|
|
}) |
|
|
|
|
.ToListAsync(); |
|
|
|
|
var examRankings = new JArray(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < exams.Count; i++) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var groups = await Db.Queryable<Ghre_ExamRecordGroup>().Where(x => x.ExamId == exams[i].Id).CountAsync(); |
|
|
|
|
var examRecordCount = await Db.Queryable<Ghre_ExamRecord>().Where(x => x.ExamId == exams[i].Id).CountAsync(); |
|
|
|
|
var examRecordPassCount = await Db.Queryable<Ghre_ExamRecord>() |
|
|
|
|
.Where(x => x.ExamId == exams[i].Id && x.IsPass == true && x.IsPass != null) |
|
|
|
|
.CountAsync(); |
|
|
|
|
var examRecordRetakeCount = await Db.Queryable<Ghre_ExamRecord>() |
|
|
|
|
.Where(x => x.ExamId == exams[i].Id && x.RetakeTimes > 0 && x.RetakeTimes != null) |
|
|
|
|
.CountAsync(); |
|
|
|
|
|
|
|
|
|
passPercent = 0; |
|
|
|
|
var retakePercent = 0; |
|
|
|
|
|
|
|
|
|
if (examRecordCount > 0) |
|
|
|
|
{ |
|
|
|
|
if (examRecordPassCount > 0) passPercent = (examRecordPassCount / examRecordCount) * 100; |
|
|
|
|
if (examRecordRetakeCount > 0) retakePercent = (examRecordRetakeCount / examRecordCount) * 100; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var item = new JObject |
|
|
|
|
{ |
|
|
|
|
new JProperty("ExamName", $"{exams[i].ExamName}({exams[i].ExamNo})" ), |
|
|
|
|
new JProperty("PaperName", exams[i].PaperName), |
|
|
|
|
new JProperty("Attempts", groups), |
|
|
|
|
new JProperty("PassPercent", passPercent), |
|
|
|
|
new JProperty("RetakePercent", retakePercent), |
|
|
|
|
//new JProperty("CourseWareName", courseWareAttachment.AttachmentName), |
|
|
|
|
}; |
|
|
|
|
examRankings.Add(item); |
|
|
|
|
} |
|
|
|
|
data.ExamRankings = examRankings; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 错误率排名 |
|
|
|
|
|
|
|
|
|
var exp = Expressionable.Create<Ghre_Question>(); |
|
|
|
|
|
|
|
|
|
courseIds.ForEach(id1 => |
|
|
|
|
{ |
|
|
|
|
exp.Or(x => x.CourseId == id1 || x.CourseIds.Contains(id1.ToString())); |
|
|
|
|
}); |
|
|
|
|
var questionErrorRankings = await Db.Queryable<Ghre_Question>() |
|
|
|
|
.Where(exp.ToExpression()) |
|
|
|
|
.Select(x => new QuestionErrorRanking |
|
|
|
|
{ |
|
|
|
|
Id = x.Id, |
|
|
|
|
QuestionNo = x.QuestionNo, |
|
|
|
|
QuestionContent = x.QuestionContent |
|
|
|
|
}) |
|
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
|
|
var questionIds = questionErrorRankings.Select(x => x.Id).ToList(); |
|
|
|
|
|
|
|
|
|
var recordDetails = await Db.Queryable<Ghre_ExamRecordDetail>() |
|
|
|
|
.Where(x => x.QuestionId != null && questionIds.Contains(x.QuestionId.Value)) |
|
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < questionErrorRankings.Count; i++) |
|
|
|
|
{ |
|
|
|
|
questionErrorRankings[i].QuestionContent = WebUtility.HtmlDecode(questionErrorRankings[i].QuestionContent); |
|
|
|
|
questionErrorRankings[i].TotalCount = recordDetails.Where(x => x.QuestionId == questionErrorRankings[i].Id).Count(); |
|
|
|
|
questionErrorRankings[i].ErrorCount = recordDetails.Where(x => x.QuestionId == questionErrorRankings[i].Id && x.IsCorrect != true).Count(); |
|
|
|
|
|
|
|
|
|
if (questionErrorRankings[i].ErrorCount > 0 && questionErrorRankings[i].TotalCount > 0) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
decimal? Percent1 = questionErrorRankings[i].ErrorCount / questionErrorRankings[i].TotalCount; |
|
|
|
|
questionErrorRankings[i].Percent1 = Percent1.TrimDecimalString(2); |
|
|
|
|
questionErrorRankings[i].Percent = Convert.ToDecimal((Percent1 * 100).TrimDecimalString(0)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
questionErrorRankings = questionErrorRankings.OrderByDescending(x => x.Percent).ToList(); |
|
|
|
|
data.QuestionErrorRankings = questionErrorRankings; |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
obj.Data = data; |
|
|
|
|
obj.Success = true; |
|
|
|
|
obj.Status = 200; |
|
|
|
|
obj.Message = "查询成功!"; |
|
|
|
|
return obj; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |