diff --git a/WeChatApplet/Services/Impl/PatriarchService.cs b/WeChatApplet/Services/Impl/PatriarchService.cs index 926db11..a72dee9 100644 --- a/WeChatApplet/Services/Impl/PatriarchService.cs +++ b/WeChatApplet/Services/Impl/PatriarchService.cs @@ -286,18 +286,33 @@ namespace YD_WeChatApplet.Api.Services.Impl var prevResult = studentResults.Skip(1).FirstOrDefault(); var maxScore = studentResults.Any() - ? studentResults.Max(x => x.Score) + ? studentResults.Max(x => x.Value) : 0; - var classAvgScore = studentResults.Any() - ? studentResults.Average(x => x.Score) - : 0; + //var classAvgScore = studentResults.Any() + // ? studentResults.Average(x => x.Value) + // : 0; - var schoolAvgScore = sportsTestResults - .Where(x => x.CategoryValue == item.Id) - .Select(x => x.Score) - .DefaultIfEmpty(0) - .Average(); + // 1. 获取每个学生最新的 ScoreTime + var latestRecords = sportsTestResults + .Where(x => x.CategoryValue == item.Id) // 先按指标过滤,提升效率 + .GroupBy(x => x.StudentNo) + .Select(g => new + { + StudentNo = g.Key, + MaxScoreTime = g.Max(x => x.ScoreTime) + }); + + // 2. 关联原表,取得最新测试的那条记录(该指标的值) + var latestValues = from record in sportsTestResults + join latest in latestRecords + on new { record.StudentNo, record.ScoreTime } + equals new { latest.StudentNo, ScoreTime = latest.MaxScoreTime } + where record.CategoryValue == item.Id + select record.Value; + + // 3. 计算平均值(如果没有数据则返回0) + var schoolAvgScore = latestValues.DefaultIfEmpty(0).Average(); // 🚀 趋势图(关键:反转集合) var trendList = studentResults @@ -316,12 +331,13 @@ namespace YD_WeChatApplet.Api.Services.Impl Name = item.CategoryName, Rank = lastResult?.Rank, + GradeId = lastResult.GradeId, PrevScore = prevResult?.Score ?? 0, LastScore = lastResult?.Score ?? 0, MaxScore = (float)maxScore, - ClassAvgScore = (float)classAvgScore, + //ClassAvgScore = (float)classAvgScore, SchoolAvgScore = (float)schoolAvgScore, ScoreTrendChart = trendChart, diff --git a/WeChatApplet/Services/Impl/TeacherService.cs b/WeChatApplet/Services/Impl/TeacherService.cs index 8133f07..baf66d4 100644 --- a/WeChatApplet/Services/Impl/TeacherService.cs +++ b/WeChatApplet/Services/Impl/TeacherService.cs @@ -426,10 +426,17 @@ namespace YD_WeChatApplet.Services res.MinHR = (int)heartRateDataList.Min(x => x.Value); res.AvgHR = (int)heartRateDataList.Average(x => x.Value); - res.HighIntensity = heartRateDataList.Where(x => x.Strength > 50).Sum(x => x.MotionDuration); + var highIntensityCount = heartRateDataList.Count(x => x.Strength > 50); - double totalDuration = heartRateDataList.Sum(x => x.MotionDuration); - res.HighIntensityDurationRatio = totalDuration > 0 ? res.HighIntensity / totalDuration : 0; + res.HighIntensity = (int)Math.Round((double)highIntensityCount / classRoomStudent.Count(), MidpointRounding.AwayFromZero); + + // 计算时间跨度(分钟) + //var minScoreTime = heartRateDataList.Min(x => x.ScoreTime); + //var maxScoreTime = heartRateDataList.Max(x => x.ScoreTime); + //double totalMinutes = (maxScoreTime - minScoreTime).TotalMinutes; + + double totalMinutes = heartRateDataList.Count(); + res.HighIntensityDurationRatio = totalMinutes > 0 ? Math.Round(highIntensityCount / totalMinutes * 100, MidpointRounding.AwayFromZero) : 0; var studentTrainingRecordList = classRoom.ClassroomStudentRecord.ToList(); List studentList = new List(); @@ -517,9 +524,17 @@ namespace YD_WeChatApplet.Services res.MinHR = (int)heartRateDataList.Min(x => x.Value); res.AvgHR = (int)heartRateDataList.Average(x => x.Value); - res.HighIntensity = heartRateDataList.Where(x => x.Strength > 50).Sum(x => x.MotionDuration); - double totalDuration = heartRateDataList.Sum(x => x.MotionDuration); - res.HighIntensityDurationRatio = totalDuration > 0 ? res.HighIntensity / totalDuration : 0; + //res.HighIntensity = heartRateDataList.Where(x => x.Strength > 50).Sum(x => x.MotionDuration); + + res.HighIntensity = heartRateDataList.Count(x => x.Strength > 50); + + // 计算时间跨度(分钟) + //var minScoreTime = heartRateDataList.Min(x => x.ScoreTime); + //var maxScoreTime = heartRateDataList.Max(x => x.ScoreTime); + //double totalMinutes = (maxScoreTime - minScoreTime).TotalMinutes; + + double totalMinutes = heartRateDataList.Count(); + res.HighIntensityDurationRatio = totalMinutes > 0 ? Math.Round((double)res.HighIntensity / totalMinutes * 100, MidpointRounding.AwayFromZero) : 0; // 计算时间轴(每分钟平均心率) DateTime baseTime; diff --git a/WeChatApplet/Services/Interface/ITeacherService.cs b/WeChatApplet/Services/Interface/ITeacherService.cs index e58b9bc..a039561 100644 --- a/WeChatApplet/Services/Interface/ITeacherService.cs +++ b/WeChatApplet/Services/Interface/ITeacherService.cs @@ -73,7 +73,6 @@ namespace YD_WeChatApplet.Services /// Task StudentClassRoomReport(StudentClassRoomReportRequestDto dto); - /// /// 班级体测报告 /// diff --git a/YD_WeChatApplet.Commons/Dto/ClassRoomRecord/StudentClassRoomReportRequestDto.cs b/YD_WeChatApplet.Commons/Dto/ClassRoomRecord/StudentClassRoomReportRequestDto.cs index 0e7d137..30eb4de 100644 --- a/YD_WeChatApplet.Commons/Dto/ClassRoomRecord/StudentClassRoomReportRequestDto.cs +++ b/YD_WeChatApplet.Commons/Dto/ClassRoomRecord/StudentClassRoomReportRequestDto.cs @@ -15,6 +15,7 @@ namespace YD_WeChatApplet.Commons.Dto.ClassRoomRecord /// 查询类型[1:课堂/2:时间] /// public int Type { get; set; } + /// /// 课堂Id /// diff --git a/YD_WeChatApplet.Commons/Dto/Patriarch/StudentReportDto.cs b/YD_WeChatApplet.Commons/Dto/Patriarch/StudentReportDto.cs index 3cb196b..ddbc198 100644 --- a/YD_WeChatApplet.Commons/Dto/Patriarch/StudentReportDto.cs +++ b/YD_WeChatApplet.Commons/Dto/Patriarch/StudentReportDto.cs @@ -67,6 +67,11 @@ namespace YD_WeChatApplet.Commons.Dto.Patriarch /// public string Rank { get; set; } + /// + ///年级Id + /// + public int? GradeId { get; set; } + /// /// 成绩趋势图 ///