Procházet zdrojové kódy

使用超级表

td_orm
H Vs před 1 rokem
rodič
revize
e2904e70fa
5 změnil soubory, kde provedl 118 přidání a 16 odebrání
  1. +18
    -0
      HealthMonitor.Common/DateTimeUtil.cs
  2. +13
    -1
      HealthMonitor.Service/Biz/db/TDengineService.cs
  3. +79
    -11
      HealthMonitor.Service/Resolver/BloodpressResolver.cs
  4. +7
    -1
      HealthMonitor.Service/Sub/TDengineDataSubcribe.cs
  5. +1
    -3
      HealthMonitor.WebApi/PackageProcess.cs

+ 18
- 0
HealthMonitor.Common/DateTimeUtil.cs Zobrazit soubor

@@ -9,6 +9,22 @@ namespace HealthMonitor.Common
public class DateTimeUtil
{


/// <summary>
/// 时间类型转成时间戳
/// </summary>
/// <param name="time">Local Time</param>
/// <returns></returns>
public static long ConvertToTimeStamp(DateTime time)
{
long intResult = 0;
DateTime startTime = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Utc, TimeZoneInfo.Local);
intResult = (long)(time - startTime).TotalMilliseconds;
return intResult;
}



/// <summary>
/// 毫秒时间戳转本地时间
/// </summary>
@@ -697,6 +713,8 @@ namespace HealthMonitor.Common
return sRet;
}


///// <summary>
///// 是否为日期型字符串
///// </summary>


+ 13
- 1
HealthMonitor.Service/Biz/db/TDengineService.cs Zobrazit soubor

