Ver código fonte

血压数据只统计is_display=true

datasub12_previous
H Vs 11 meses atrás
pai
commit
ed09e845b9
2 arquivos alterados com 6 adições e 481 exclusões
  1. +3
    -480
      HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs
  2. +3
    -1
      HealthMonitor.WebApi/Worker.cs

+ 3
- 480
HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs Ver arquivo

@@ -183,7 +183,9 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor
lastPushDiastolicInc = lastPush!.DiastolicIncValue;
startTime = lastPush!.Timestamp;

var condition = $"ts between '{startTime:yyyy-MM-dd HH:mm:ss.fff}' and '{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}'";
var condition = $"ts between '{startTime:yyyy-MM-dd HH:mm:ss.fff}' and '{endTime:yyyy-MM-dd HH:mm:ss.fff}'" +
$" and serialno='{imei}'" +
$" and is_display = true";
var hmBpResponse = await _serviceTDengine.ExecuteSelectRestResponseAsync("stb_hm_bloodpress", condition);
var hmBpParser = JsonConvert.DeserializeObject<ParseTDengineRestResponse<BloodPressureModel>>(hmBpResponse!);

@@ -228,201 +230,6 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor
_logger.LogInformation($"{imei},手工校准,发给设备的绝对增量值=(上次绝对增量值+新数据的增量值)");
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);


