using IStation.Model;
|
|
namespace IStation.Test
|
{
|
public class Station2TotalFlowDiffHelper
|
{
|
/// <summary>
|
/// 输出偏差数据
|
/// </summary>
|
public static void Start()
|
{
|
var bll = new BLL.StationSignalRecordPacket();
|
var projectId = 661070185922629;
|
IStation.SettingsD.Project.ID = projectId;
|
var monitorDataSourcesId = 663976941449285;//2024-202504
|
var stationId = 462958422204485;
|
var ptFilterList = new List<PointViewModel>();
|
|
var packets = bll.Get(monitorDataSourcesId, stationId);
|
var ptList = new List<FlowDiffViewModel>();
|
|
var records = packets.SelectMany(x => x.StationSignalRecords).ToList();
|
foreach (var x in records)
|
{
|
if (x.TotalPressure > 0 && x.TotalFlow > 0)
|
{
|
ptList.Add( new (x.TotalFlow, Math.Round(x.TotalPressure, 1), x.DiffFlow));
|
}
|
}
|
|
var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "stationcsv");
|
if (!Directory.Exists(fullPath))
|
{
|
Directory.CreateDirectory(fullPath);
|
}
|
|
|
|
var group = ptList.GroupBy(x => x.Pressure);
|
string filePath = Path.Combine(fullPath, "flow_diff_range2.csv");
|
using StreamWriter writer = new(filePath, false, System.Text.Encoding.UTF8);
|
writer.WriteLine($"Pressure2,FlowDiffUpper,FlowDiffAverage,FlowDiffLower");
|
var allList = new List<FlowDiffViewModel>();
|
foreach (var item in group)
|
{
|
var tt = item.ToList();
|
var fList = Filter(tt);
|
allList.AddRange(fList);
|
var x = item.Key;
|
var yUpper = item.Max(x => x.FlowDiff);
|
var yLower = item.Min(x => x.FlowDiff);
|
var yAverage = item.Average(x => x.FlowDiff);
|
|
if (fList != null && fList.Any())
|
{
|
yUpper = fList.Max(x => x.FlowDiff);
|
yLower = fList.Min(x => x.FlowDiff);
|
yAverage = fList.Average(x => x.FlowDiff);
|
}
|
|
yUpper = Math.Round(yUpper,1);
|
yLower = Math.Round(yLower, 1);
|
yAverage = Math.Round(yAverage, 1);
|
|
writer.WriteLine($"{x},{yUpper},{yAverage},{yLower}");
|
}
|
string filePathAll = Path.Combine(fullPath, "flow_diff2.csv");
|
CsvHelper.ExportToCsv(allList, filePathAll);
|
|
Console.WriteLine("ok");
|
Console.ReadKey();
|
|
}
|
|
public static List<FlowDiffViewModel> Filter(List<FlowDiffViewModel> ptList)
|
{
|
var pressures = ptList.Select(p => p.FlowDiff).ToList();
|
|
// 计算统计量
|
var (mean, stdDev) = DynamicThresholdProcessorHelper.CalculateStats(pressures);
|
double skewness = DynamicThresholdProcessorHelper.CalculateSkewness(pressures);
|
// 动态调整σ倍数
|
//double sigmaMultiplier = DynamicThresholdProcessorHelper.CalculateSigmaMultiplier(skewness);
|
var sigmaMultiplier = 3;//目前默认 标准差
|
|
// 计算边界
|
double lower = mean - sigmaMultiplier * stdDev;
|
double upper = mean + sigmaMultiplier * stdDev;
|
|
return ptList.Where(p => p.FlowDiff >= lower && p.FlowDiff <= upper).ToList();
|
}
|
|
public class FlowDiffViewModel
|
{
|
public FlowDiffViewModel(double totalFlow, double pressure, double flowDiff)
|
{
|
TotalFlow = Math.Round(totalFlow, 1);
|
Pressure = pressure;
|
FlowDiff = Math.Round(flowDiff,1);
|
}
|
public double TotalFlow { get; set; }
|
public double Pressure { get; set; }
|
public double FlowDiff { get; set; }
|
}
|
|
|
}
|
}
|