@@ -33,13 +33,20 @@ namespace HealthMonitor.Service.Biz.db
}
public IntPtr Connection()
{
string host = _configTDengineService.Host;
string user = _configTDengineService.UserName;
string db = _configTDengineService.DB;
short port = _configTDengineService.Port;
string password = _configTDengineService.Password;
//#if DEBUG
// //string configDir = "C:/TDengine/cfg";
// //TDengine.Options((int)TDengineInitOption.TSDB_OPTION_CONFIGDIR, configDir);
// TDengine.Options((int)TDengineInitOption.TSDB_OPTION_TIMEZONE, "Asia/Beijing");
//#endif
IntPtr conn = TDengine.Connect(host, user, password, db, port);


if (conn == IntPtr.Zero)
{
_logger.LogError($"连接 TDengine 失败....");
@@ -130,6 +137,11 @@ namespace HealthMonitor.Service.Biz.db
// "d1002 USING power.meters TAGS('California.SanFrancisco', 3) VALUES('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000) " +
// "d1003 USING power.meters TAGS('California.LosAngeles', 2) VALUES('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000) " +
// "d1004 USING power.meters TAGS('California.LosAngeles', 3) VALUES('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000)('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
//#if DEBUG
// //string configDir = "C:/TDengine/cfg";
// //TDengine.Options((int)TDengineInitOption.TSDB_OPTION_CONFIGDIR, configDir);
// TDengine.Options((int)TDengineInitOption.TSDB_OPTION_TIMEZONE, "Asia/Beijing");
//#endif
IntPtr res = TDengine.Query(conn, sql);
CheckRes(conn, res, "failed to insert data");
int affectedRows = TDengine.AffectRows(res);


+ 79
- 11
HealthMonitor.Service/Resolver/BloodpressResolver.cs Zobrazit soubor

@@ -106,8 +106,8 @@ namespace HealthMonitor.Service.Resolver
DateTime endTime = now;

//
var systolicAggregate = await _serviceTDengine.GetAggregateValueAsync("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
var diastolicAggregate = await _serviceTDengine.GetAggregateValueAsync("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
var systolicAggregate = await _serviceTDengine.GetAggregateValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
var diastolicAggregate = await _serviceTDengine.GetAggregateValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
//var systolicAggregate = _serviceTDengine.GetAggregateValue("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
//var diastolicAggregate = _serviceTDengine.GetAggregateValue("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'");
@@ -120,8 +120,8 @@ namespace HealthMonitor.Service.Resolver


// 计算去除最大值和最小值和异常值的平均值
var systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and systolic_value < {systolicRefValue} ");
var diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and diastolic_value < {diastolicRefValue}");
var systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and systolic_value < {systolicRefValue} ");
var diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and diastolic_value < {diastolicRefValue}");

//var systolicAvg = _serviceTDengine.GetAvgExceptMaxMinValue("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and systolic_value < {systolicRefValue} ");
//var diastolicAvg = _serviceTDengine.GetAvgExceptMaxMinValue("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and diastolic_value < {diastolicRefValue}");
@@ -141,9 +141,78 @@ namespace HealthMonitor.Service.Resolver

#endregion




// _logger.LogInformation($"health_monitor.hm_bp_stats_inc_{bp.Serialno.Substring(bp.Serialno.Length - 2)}");
//if (bp.MessageId.Equals("1674952622991276544"))
//{
// var aa = bp;
// var cc = aa;
//}

#region 插入BP增量值 hm_bloodpress_stats_inc
var sql = $"INSERT INTO health_monitor.hm_bloodpress_stats_inc VALUES(" +
$"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
//var sql = $"INSERT INTO health_monitor.hm_bp_stats_inc_{bp.Serialno.Substring(bp.Serialno.Length - 2)} VALUES(" +
// $"{DateTimeUtil.ConvertToTimeStamp((DateTime)bp.LastUpdate)* 1000000}" +
// $"'{bp.BloodPressId}'," +
// $"'{bp.MessageId}'," +
// $"'{bp.Serialno}'," +
// $"{bp.SystolicValue}," +
// $"{systolicRefValue}," +
// $"{systolicAvg}," +
// $"{systolicMax}," +
// $"{systolicMin}," +
// $"{systolicAvgOffset}," +
// $"{systolicInc}," +
// $"{bp.DiastolicValue}," +
// $"{diastolicRefValue}," +
// $"{diastolicAvg}," +
// $"{diastolicMax}," +
// $"{diastolicMin}," +
// $"{diastolicAvgOffset}," +
// $"{diastolicInc}," +
// $"{gender}," +
// $"{age}," +
// $"{height}," +
// $"{weight}," +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"{duration}," +
// $"'{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{string.Empty}')";

//var sql = $"INSERT INTO health_monitor.hm_bp_stats_inc_{bp.Serialno.Substring(bp.Serialno.Length - 2)} VALUES(" +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{bp.BloodPressId}'," +
// $"'{bp.MessageId}'," +
// $"'{bp.Serialno}'," +
// $"{bp.SystolicValue}," +
// $"{systolicRefValue}," +
// $"{systolicAvg}," +
// $"{systolicMax}," +
// $"{systolicMin}," +
// $"{systolicAvgOffset}," +
// $"{systolicInc}," +
// $"{bp.DiastolicValue}," +
// $"{diastolicRefValue}," +
// $"{diastolicAvg}," +
// $"{diastolicMax}," +
// $"{diastolicMin}," +
// $"{diastolicAvgOffset}," +
// $"{diastolicInc}," +
// $"{gender}," +
// $"{age}," +
// $"{height}," +
// $"{weight}," +
// $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"{duration}," +
// $"'{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
// $"'{string.Empty}')";
//var res = await _serviceTDengine.GernalRestSql(sql);

var sql = $"INSERT INTO health_monitor.hm_bp_stats_inc_{bp.Serialno.Substring(bp.Serialno.Length - 2)} VALUES(" +
$"'{bp.LastUpdate:yyyy-MM-dd HH:mm:ss.fff}'," +
$"'{bp.BloodPressId}'," +
$"'{bp.MessageId}'," +
$"'{bp.Serialno}'," +
@@ -165,13 +234,12 @@ namespace HealthMonitor.Service.Resolver
$"{age}," +
$"{height}," +
$"{weight}," +
$"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
$"'{bp.LastUpdate:yyyy-MM-dd HH:mm:ss.fff}'," +
$"{duration}," +
$"'{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
$"'{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," +
$"'{startTime:yyyy-MM-dd HH:mm:ss.fff}'," +
$"'{endTime:yyyy-MM-dd HH:mm:ss.fff}'," +
$"'{string.Empty}')";
//var res = await _serviceTDengine.GernalRestSql(sql);
_serviceTDengine.ExecuteInsertSQL(sql);
_serviceTDengine.ExecuteInsertSQL(sql);
#endregion
}



+ 7
- 1
HealthMonitor.Service/Sub/TDengineDataSubcribe.cs Zobrazit soubor

@@ -85,7 +85,13 @@ namespace HealthMonitor.Service.Sub
string username = _configTDengineService.UserName;
string password = _configTDengineService.Password;
string dbname = _configTDengineService.DB;
//#if DEBUG
// //string configDir = "C:/TDengine/cfg";
// //TDengine.Options((int)TDengineInitOption.TSDB_OPTION_CONFIGDIR, configDir);
// TDengine.Options((int)TDengineInitOption.TSDB_OPTION_TIMEZONE, "Asia/Beijing");
//#endif
var conn = TDengine.Connect(host, username, password, dbname, port);

if (conn == IntPtr.Zero)
{
_logger.LogError("reason:{TDengine.Error(conn)}", TDengine.Error(conn));
@@ -127,7 +133,7 @@ namespace HealthMonitor.Service.Sub
attributes = attributes.TrimEnd(',');

//create topic
IntPtr res = TDengine.Query(Connection, $"create topic if not exists {topic} as select {attributes} from health_monitor.hm_bloodpress");
IntPtr res = TDengine.Query(Connection, $"create topic if not exists {topic} as select {attributes} from health_monitor.stb_hm_bloodpress");

if (TDengine.ErrorNo(res) != 0)
{


+ 1
- 3
HealthMonitor.WebApi/PackageProcess.cs Zobrazit soubor

@@ -33,9 +33,7 @@ namespace HealthMonitor.WebApi
}
catch (Exception ex)
{

_logger.LogError("未处理异常 message: {ex.Message}\n {ex.StackTrace}", ex.Message, ex.StackTrace);
_logger.LogError($"未处理异常 message: {ex.Message}\n {ex.StackTrace}");
}

return true;


Načítá se…
Zrušit
Uložit