Browse Source

optimize: 优化运算速度,修改实体类配置,添加种子数据

master
fajiao 2 years ago
parent
commit
17e1a4c46f
  1. 5
      Cis.Application/Cb/Entity/CbCamera.cs
  2. 15
      Cis.Application/Cis.Application.xml
  3. 2
      Cis.Application/Cm/Entity/CmMarkGroup.cs
  4. 6
      Cis.Application/Cm/Entity/CmMarkLabel.cs
  5. 9
      Cis.Application/Core/Center/CameraDataCenter.cs
  6. 56
      Cis.Application/Core/Component/MarkSeacher/Seacher/MarkSearcherBase.cs
  7. 11
      Cis.Application/Sys/Entity/SysDictData.cs
  8. 7
      Cis.Application/Sys/Entity/SysDictType.cs
  9. 18
      Cis.Application/Sys/SeedData/SysDictDataSeedData.cs
  10. 13
      Cis.Application/Sys/SeedData/SysDictTypeSeedData.cs
  11. 15
      Cis.Core/Cis.Core.xml
  12. 19
      Cis.Core/Common/Enum/CacheTypeEnum.cs

5
Cis.Application/Cb/Entity/CbCamera.cs

@ -1,4 +1,6 @@
namespace Cis.Application.Cb; using Furion.DataValidation;
namespace Cis.Application.Cb;
/// <summary> /// <summary>
/// 相机表 /// 相机表
@ -19,6 +21,7 @@ public class CbCamera : EntityBase
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "ip地址", Length = 16)] [SugarColumn(ColumnDescription = "ip地址", Length = 16)]
[Required, MaxLength(16)] [Required, MaxLength(16)]
[DataValidation(ValidationTypes.IPv4)]
public string Ip { get; set; } public string Ip { get; set; }
/// <summary> /// <summary>

15
Cis.Application/Cis.Application.xml

@ -669,6 +669,16 @@
<param name="zoomPos"></param> <param name="zoomPos"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Cis.Application.Core.Component.MarkSeacher.MarkSearcherBase.GetZoomTag(System.Double)">
<summary>
将计算公式存储到数据库,实现动态计算公式
https://github.com/houlongchao/HLC.Expression
https://blog.csdn.net/cxb2011/article/details/100837168
https://github.com/zz1231118/Rabbit
</summary>
<param name="zoomPos"></param>
<returns></returns>
</member>
<member name="M:Cis.Application.Core.Component.MarkSeacher.MarkSearcherBase.UpdateCameraCalcParams(EC.Helper.CameraSDK.PtzInfo)"> <member name="M:Cis.Application.Core.Component.MarkSeacher.MarkSearcherBase.UpdateCameraCalcParams(EC.Helper.CameraSDK.PtzInfo)">
<summary> <summary>
更新相机计算参数 更新相机计算参数
@ -759,11 +769,6 @@
字典类型Id 字典类型Id
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Sys.SysDictData.DictType">
<summary>
字典类型
</summary>
</member>
<member name="P:Cis.Application.Sys.SysDictData.Value"> <member name="P:Cis.Application.Sys.SysDictData.Value">
<summary> <summary>

2
Cis.Application/Cm/Entity/CmMarkGroup.cs

@ -11,12 +11,14 @@ public class CmMarkGroup : EntityBase
/// 名称 /// 名称
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "名称", Length = 64)] [SugarColumn(ColumnDescription = "名称", Length = 64)]
[Required]
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// 排序 /// 排序
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "排序")] [SugarColumn(ColumnDescription = "排序")]
[Required]
public int Order { get; set; } public int Order { get; set; }
/// <summary> /// <summary>

6
Cis.Application/Cm/Entity/CmMarkLabel.cs

