yundongguan
This commit is contained in:
parent
d3e9523a58
commit
c28da1d332
@ -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,
|
||||
|
||||
@ -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<StudentTrainingRecordDto> studentList = new List<StudentTrainingRecordDto>();
|
||||
@ -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;
|
||||
|
||||
@ -73,7 +73,6 @@ namespace YD_WeChatApplet.Services
|
||||
/// <returns></returns>
|
||||
Task<StudentClassRoomReportDto> StudentClassRoomReport(StudentClassRoomReportRequestDto dto);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 班级体测报告
|
||||
/// </summary>
|
||||
|
||||
@ -15,6 +15,7 @@ namespace YD_WeChatApplet.Commons.Dto.ClassRoomRecord
|
||||
/// 查询类型[1:课堂/2:时间]
|
||||
/// </summary>
|
||||
public int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 课堂Id
|
||||
/// </summary>
|
||||
|
||||
@ -67,6 +67,11 @@ namespace YD_WeChatApplet.Commons.Dto.Patriarch
|
||||
/// </summary>
|
||||
public string Rank { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///年级Id
|
||||
/// </summary>
|
||||
public int? GradeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成绩趋势图
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user