/** 取消
//// A.没有下推记录
//if (lastPush?.Count == 0 || lastPush == null)
//{
// //#region 初始化remarks
// //// 读数据库,remarks为空就写commandValue,更新缓存
// //var resFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(imei, systolicRefValue, diastolicRefValue).ConfigureAwait(false);
// //if (resFlag)
// //{
// // _logger.LogInformation($"更新gps_person remarks和缓存");
// //}
// //else
// //{
// // _logger.LogInformation($"更新gps_person remarks和缓存失败");
// //}
// //#endregion

// int count = await _serviceTDengine.GetCount("stb_hm_bloodpress", $"serialno='{imei}' ");
// // A.1 没有下推记录,没有测量记录,下推增量值 0
// if (count.Equals(0))
// {
// _logger.LogInformation("A.1 没有下推记录,没有测量记录,下推增量值 0");
// // return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false);
// systolicInc = 0;
// diastolicInc = 0;
// systolicAvg = 0;
// diastolicAvg = 0;
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);

// }
// // A.2 没有下推记录,测量记录,正常计算增量值
// else
// {
// // 平均值: 计算去除最大值 MAX和最小值 MIN 和异常值 ABN 的平均值
// systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and systolic_value < {systolicRefValue} ");
// diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and diastolic_value < {diastolicRefValue}");

// // 数据异常,不修改增量值
// if (systolicAvg.Equals(0) || diastolicAvg.Equals(0))
// {
// _logger.LogInformation(" A.2 没有下推记录,有测量记录,正常计算增量值 ,平均值为0, 增量值将按0下发");
// systolicInc = 0;
// diastolicInc = 0;
// //return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false);
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);

// }
// // 数据正常
// else
// {
// //// 偏移参数
// //var avgOffset = 0.25M;
// //var systolicAvgOffset = avgOffset;
// //var diastolicAvgOffset = avgOffset;


// // 增量值=(标定值-平均值)* 0.25
// systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!;
// diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;
// _logger.LogInformation(" A.2 没有下推记录,有测量记录,正常计算增量值 ,增量值将正常下发");
// // return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false);
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);

// }
// }
//}
//// B.有下推记录(更改过个人信息)
//else
//{
// // B.1. 设备已经被重新设置
// if (
// (int)lastPush![2] == 0
// && (int)lastPush![3] == 0
// && (int)lastPush![4] == 0
// && (int)lastPush![5] == 0
// )
// {

// // 转换时间
// _ = DateTime.TryParse(lastPush?[0]!.ToString(), out DateTime newTs);
// endTime = DateTime.Now;//newTs;
// startTime = newTs;//DateTime.Now;

// int count = await _serviceTDengine.GetCount("stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' ");
// // B.1.1 设备已经被重新设置, 从重置的ts 到 now 没有测量数据,inc=0
// if (count.Equals(0))
// {
// _logger.LogWarning("B.1.1 设备已经被重新设置, 从重置的ts 到 now 没有测量数据,inc=0");
// systolicInc = 0;
// diastolicInc = 0;
// systolicAvg = 0;
// diastolicAvg = 0;
// // return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false);
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);

// }
// // B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据
// else
// {
// // 平均值: 计算去除最大值 MAX和最小值 MIN 和异常值 ABN 的平均值
// systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and systolic_value < {systolicRefValue} ");
// diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and diastolic_value < {diastolicRefValue}");

// // 数据异常,不修改增量值
// if (systolicAvg.Equals(0) || diastolicAvg.Equals(0))
// {
// _logger.LogWarning("B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据,平均值为0,增量值将按0下发");
// systolicInc = 0;
// diastolicInc = 0;
// //return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false);
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);
// }
// // 数据正常
// else
// {
// //// 偏移参数
// //var avgOffset = 0.25M;
// //var systolicAvgOffset = avgOffset;
// //var diastolicAvgOffset = avgOffset;
// // 增量值=(标定值-平均值)* 0.25
// systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)! + SafeType.SafeInt(lastPush![4]); ;
// diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)! + SafeType.SafeInt(lastPush![5]); ;
// _logger.LogInformation("B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据 ,增量值将正常下发");
// //return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false);
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);
// }

// }

// }
// // B.2. 曾经下推过断言有测量记录
// else
// {
// // 转换时间
// _ = DateTime.TryParse(lastPush?[0]!.ToString(), out DateTime newTs);
// endTime = DateTime.Now;
// startTime = newTs;

// // 最大值,最小值
// var systolicAggregate = await _serviceTDengine.GetAggregateValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}'");
// var diastolicAggregate = await _serviceTDengine.GetAggregateValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}'");

// // 平均值: 计算去除最大值 MAX和最小值 MIN 和异常值 ABN 的平均值
// systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and systolic_value < {systolicRefValue} ");
// diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and diastolic_value < {diastolicRefValue}");
// // 偏移参数
// //var avgOffset = 0.25M;
// //var systolicAvgOffset = avgOffset;
// //var diastolicAvgOffset = avgOffset;


// // 增量值=(标定值-平均值)* 0.25
// //systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!;
// //diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;

// systolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)! + SafeType.SafeInt(lastPush![4]); ;
// diastolicInc = (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)! + SafeType.SafeInt(lastPush![5]); ;

// // B.2.1 数据异常,将按最后一次测量值的offeset下发
// if (systolicAvg.Equals(0) || diastolicAvg.Equals(0))
// {
// _logger.LogInformation("B.2.1 曾经下推过断言有测量记录,数据异常,平均值为0");
// _logger.LogInformation($"{imei}本次计算结果\n{startTime:yyyy-MM-dd HH:mm:ss.fff}--{endTime:yyyy-MM-dd HH:mm:ss.fff}" +
// $"\n systolic:REF:{systolicRefValue} - Inc:{systolicInc} - AVG:{systolicAvg} - MAX:{systolicAggregate.Max} - MIN: {systolicAggregate.Min} " +
// $"\n diastolic:REF:{diastolicRefValue} - Inc:{diastolicInc} - AVG:{diastolicAvg} - MAX:{diastolicAggregate.Max} - MIN: {diastolicAggregate.Min}");
// _logger.LogInformation($"上次下发的增量值:systolic:{(int)lastPush![4]}--diastolic:{(int)lastPush![5]}");

// //if (systolicAvg.Equals(0))
// //{
// // systolicInc = (int)lastPush[4];
// //}

// //if (diastolicAvg.Equals(0))
// //{
// // diastolicInc = (int)lastPush[5];
// //}

// //return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false);
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);
// }
// // B.2.2 数据正常,按正常计算
// else
// {

// // 增量值=(标定值-平均值)* 0.25
// systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)! + SafeType.SafeInt(lastPush![4]);
// diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)! + SafeType.SafeInt(lastPush![5]);
// _logger.LogInformation("B.2.2 曾经下推过断言有测量记录,数据正常,按正常计算 ,增量值将正常下发");
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);
// }
// }
//}
*/

