diff --git a/Tiobon.Core.Model/ViewModels/Extend/QuestionErrorRanking.cs b/Tiobon.Core.Model/ViewModels/Extend/QuestionErrorRanking.cs new file mode 100644 index 00000000..c567e5b2 --- /dev/null +++ b/Tiobon.Core.Model/ViewModels/Extend/QuestionErrorRanking.cs @@ -0,0 +1,14 @@ +namespace Tiobon.Core.Model.ViewModels.Extend; + +public class QuestionErrorRanking +{ + public long Id { get; set; } + public string QuestionContent { get; set; } + public string QuestionNo { get; set; } + public decimal ErrorCount { get; set; } + + public decimal TotalCount { get; set; } + public string Percent1 { get; set; } + public decimal Percent { get; set; } + +} diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index ebe123e4..997e86a9 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -1406,7 +1406,7 @@ public class Ghre_CourseServices : BaseServices(sql1); + var data = DbAccess.QueryList(sql1); totalCount = await Db.Ado.GetIntAsync("SELECT COUNT(0) from Ghre_CourseScene_V A WHERE 1=1"); @@ -1558,7 +1558,6 @@ public class Ghre_CourseServices : BaseServices() + .Where(x => x.CourseId == id || x.CourseIds.Contains(id.ToString())) + .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() + .Where(x => x.QuestionId != null && questionIds.Contains(x.QuestionId.Value)) + .ToListAsync(); + + for (int i = 0; i < questionErrorRankings.Count; i++) + { + 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;