Browse Source

校准数据不足,清零后,下发,手动标定值,增量值=0

datasub12_previous
H Vs 11 months ago
parent
commit
167cece5dd
4 changed files with 39 additions and 13 deletions
  1. +6
    -6
      HealthMonitor.Model/Service/Mapper/ParseTDengineRestResponse.cs
  2. +7
    -6
      HealthMonitor.Service/Biz/IotWebApiService.cs
  3. +1
    -1
      HealthMonitor.Service/Resolver/BloodpressResolver.cs
  4. +25
    -0
      HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs

+ 6
- 6
HealthMonitor.Model/Service/Mapper/ParseTDengineRestResponse.cs View File

@@ -150,12 +150,6 @@ namespace HealthMonitor.Model.Service.Mapper
public decimal AverageAfterRemovingOneMinMaxRef(Func<T, decimal> valueSelector, int refValue)
{
var values = ParseData.Select(valueSelector).ToList();

if (values.Count <= 2)
{
throw new ArgumentException("数据不够不能计算");
}

// Remove the specified number of minimum and maximum values
//values.RemoveAll(_ => _ == values.Min());
//values.RemoveAll(_ => _ == values.Max());
@@ -166,6 +160,12 @@ namespace HealthMonitor.Model.Service.Mapper
// Remove values less than the specified threshold
values.RemoveAll(_ => _ > refValue);

if (values.Count < 2)
{
// throw new ArgumentException("数据不够不能计算");
// 平均值为0,说明数据不足,不能计算增量值
return 0M;
}
// Calculate and return the average of the remaining values
return values.Average();
}


+ 7
- 6
HealthMonitor.Service/Biz/IotWebApiService.cs View File

@@ -273,18 +273,20 @@ namespace HealthMonitor.Service.Biz
/// <param name="diastolicRefValue"></param>
/// <param name="systolicIncValue"></param>
/// <param name="diastolicIncValue"></param>
/// <param name="isInitRemakers">是否初始化,即清空remakers</param>
/// <returns></returns>
public async Task<bool> UpdatePersonRemarksAsync(string imei, int systolicRefValue, int diastolicRefValue, int systolicIncValue, int diastolicIncValue)
public async Task<bool> UpdatePersonRemarksAsync(string imei, int systolicRefValue, int diastolicRefValue, int systolicIncValue, int diastolicIncValue, bool isInitRemakers=false)
{
var flag = false;
try
{
// 保证实时性,先更新缓存,再更新数据库
var personCache = await _personCacheMgr.GetDeviceGpsPersonCacheObjectBySerialNoAsync(new Guid().ToString(), imei).ConfigureAwait(false);
if (personCache == null)
{
_logger.LogInformation($"Person remarks数据异常,检查缓存和数据库");
_logger.LogInformation($"{imei} -- Person remarks数据异常,检查缓存和数据库");
}
else if (string.IsNullOrWhiteSpace(personCache["person"]!["remarks"]!.ToString()))
{
@@ -300,7 +302,7 @@ namespace HealthMonitor.Service.Biz
diastolicIncValue //舒张压显示增量,值为0 表示不生效
}
};
var newRemarkStr = $"is_blood_press:{JsonConvert.SerializeObject(newRemarkData)}|";
var newRemarkStr = isInitRemakers ? string.Empty:$"is_blood_press:{JsonConvert.SerializeObject(newRemarkData)}|";
personCache["person"]!["remarks"] = newRemarkStr;
bool cacheFlag = await _personCacheMgr.UpdateDeviceGpsPersonCacheObjectBySerialNoAsync(personCache, imei);
if (cacheFlag)
@@ -324,20 +326,19 @@ namespace HealthMonitor.Service.Biz
// 更新字段
person!.Remarks = newRemarkStr;
await _gpsPersonApiClient.UpdateAsync(person, new RequestHeader() { RequestId = $"{imei}" }).ConfigureAwait(false);
_logger.LogInformation($"更新Person remarks字段|{person.Remarks}");
_logger.LogInformation($"{imei} 更新Person remarks字段|{person.Remarks}");

}
else
{
_logger.LogInformation($"{imei} 更新缓存和数据库{nameof(UpdatePersonRemarksAsync)}失败,{JsonConvert.SerializeObject(personCache)}");

}
flag = cacheFlag;
}
}
catch (Exception ex)
{
_logger.LogError($"{nameof(UpdatePersonRemarksAsync)} 更新个人信息异常:{ex.Message}, {ex.StackTrace}");
_logger.LogError($"{nameof(UpdatePersonRemarksAsync)} {imei}--更新个人信息异常:{ex.Message}, {ex.StackTrace}");
}
return flag;
}


+ 1
- 1
HealthMonitor.Service/Resolver/BloodpressResolver.cs View File

@@ -158,7 +158,7 @@ namespace HealthMonitor.Service.Resolver
systolicRefValue = bpRef!.Systolic;//?
diastolicRefValue = bpRef!.Diastolic;//?
#endregion
_logger.LogInformation($"Person Remarks 值:{person?.Person.Remarks}");
_logger.LogInformation($"{bp.Serialno} -- Person Remarks 值:{person?.Person.Remarks}");
if (string.IsNullOrWhiteSpace(person?.Person.Remarks))
{
_logger.LogInformation($"{bp.Serialno},设备解绑后绑定,首次手工测量了血压值,下发年龄标定值和增量值(测量值=平均值计算得出的)");


+ 25
- 0
HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs View File

@@ -190,6 +190,31 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor
systolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.SystolicValue, SafeType.SafeInt(systolicRefValue!)))!;
diastolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.DiastolicValue, SafeType.SafeInt(diastolicRefValue!)))!;

// 平均值为0,说明数据不足,不能计算增量值
// 数据不足等同进行初始化,只下发标定值,增量值为0;remarks恢复到未校准状态,需要基于第一个测量值生成增量值。
if (systolicAvg.Equals(0)|| diastolicAvg.Equals(0))
{
_logger.LogInformation($"测量数据样本不足,将进行标定值初始,只下发标定值,增量值为0;remarks恢复到未校准状态。");
// 重置设备
var statNow=DateTime.Now;
await IotSetBloodPressCalibrationConfigResponseAsync(imei, 0, 0, 0, 0, 0, 0, 0, 0, statNow, statNow).ConfigureAwait(false);
_logger.LogInformation($"1.测量数据样本不足,重置设备");

var initRemarksFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(imei, 0, 0, 0, 0, true).ConfigureAwait(false);
if (initRemarksFlag)
{
_logger.LogInformation($"2.测量数据样本不足,remarks恢复到未校准状态(remarks设置为空),成功");
}
else
{
_logger.LogInformation($"2.测量数据样本不足,remarks恢复到未校准状态(remarks设置为空),失败");
}
_logger.LogInformation($"3.测量数据样本不足,只下发手动标定值systolicRefValue:{systolicRefValue} -- diastolicRefValue:{diastolicRefValue},增量值为0");
statNow = DateTime.Now.AddSeconds(3);
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, 0, 0, 0, 0, 0, 0, statNow, statNow).ConfigureAwait(false);
}

// 增量值=(标定值-平均值)* 0.25
var currentSystolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!;
var currentDiastolicInc = (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;


Loading…
Cancel
Save