#endregion

}
@@ -432,291 +239,7 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor

return ApiResponse<object>.Fail(500, $" 接口出错:{ex.Message}\n{ex.StackTrace}");
}

}

/**
[HttpPost]
public async Task<ApiResponse<object>> Put([FromBody] BloodPressManualCalibration model, [FromHeader] string requestId)
{
var imei = model.Imei;

#region 设备合法性

#if DEBUG

#else
var param = new GeneralParam
{
Filters = new List<QueryFilterCondition>
{
new QueryFilterCondition
{
Key=nameof(GpsDevice.Serialno),
Value=model.Imei,
ValueType=QueryValueTypeEnum.String,
Operator=QueryOperatorEnum.Equal
}
}
};

var device = await _deviceApiClient.GetFirstAsync(param, new RequestHeader { RequestId = requestId }).ConfigureAwait(false);

if (device == null)
{

_logger.LogError($"非法设备:{model.Imei}");
return ApiResponse<object>.Fail(500, $"非法设备:{model.Imei}");
}
#endif

#endregion

#region 重置设备
if (model.ManualSystolicRefValue.Equals(0) && model.ManualDiastolicRefValue.Equals(0))
{
//return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, 0, 0, 0, 0).ConfigureAwait(false);
var statNow = DateTime.Now;
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, 0, 0, 0, 0, 0, 0, 0, 0, statNow, statNow).ConfigureAwait(false);

//return ApiResponse<object>.Success(new
//{
// imei = model.Imei,
// systolicCalibrationValue = 0, //收缩压标定值,值为0 表示不生效
// diastolicCalibrationValue = 0, //舒张压标定值,值为0表示不生效
// systolicIncValue = 0, //收缩压显示增量,值为0 表示不生效
// diastolicIncValue = 0 //舒张压显示增量,值为0 表示不生效
//});
}

#endregion

#region 数据合法性
if (model.ManualSystolicRefValue.Equals(0) || model.ManualDiastolicRefValue.Equals(0))
{
return ApiResponse<object>.Fail(501, $"数据非法,{JsonConvert.SerializeObject(model)}");
}
#endregion

#region 计算增量值

// 计算增量值
int systolicRefValue = model.ManualSystolicRefValue;//?
int diastolicRefValue = model.ManualDiastolicRefValue;//?
// 没有血压数据时增量值为0
int systolicInc;
int diastolicInc;
int systolicAvg;
int diastolicAvg;

// 偏移参数
var avgOffset = 0.25M;
var systolicAvgOffset = avgOffset;
var diastolicAvgOffset = avgOffset;

//int duration = 7;
long duration = 7 * 24 * 3600 * 1000;
TimeSpan ts = TimeSpan.FromMilliseconds(duration);
DateTime endTime = DateTime.Now; //测试
DateTime startTime = endTime - ts;

var lastPush = await _serviceTDengine.GetLastAsync("stb_hm_bp_push_ref_inc_value", $"serialno='{imei}' order by ts desc");

// A.没有下推记录
if (lastPush?.Count == 0 || lastPush == null)
{
//#region 初始化remarks
//// 读数据库,remarks为空就写commandValue,更新缓存
//var resFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(imei, systolicRefValue, diastolicRefValue).ConfigureAwait(false);
//if (resFlag)
//{
// _logger.LogInformation($"更新gps_person remarks和缓存");
//}
//else
//{
// _logger.LogInformation($"更新gps_person remarks和缓存失败");
//}
//#endregion

int count = await _serviceTDengine.GetCount("stb_hm_bloodpress", $"serialno='{imei}' ");
// A.1 没有下推记录,没有测量记录,下推增量值 0
if (count.Equals(0))
{
_logger.LogInformation("A.1 没有下推记录,没有测量记录,下推增量值 0");
// return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false);
systolicInc = 0;
diastolicInc = 0;
systolicAvg = 0;
diastolicAvg = 0;
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);

}
// A.2 没有下推记录,测量记录,正常计算增量值
else
{
// 平均值: 计算去除最大值 MAX和最小值 MIN 和异常值 ABN 的平均值
systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and systolic_value < {systolicRefValue} ");
diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and diastolic_value < {diastolicRefValue}");

// 数据异常,不修改增量值
if (systolicAvg.Equals(0) || diastolicAvg.Equals(0))
{
_logger.LogInformation(" A.2 没有下推记录,有测量记录,正常计算增量值 ,平均值为0, 增量值将按0下发");
systolicInc = 0;
diastolicInc = 0;
//return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false);
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);

}
// 数据正常
else
{
//// 偏移参数
//var avgOffset = 0.25M;
//var systolicAvgOffset = avgOffset;
//var diastolicAvgOffset = avgOffset;


// 增量值=(标定值-平均值)* 0.25
systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!;
diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;
_logger.LogInformation(" A.2 没有下推记录,有测量记录,正常计算增量值 ,增量值将正常下发");
// return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false);
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);

}
}
}
// B.有下推记录(更改过个人信息)
else
{
// B.1. 设备已经被重新设置
if (
(int)lastPush![2] == 0
&& (int)lastPush![3] == 0
&& (int)lastPush![4] == 0
&& (int)lastPush![5] == 0
)
{

// 转换时间
_ = DateTime.TryParse(lastPush?[0]!.ToString(), out DateTime newTs);
endTime = DateTime.Now;//newTs;
startTime = newTs;//DateTime.Now;

int count = await _serviceTDengine.GetCount("stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' ");
// B.1.1 设备已经被重新设置, 从重置的ts 到 now 没有测量数据,inc=0
if (count.Equals(0))
{
_logger.LogWarning("B.1.1 设备已经被重新设置, 从重置的ts 到 now 没有测量数据,inc=0");
systolicInc = 0;
diastolicInc = 0;
systolicAvg = 0;
diastolicAvg = 0;
// return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false);
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);

}
// B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据
else
{
// 平均值: 计算去除最大值 MAX和最小值 MIN 和异常值 ABN 的平均值
systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and systolic_value < {systolicRefValue} ");
diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and diastolic_value < {diastolicRefValue}");

// 数据异常,不修改增量值
if (systolicAvg.Equals(0) || diastolicAvg.Equals(0))
{
_logger.LogWarning("B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据,平均值为0,增量值将按0下发");
systolicInc = 0;
diastolicInc = 0;
//return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false);
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);
}
// 数据正常
else
{
//// 偏移参数
//var avgOffset = 0.25M;
//var systolicAvgOffset = avgOffset;
//var diastolicAvgOffset = avgOffset;
// 增量值=(标定值-平均值)* 0.25
systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)! + SafeType.SafeInt(lastPush![4]); ;
diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)! + SafeType.SafeInt(lastPush![5]); ;
_logger.LogInformation("B.1.2 设备已经被重新设置, 从重置的ts 到 now 有测量数据 ,增量值将正常下发");
//return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false);
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);
}

}

}
// B.2. 曾经下推过断言有测量记录
else
{
// 转换时间
_ = DateTime.TryParse(lastPush?[0]!.ToString(), out DateTime newTs);
endTime = DateTime.Now;
startTime = newTs;

// 最大值,最小值
var systolicAggregate = await _serviceTDengine.GetAggregateValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}'");
var diastolicAggregate = await _serviceTDengine.GetAggregateValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}'");

// 平均值: 计算去除最大值 MAX和最小值 MIN 和异常值 ABN 的平均值
systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and systolic_value < {systolicRefValue} ");
diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-dd HH:mm:ss.fff}' and ts <='{endTime:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imei}' and diastolic_value < {diastolicRefValue}");
// 偏移参数
//var avgOffset = 0.25M;
//var systolicAvgOffset = avgOffset;
//var diastolicAvgOffset = avgOffset;


// 增量值=(标定值-平均值)* 0.25
//systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!;
//diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;

systolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)! + SafeType.SafeInt(lastPush![4]); ;
diastolicInc = (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)! + SafeType.SafeInt(lastPush![5]); ;

// B.2.1 数据异常,将按最后一次测量值的offeset下发
if (systolicAvg.Equals(0) || diastolicAvg.Equals(0))
{
_logger.LogInformation("B.2.1 曾经下推过断言有测量记录,数据异常,平均值为0");
_logger.LogInformation($"{imei}本次计算结果\n{startTime:yyyy-MM-dd HH:mm:ss.fff}--{endTime:yyyy-MM-dd HH:mm:ss.fff}" +
$"\n systolic:REF:{systolicRefValue} - Inc:{systolicInc} - AVG:{systolicAvg} - MAX:{systolicAggregate.Max} - MIN: {systolicAggregate.Min} " +
$"\n diastolic:REF:{diastolicRefValue} - Inc:{diastolicInc} - AVG:{diastolicAvg} - MAX:{diastolicAggregate.Max} - MIN: {diastolicAggregate.Min}");
_logger.LogInformation($"上次下发的增量值:systolic:{(int)lastPush![4]}--diastolic:{(int)lastPush![5]}");

//if (systolicAvg.Equals(0))
//{
// systolicInc = (int)lastPush[4];
//}

//if (diastolicAvg.Equals(0))
//{
// diastolicInc = (int)lastPush[5];
//}

//return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false);
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);
}
// B.2.2 数据正常,按正常计算
else
{

// 增量值=(标定值-平均值)* 0.25
systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)! + SafeType.SafeInt(lastPush![4]);
diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)! + SafeType.SafeInt(lastPush![5]);
_logger.LogInformation("B.2.2 曾经下推过断言有测量记录,数据正常,按正常计算 ,增量值将正常下发");
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc, systolicAvg, diastolicAvg, systolicAvgOffset, diastolicAvgOffset, startTime, endTime).ConfigureAwait(false);
}
}
}
#endregion
}*/