@ -11,6 +11,7 @@ public class CmMarkLabel : EntityBase
/// 相机 Id /// 相机 Id
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "相机Id")] [SugarColumn(ColumnDescription = "相机Id")]
[Required]
public long CbCameraId { get; set; } public long CbCameraId { get; set; }
/// <summary> /// <summary>
@ -23,6 +24,7 @@ public class CmMarkLabel : EntityBase
/// 名称 /// 名称
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "名称", Length = 64)] [SugarColumn(ColumnDescription = "名称", Length = 64)]
[Required]
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
@ -47,24 +49,28 @@ public class CmMarkLabel : EntityBase
/// 视频宽度 /// 视频宽度
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "视频宽度")] [SugarColumn(ColumnDescription = "视频宽度")]
[Required]
public double VideoWidth { get; set; } public double VideoWidth { get; set; }
/// <summary> /// <summary>
/// 视频高度 /// 视频高度
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "视频高度")] [SugarColumn(ColumnDescription = "视频高度")]
[Required]
public double VideoHeight { get; set; } public double VideoHeight { get; set; }
/// <summary> /// <summary>
/// 画布 left 距离比例 /// 画布 left 距离比例
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "画布 left 距离比例")] [SugarColumn(ColumnDescription = "画布 left 距离比例")]
[Required]
public double CanvasLeftRatio { get; set; } public double CanvasLeftRatio { get; set; }
/// <summary> /// <summary>
/// 画布 top 距离比例 /// 画布 top 距离比例
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "画布 top 距离比例")] [SugarColumn(ColumnDescription = "画布 top 距离比例")]
[Required]
public double CanvasTopRatio { get; set; } public double CanvasTopRatio { get; set; }
/// <summary> /// <summary>

9
Cis.Application/Core/Center/CameraDataCenter.cs

