Commit 2dc9fb79 by liulongfei

1. 操作日志记录

parent 00c929b2
......@@ -173,8 +173,6 @@ namespace VIZ.H2V.Module
// 裁切框在手动模式下由客户端控制,不需要处理算法给的裁切框
if (msg.roi == null || this.StrategyMode == AlgorithmStrategyMode.manual_mode)
{
view.video.ClearClipBox();
return;
}
......
......@@ -115,6 +115,9 @@ namespace VIZ.H2V.Module
try
{
// 记录操作日志
this.WriteLogOperation(context);
// 停止3D鼠标更新
Navigation3DManager.Navigation3DModel.IsReady = false;
......@@ -305,5 +308,33 @@ namespace VIZ.H2V.Module
break;
}
}
/// <summary>
/// 操作日志
/// </summary>
/// <param name="context">切换算法上下文</param>
private void WriteLogOperation(ChangeStrategyContext context)
{
AlgorithmStrategyMode last_mode = this.StrategyMode;
lock (ApplicationDomainEx.CsvContext.LogOperations)
{
DateTime now = DateTime.Now;
LogOperation last = ApplicationDomainEx.CsvContext.LogOperations.LastOrDefault();
if (last != null)
{
last.EndTime = now;
last.Duration = now - last.BeginTime;
}
LogOperation log = new LogOperation();
log.ViewKey = this.ViewKey;
log.Operation = last_mode.GetDescription();
log.BeginTime = now;
ApplicationDomainEx.CsvContext.LogOperations.Add(log);
}
}
}
}
......@@ -38,11 +38,17 @@ namespace VIZ.H2V.Module
string algorithm_border_scence_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config", "algorithm_border_scene.csv");
string clip_system_path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config", "clip_system.csv");
// CSV配置
ApplicationDomainEx.CsvContext = new CsvContext();
ApplicationDomainEx.CsvContext.LoadAlgorithmStrategys(algorithm_strategy_path);
ApplicationDomainEx.CsvContext.LoadAlgorithmBorderScenes(algorithm_border_scence_path);
ApplicationDomainEx.CsvContext.LoadClipSystems(clip_system_path);
// 操作日志
ApplicationDomainEx.CsvContext.OpenLogOperations();
ApplicationDomainEx.LoopManager.Register("AppSetup_InitCsv.WriteLogOperations", 60, this.WriteLogOperations);
return true;
}
......@@ -52,7 +58,25 @@ namespace VIZ.H2V.Module
/// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context)
{
lock (ApplicationDomainEx.CsvContext.LogOperations)
{
LogOperation last = ApplicationDomainEx.CsvContext.LogOperations.LastOrDefault();
if (last != null)
{
last.EndTime = DateTime.Now;
last.Duration = last.EndTime - last.BeginTime;
}
}
ApplicationDomainEx.CsvContext.CloseLogOperations();
}
/// <summary>
/// 写入操作日志
/// </summary>
private void WriteLogOperations()
{
ApplicationDomainEx.CsvContext.FlushLogOperations();
}
}
}
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
......@@ -6,6 +7,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CsvHelper;
using CsvHelper.Configuration;
using VIZ.Framework.Storage;
namespace VIZ.H2V.Storage
{
......@@ -17,19 +20,28 @@ namespace VIZ.H2V.Storage
/// <summary>
/// 算法信息
/// </summary>
[Csv(Scene = CsvScene.Read)]
public List<AlgorithmStrategy> AlgorithmStrategys { get; private set; }
/// <summary>
/// 边线场景
/// </summary>
[Csv(Scene = CsvScene.Read)]
public List<AlgorithmBorderScene> AlgorithmBorderScenes { get; private set; }
/// <summary>
/// 裁切系统
/// </summary>
[Csv(Scene = CsvScene.Read)]
public List<ClipSystem> ClipSystems { get; private set; }
/// <summary>
/// 操作日志
/// </summary>
[Csv(Scene = CsvScene.Read)]
public List<LogOperation> LogOperations { get; private set; }
/// <summary>
/// 加载算法信息
/// </summary>
/// <param name="path">文件路径</param>
......@@ -67,5 +79,61 @@ namespace VIZ.H2V.Storage
this.ClipSystems = reader.GetRecords<ClipSystem>()?.ToList();
}
}
// ====================================================================================
// 操作日志
/// <summary>
/// 操作日志输出
/// </summary>
private CsvWriter logOperationsWriter;
/// <summary>
/// 打开操作日志
/// </summary>
public void OpenLogOperations()
{
string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log_operation");
string fileName = Path.Combine(dir, $"{DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss")}.csv");
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
CsvConfiguration config = new CsvConfiguration(System.Threading.Thread.CurrentThread.CurrentCulture);
CsvWriter writer = new CsvWriter(new StreamWriter(fileName, false, Encoding.Default), config);
writer.Context.RegisterClassMap(new LogOperationMap());
this.LogOperations = new List<LogOperation>();
this.logOperationsWriter = writer;
}
/// <summary>
/// 输出操作日志
/// </summary>
public void FlushLogOperations()
{
if (this.logOperationsWriter == null || this.LogOperations == null || this.LogOperations.Count == 0)
return;
lock (this.LogOperations)
{
this.logOperationsWriter.WriteRecords(this.LogOperations);
this.LogOperations.Clear();
}
}
/// <summary>
/// 关闭操作日志
/// </summary>
public void CloseLogOperations()
{
this.FlushLogOperations();
this.logOperationsWriter?.Flush();
this.logOperationsWriter?.Dispose();
this.logOperationsWriter = null;
}
}
}
......@@ -115,6 +115,7 @@
<Compile Include="CSV\Algorithm\AlgorithmStrategy.cs" />
<Compile Include="CSV\Clip\ClipSystem.cs" />
<Compile Include="CSV\CsvContext.cs" />
<Compile Include="CSV\Log\LogOperation.cs" />
<Compile Include="Init\Config\AlgorithmConfig.cs" />
<Compile Include="Init\Config\UdpConfig.cs" />
<Compile Include="LiteDB\Algorithm\AlgorithmBase.cs" />
......
......@@ -35,7 +35,7 @@ VIDEO_CLIP_BOX_BORDER_COLOR=#FFFF0000
;视频剪切掩码颜色
VIDEO_CLIP_BOX_MASK_COLOR=#88000000
;视频边线检测多边形区域透明度
VIDEO_SIDE_CHECK_POLYGON_OPACITY=0.2
VIDEO_SIDE_CHECK_POLYGON_OPACITY=0.15
; ============================================================
; === Navigation3D ===
; ============================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment