This commit is contained in:
tanglong 2025-07-18 10:23:00 +08:00
parent 673b04ab16
commit 02cf22cae4
29 changed files with 25 additions and 11 deletions

View File

@ -15,19 +15,21 @@ namespace YD_AllHeartRates.Api.Services.Impl
public static ChartDataDto BuildHeartRateTrend(List<HeartRateData> data) public static ChartDataDto BuildHeartRateTrend(List<HeartRateData> data)
{ {
var hourlyAvg = data var hourlyAvg = data
.Where(x => x.ScoreTime.Hour >= 8 && x.ScoreTime.Hour <= 16)
.GroupBy(x => x.ScoreTime.Hour) .GroupBy(x => x.ScoreTime.Hour)
.OrderBy(g => g.Key)
.ToDictionary(g => g.Key, g => (int)Math.Round(g.Average(x => x.Value))); .ToDictionary(g => g.Key, g => (int)Math.Round(g.Average(x => x.Value)));
var chart = new ChartDataDto(); var chart = new ChartDataDto();
for (int hour = 8; hour <= 16; hour++) foreach (var hour in hourlyAvg.Keys)
{ {
chart.AxisX.Add($"{hour:00}:00"); chart.AxisX.Add($"{hour:00}:00");
chart.AxisY.Add(hourlyAvg.TryGetValue(hour, out int val) ? val : 0); chart.AxisY.Add(hourlyAvg[hour]);
} }
return chart; return chart;
} }
public static int CalculateReachRate(int reachCount, int total) public static int CalculateReachRate(int reachCount, int total)
=> total == 0 ? 0 : (int)((double)reachCount / total * 100); => total == 0 ? 0 : (int)((double)reachCount / total * 100);

View File

@ -23,7 +23,7 @@ namespace YD_AllHeartRates.Api.Services.Impl
public UserContext _userContext; public UserContext _userContext;
private readonly ICaching _caching; private readonly ICaching _caching;
private readonly LoginContext _loginContext; private readonly LoginContext _loginContext;
private string cacheKey; //private string cacheKey;
private string schoolCode; private string schoolCode;
/// <summary> /// <summary>
@ -37,7 +37,7 @@ namespace YD_AllHeartRates.Api.Services.Impl
_loginContext = loginContext; _loginContext = loginContext;
schoolCode = _loginContext.SchoolCode; schoolCode = _loginContext.SchoolCode;
cacheKey = $"HeartRateData_{schoolCode}"; //cacheKey = $"HeartRateData_{schoolCode}";
} }
/// <summary> /// <summary>
@ -68,7 +68,7 @@ namespace YD_AllHeartRates.Api.Services.Impl
res.FemaleCount = studentList.Count(x => x.Sex == 2); res.FemaleCount = studentList.Count(x => x.Sex == 2);
// 先尝试从缓存读取 // 先尝试从缓存读取
var cacheKey = $"HeartRateData_{schoolCode}"; var cacheKey = $"HeartRateData_{schoolCode}_{scoreTime}";
var data = _caching.Get<List<HeartRateData>>(cacheKey); var data = _caching.Get<List<HeartRateData>>(cacheKey);
if (data == null || data.Count == 0) if (data == null || data.Count == 0)
@ -153,6 +153,8 @@ namespace YD_AllHeartRates.Api.Services.Impl
res.FemaleCount = studentList.Count(x => x.Sex == 2); res.FemaleCount = studentList.Count(x => x.Sex == 2);
// 先尝试从缓存读取 // 先尝试从缓存读取
var cacheKey = $"HeartRateData_{schoolCode}_{scoreTime}";
var allData = _caching.Get<List<HeartRateData>>(cacheKey); var allData = _caching.Get<List<HeartRateData>>(cacheKey);
if (allData == null || allData.Count == 0) if (allData == null || allData.Count == 0)
@ -234,6 +236,7 @@ namespace YD_AllHeartRates.Api.Services.Impl
// 先尝试从缓存读取 // 先尝试从缓存读取
var cacheKey = $"HeartRateData_{schoolCode}_{scoreTime}";
var allData = _caching.Get<List<HeartRateData>>(cacheKey); var allData = _caching.Get<List<HeartRateData>>(cacheKey);
if (allData == null || allData.Count == 0) if (allData == null || allData.Count == 0)
@ -289,6 +292,7 @@ namespace YD_AllHeartRates.Api.Services.Impl
var (dayStart, dayEnd, _) = HeartRateReportHelper.GetTimeRange(scoreTime); var (dayStart, dayEnd, _) = HeartRateReportHelper.GetTimeRange(scoreTime);
// 先尝试从缓存读取 // 先尝试从缓存读取
var cacheKey = $"HeartRateData_{schoolCode}_{scoreTime}";
var allData = _caching.Get<List<HeartRateData>>(cacheKey); var allData = _caching.Get<List<HeartRateData>>(cacheKey);
if (allData == null || allData.Count == 0) if (allData == null || allData.Count == 0)

View File

@ -1159,6 +1159,14 @@
"strength": { "strength": {
"type": "integer", "type": "integer",
"format": "int32" "format": "int32"
},
"heartRateQuantityOfElectricity": {
"type": "integer",
"format": "int32"
},
"jumpingRopeQuantityOfElectricity": {
"type": "integer",
"format": "int32"
} }
}, },
"additionalProperties": false "additionalProperties": false

View File

@ -1 +1 @@
gHVWCKohB6C4bdR0I1MF4cuarmHEhD0pEyb1opvSeEg=WWmIfOUbyYPYdKFHlVpzo+vbEnfIsJNTTcG8+oWdtSc= gdHYaiK/7EbeTXziWUiXX37QXolLjJlP0w2KiZs9Dnk=WWmIfOUbyYPYdKFHlVpzo+vbEnfIsJNTTcG8+oWdtSc=

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Api")] [assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d3cc0e7db0e9ebfb2cc92503a057c7a76b5f4c57")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+673b04ab16b93125ceea569c378087da009d4f49")]
[assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Api")] [assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Api")]
[assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Api")] [assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
cbe9d0728937a26250ea063ac4bd395e2c94912c2374133835da7625ce0f0db7 1a53c74af4873b2605bdc9a7da74758e13d6728849211d648bbc7461516f7e84

View File

@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Commons")] [assembly: System.Reflection.AssemblyCompanyAttribute("YD_AllHeartRates.Commons")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d3cc0e7db0e9ebfb2cc92503a057c7a76b5f4c57")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+673b04ab16b93125ceea569c378087da009d4f49")]
[assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Commons")] [assembly: System.Reflection.AssemblyProductAttribute("YD_AllHeartRates.Commons")]
[assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Commons")] [assembly: System.Reflection.AssemblyTitleAttribute("YD_AllHeartRates.Commons")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
7cc92e468d5c1c78e4f42a9aa4debc7003fa321116bbf36b48ad59c7c6fac543 58915e3b074ddda03447dd77b61a092e6eb4ae183cfbdb375100cb3d94e59569