private async Task<ApiResponse<object>> IotSetBloodPressCalibrationConfigResponseAsync(string imei, int systolicRefValue, int diastolicRefValue, int systolicInc, int diastolicInc)
{
BloodPressCalibrationConfigModel bpIncData = new()


+ 3
- 1
HealthMonitor.WebApi/Worker.cs Ver arquivo

@@ -223,7 +223,9 @@ namespace HealthMonitor.WebApi
systolicRefValue = lastPush!.SystolicRefValue;
diastolicRefValue = lastPush!.DiastolicRefValue;

condition = $"ts between '{startTime:yyyy-MM-dd HH:mm:ss.fff}' and '{lastPush?.Timestamp:yyyy-MM-dd HH:mm:ss.fff}' and serialno='{imeiDel}'";
condition = $"ts between '{startTime:yyyy-MM-dd HH:mm:ss.fff}' and '{lastPush?.Timestamp:yyyy-MM-dd HH:mm:ss.fff}' " +
$"and serialno='{imeiDel}' " +
$"and is_display = true";
var hmBpResponse = await _serviceTDengine.ExecuteSelectRestResponseAsync("stb_hm_bloodpress", condition);
var hmBpParser = JsonConvert.DeserializeObject<ParseTDengineRestResponse<BloodPressureModel>>(hmBpResponse!);
var hmBp = hmBpParser?.Select();


Carregando…
Cancelar
Salvar