@ -1,6 +1,4 @@
using Cis.Application.Cb; using Cis.Application.Core.Component.MarkSeacher;
using Cis.Application.Cm;
using Cis.Application.Core.Component.MarkSeacher;
using Cis.Application.Core.Component.PtzServer; using Cis.Application.Core.Component.PtzServer;
using EC.Helper.CameraSDK; using EC.Helper.CameraSDK;
using StackExchange.Profiling.Internal; using StackExchange.Profiling.Internal;
@ -13,10 +11,7 @@ public class CameraDataCenter : ISingleton
{ {
#region Attr #region Attr
private readonly SqlSugarRepository<CbCamera> _cbCameraRep;
private readonly SqlSugarRepository<CmMarkLabel> _cmMarkLableRep;
private readonly IDatabase _cache; private readonly IDatabase _cache;
private readonly CameraDataOptions _options; private readonly CameraDataOptions _options;
private readonly ICameraSdkServer _cameraSdkServer; private readonly ICameraSdkServer _cameraSdkServer;
private readonly IMarkSearcherServer _markSearcherServer; private readonly IMarkSearcherServer _markSearcherServer;
@ -35,8 +30,6 @@ public class CameraDataCenter : ISingleton
IMarkSearcherServer markSearcherServer IMarkSearcherServer markSearcherServer
) )
{ {
_cbCameraRep = App.GetService<SqlSugarRepository<CbCamera>>();
_cmMarkLableRep = App.GetService<SqlSugarRepository<CmMarkLabel>>();
_cache = cache; _cache = cache;
_options = App.GetOptions<CameraDataOptions>(); _options = App.GetOptions<CameraDataOptions>();
_cameraSdkServer = cameraSdkServer; _cameraSdkServer = cameraSdkServer;

56
Cis.Application/Core/Component/MarkSeacher/Seacher/MarkSearcherBase.cs

@ -147,29 +147,12 @@ public abstract class MarkSearcherBase
public List<MarkLabelCalcResult> Search() public List<MarkLabelCalcResult> Search()
{ {
List<MarkLabelCalcResult> resultList = new(); List<MarkLabelCalcResult> resultList = new();
if (World2CameraMatrix == null || MarkLabelCalcParamsDict.IsEmpty) if (World2CameraMatrix == null || MarkLabelCalcParamsDict.IsEmpty)
return resultList; return resultList;
foreach (MarkLabelCalcParams item in MarkLabelCalcParamsDict.Values) foreach (MarkLabelCalcParams item in MarkLabelCalcParamsDict.Values)
{ {
Matrix<double> labelC2WMatrix = ConvertCameraToWorld(item); MarkLabelCalcResult labelCalcResult = SearchMarkLabel(item);
Matrix<double> labelPointMatrix = new DenseMatrix(3, 1, new double[]
{
(item.CanvasLeftRatio-0.5)*item.VideoWidth / CameraCalcParams.VideoWidth,
(item.CanvasTopRatio-0.5)*item.VideoHeight / CameraCalcParams.VideoHeight,
1
});
Matrix<double> lResult = labelC2WMatrix.Multiply(labelPointMatrix);
Matrix<double> pResult = World2CameraMatrix.Multiply(lResult);
double x = pResult[0, 0] / pResult[2, 0] + 0.5;
double y = pResult[1, 0] / pResult[2, 0] + 0.5;
MarkLabelCalcResult labelCalcResult;
if (x > 0.99 || x < 0.01 || y > 0.99 || y < 0.01 || pResult[2, 0] < 0)
labelCalcResult = MarkLabelCalcResult.New(item.Id, false);
else
labelCalcResult = MarkLabelCalcResult.New(item.Id, true, x, y);
resultList.Add(labelCalcResult); resultList.Add(labelCalcResult);
} }
return resultList; return resultList;
@ -177,7 +160,42 @@ public abstract class MarkSearcherBase
public async Task<List<MarkLabelCalcResult>> SearchAsync() public async Task<List<MarkLabelCalcResult>> SearchAsync()
{ {
return await Task.Run(Search); List<MarkLabelCalcResult> resultList = new();
if (World2CameraMatrix == null || MarkLabelCalcParamsDict.IsEmpty)
return resultList;
List<Task> tasks = new();
foreach (MarkLabelCalcParams item in MarkLabelCalcParamsDict.Values)
{
tasks.Add(Task.Run(() =>
{
resultList.Add(SearchMarkLabel(item));
}));
}
await Task.WhenAll(tasks);
return resultList;
}
private MarkLabelCalcResult SearchMarkLabel(MarkLabelCalcParams item)
{
Matrix<double> labelC2WMatrix = ConvertCameraToWorld(item);
Matrix<double> labelPointMatrix = new DenseMatrix(3, 1, new double[]
{
(item.CanvasLeftRatio-0.5)*item.VideoWidth / CameraCalcParams.VideoWidth,
(item.CanvasTopRatio-0.5)*item.VideoHeight / CameraCalcParams.VideoHeight,
1
});
Matrix<double> lResult = labelC2WMatrix.Multiply(labelPointMatrix);
Matrix<double> pResult = World2CameraMatrix.Multiply(lResult);
double x = pResult[0, 0] / pResult[2, 0] + 0.5;
double y = pResult[1, 0] / pResult[2, 0] + 0.5;
MarkLabelCalcResult labelCalcResult;
if (x > 0.99 || x < 0.01 || y > 0.99 || y < 0.01 || pResult[2, 0] < 0)
labelCalcResult = MarkLabelCalcResult.New(item.Id, false);
else
labelCalcResult = MarkLabelCalcResult.New(item.Id, true, x, y);
return labelCalcResult;
} }
#endregion Calc #endregion Calc

11
Cis.Application/Sys/Entity/SysDictData.cs

@ -4,21 +4,16 @@
/// 系统字典值表 /// 系统字典值表
/// </summary> /// </summary>
[SugarTable("sys_dict_data", "系统字典值表")] [SugarTable("sys_dict_data", "系统字典值表")]
[Tenant(SysInfo.DbName)]
public class SysDictData : EntityBase public class SysDictData : EntityBase
{ {
/// <summary> /// <summary>
/// 字典类型Id /// 字典类型Id
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "字典类型Id")] [SugarColumn(ColumnDescription = "字典类型Id")]
[Required]
public long DictTypeId { get; set; } public long DictTypeId { get; set; }
/// <summary>
/// 字典类型
/// </summary>
[SugarColumn(IsIgnore = true)]
[Navigate(NavigateType.OneToOne, nameof(DictTypeId))]
public SysDictType DictType { get; set; }
/// <summary> /// <summary>
/// 值 /// 值
/// </summary> /// </summary>
@ -37,6 +32,7 @@ public class SysDictData : EntityBase
/// 排序 /// 排序
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "排序")] [SugarColumn(ColumnDescription = "排序")]
[Required]
public int Order { get; set; } public int Order { get; set; }
/// <summary> /// <summary>
@ -50,5 +46,6 @@ public class SysDictData : EntityBase
/// 状态 /// 状态
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "状态")] [SugarColumn(ColumnDescription = "状态")]
[Required]
public StatusEnum Status { get; set; } = StatusEnum.Enable; public StatusEnum Status { get; set; } = StatusEnum.Enable;
} }

7
Cis.Application/Sys/Entity/SysDictType.cs

