using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace YunDa.SOMS.Application.DataMonitoring.SecondaryCircuitInspection.Services
{
///
/// 时间窗口计算服务接口
///
public interface ITimeWindowCalculatorService
{
///
/// 计算时间窗口内的数据并返回JSON格式结果
///
/// 巡检项ID
/// 时间窗口(秒)
/// 取消令牌
/// JSON格式的计算结果,如 {"16835_0": 52.5, "16835_1": 75.3}
Task CalculateTimeWindowDataAsync(
Guid inspectionItemId,
int timeWindowSeconds = 60,
CancellationToken cancellationToken = default);
///
/// 计算时间窗口内的数据并返回结构化结果
///
/// 巡检项ID
/// 时间窗口(秒)
/// 取消令牌
/// 结构化的计算结果
Task CalculateTimeWindowDataStructuredAsync(
Guid inspectionItemId,
int timeWindowSeconds = 60,
CancellationToken cancellationToken = default);
///
/// 根据变量代码列表计算时间窗口数据
///
/// 变量代码列表,格式如 ["16835_0", "16835_1"]
/// 时间窗口(秒)
/// 取消令牌
/// JSON格式的计算结果
Task CalculateVariableDataAsync(
List variableCodes,
int timeWindowSeconds = 60,
CancellationToken cancellationToken = default);
///
/// 计算时间窗口内的历史数据(支持时间序列)
///
/// 巡检项ID
/// 时间窗口(秒)
/// 采样间隔(秒)
/// 取消令牌
/// 时间序列数据
Task>> CalculateTimeSeriesDataAsync(
Guid inspectionItemId,
int timeWindowSeconds = 60,
int sampleIntervalSeconds = 5,
CancellationToken cancellationToken = default);
///
/// 使用JavaScript表达式计算时间窗口数据
///
/// 巡检项ID
/// JavaScript表达式
/// 时间窗口(秒)
/// 取消令牌
/// 计算结果
Task CalculateWithJavaScriptExpressionAsync(
Guid inspectionItemId,
string javascriptExpression,
int timeWindowSeconds = 60,
CancellationToken cancellationToken = default);
}
///
/// 计算结果类
///
public class CalculationResult
{
///
/// 计算是否成功
///
public bool IsSuccess { get; set; }
///
/// 错误信息
///
public string ErrorMessage { get; set; }
///
/// 计算结果数据(变量代码 -> 值)
///
public Dictionary Data { get; set; }
///
/// JSON格式的结果
///
public string JsonResult { get; set; }
///
/// 计算详情
///
public List CalculationDetails { get; set; }
///
/// 计算耗时(毫秒)
///
public long ExecutionTimeMs { get; set; }
///
/// 计算时间
///
public DateTime CalculationTime { get; set; }
///
/// 时间窗口开始时间
///
public DateTime WindowStartTime { get; set; }
///
/// 时间窗口结束时间
///
public DateTime WindowEndTime { get; set; }
public CalculationResult()
{
Data = new Dictionary();
CalculationDetails = new List();
CalculationTime = DateTime.Now;
}
}
}