@ -1,9 +1,12 @@
namespace Cis.Application.Sys; using Cis.Application.Cm;
namespace Cis.Application.Sys;
/// <summary> /// <summary>
/// 系统字典类型表 /// 系统字典类型表
/// </summary> /// </summary>
[SugarTable(SysInfo.SysDictTypeTbName, SysInfo.SysDictTypeTbDesc)] [SugarTable(SysInfo.SysDictTypeTbName, SysInfo.SysDictTypeTbDesc)]
[Tenant(SysInfo.DbName)]
public class SysDictType : EntityBase public class SysDictType : EntityBase
{ {
/// <summary> /// <summary>
@ -24,6 +27,7 @@ public class SysDictType : EntityBase
/// 排序 /// 排序
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "排序")] [SugarColumn(ColumnDescription = "排序")]
[Required]
public int Order { get; set; } public int Order { get; set; }
/// <summary> /// <summary>
@ -37,5 +41,6 @@ public class SysDictType : EntityBase
/// 状态 /// 状态
/// </summary> /// </summary>
[SugarColumn(ColumnDescription = "状态")] [SugarColumn(ColumnDescription = "状态")]
[Required]
public StatusEnum Status { get; set; } = StatusEnum.Enable; public StatusEnum Status { get; set; } = StatusEnum.Enable;
} }

18
Cis.Application/Sys/SeedData/SysDictDataSeedData.cs

@ -0,0 +1,18 @@
namespace Cis.Application.Sys.SeedData;
public class SysDictDataSeedData : ISqlSugarEntitySeedData<SysDictData>
{
public IEnumerable<SysDictData> HasData()
{
return new SysDictData[]
{
new(){Id=358769934100001, DictTypeId=358728043100001, Code="HiK", Value="1", Order=100, Remark="海康相机", Status=StatusEnum.Enable, CreateTime=DateTime.Parse("2022-11-30 00:00:00")},
new(){Id=358769934100002, DictTypeId=358728043100001, Code="DaHua", Value="2", Order=100, Remark="大华相机", Status=StatusEnum.Enable, CreateTime=DateTime.Parse("2022-11-30 00:00:00")},
new(){Id=358769934100003, DictTypeId=358728043100001, Code="YuShi", Value="3", Order=100, Remark="宇视相机", Status=StatusEnum.Enable, CreateTime=DateTime.Parse("2022-11-30 00:00:00")},
new(){Id=358769934100011, DictTypeId=358728043100002, Code="HiK", Value="8000", Order=100, Remark="海康sdk端口", Status=StatusEnum.Enable, CreateTime=DateTime.Parse("2022-11-30 00:00:00")},
new(){Id=358769934100012, DictTypeId=358728043100002, Code="DaHua", Value="37777", Order=100, Remark="大华sdk端口", Status=StatusEnum.Enable, CreateTime=DateTime.Parse("2022-11-30 00:00:00")},
new(){Id=358769934100013, DictTypeId=358728043100002, Code="YuShi", Value="8800", Order=100, Remark="宇视sdk端口", Status=StatusEnum.Enable, CreateTime=DateTime.Parse("2022-11-30 00:00:00")},
};
}
}

13
Cis.Application/Sys/SeedData/SysDictTypeSeedData.cs

@ -0,0 +1,13 @@
namespace Cis.Application.Sys.SeedData;
public class SysDictTypeSeedData : ISqlSugarEntitySeedData<SysDictType>
{
public IEnumerable<SysDictType> HasData()
{
return new SysDictType[]
{
new(){ Id=358728043100001, Name="相机类型", Code="camera_type", Order=100, Remark="相机类型", Status=StatusEnum.Enable, CreateTime=DateTime.Parse("2022-11-30 00:00:00")},
new(){ Id=358728043100002, Name="相机SDK端口", Code="camera_sdk_port", Order=100, Remark="相机SDK端口", Status=StatusEnum.Enable, CreateTime=DateTime.Parse("2022-11-30 00:00:00")},
};
}
}

15
Cis.Core/Cis.Core.xml

@ -194,21 +194,6 @@
时间戳 时间戳
</summary> </summary>
</member> </member>
<member name="T:Cis.Core.CacheTypeEnum">
<summary>
缓存类型枚举
</summary>
</member>
<member name="F:Cis.Core.CacheTypeEnum.Memory">
<summary>
内存缓存
</summary>
</member>
<member name="F:Cis.Core.CacheTypeEnum.Redis">
<summary>
Redis缓存
</summary>
</member>
<member name="T:Cis.Core.StatusEnum"> <member name="T:Cis.Core.StatusEnum">
<summary> <summary>
通用状态枚举 通用状态枚举

19
Cis.Core/Common/Enum/CacheTypeEnum.cs

@ -1,19 +0,0 @@
namespace Cis.Core;
/// <summary>
/// 缓存类型枚举
/// </summary>
public enum CacheTypeEnum
{
/// <summary>
/// 内存缓存
/// </summary>
[Description("内存缓存")]
Memory,
/// <summary>
/// Redis缓存
/// </summary>
[Description("Redis缓存")]
Redis
}
Loading…
Cancel
Save