From ea7b317c22ecb371910373b4d20f6bac3ad47738 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期二, 01 四月 2025 11:13:37 +0800
Subject: [PATCH] 系统曲线  修改逻辑

---
 WinFrmUI/PBS.WinFrmUI.Hydro/05-system-curve/02-chart/SystemCurveChartCtrl.cs |   77 +++++++++++++++++++++++++++++++++++---
 1 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/WinFrmUI/PBS.WinFrmUI.Hydro/05-system-curve/02-chart/SystemCurveChartCtrl.cs b/WinFrmUI/PBS.WinFrmUI.Hydro/05-system-curve/02-chart/SystemCurveChartCtrl.cs
index de1411a..eaeebba 100644
--- a/WinFrmUI/PBS.WinFrmUI.Hydro/05-system-curve/02-chart/SystemCurveChartCtrl.cs
+++ b/WinFrmUI/PBS.WinFrmUI.Hydro/05-system-curve/02-chart/SystemCurveChartCtrl.cs
@@ -1,5 +1,7 @@
-锘縰sing DevExpress.Utils;
+锘縰sing DevExpress.CodeParser;
+using DevExpress.Utils;
 using DevExpress.XtraCharts;
+using System.Linq;
 using Yw.WinFrmUI.Phart;
 
 namespace PBS.WinFrmUI.Hydro
@@ -156,20 +158,39 @@
             foreach (var item in waterPointGroup)
             {
                 var x = item.Key;
-                var yList = item.Select(x => x.EndPressure).OrderBy(x => x).ToList();
+                var list = item.Select(t => new Yw.Geometry.Point2d(x, t.EndPressure)).ToList();
 
-                var yUpper = CalculatePercentile(yList, 0.95);
-                var yLower = CalculatePercentile(yList, 0.05);
-                var yNumList = yList.Where(x => x >= yLower && x <= yUpper);
-                if (yNumList == null || !yNumList.Any())
+                //var yList = item.Select(x => x.EndPressure).OrderBy(x => x).ToList();
+
+                //var yUpper = CalculatePercentile(yList, 0.95);
+                //var yLower = CalculatePercentile(yList, 0.05);
+                //var yNumList = yList.Where(x => x >= yLower && x <= yUpper);
+                //if (yNumList == null || !yNumList.Any())
+                //{
+                //    continue;
+                //}
+                //var yAverage = yNumList.Where(x => x >= yLower && x <= yUpper).Average();
+
+                //upperPressurePtList.Add(new Yw.Geometry.Point2d(x, yUpper));
+                //lowerPressurePtList.Add(new Yw.Geometry.Point2d(x, yLower));
+                //averagePressurePtList.Add(new Yw.Geometry.Point2d(x, yAverage));
+
+                var fList = DynamicThresholdProcessor.FilterWithDynamicSigma(list);
+               // var fList = FilterByStdDev(list);
+                if (fList == null || !fList.Any())
                 {
                     continue;
                 }
-                var yAverage = yNumList.Where(x => x >= yLower && x <= yUpper).Average();
+
+                var yUpper = fList.Max(x => x.Y);
+                var yLower = fList.Min(x => x.Y);
+                var yAverage = fList.Average(x => x.Y);
 
                 upperPressurePtList.Add(new Yw.Geometry.Point2d(x, yUpper));
                 lowerPressurePtList.Add(new Yw.Geometry.Point2d(x, yLower));
                 averagePressurePtList.Add(new Yw.Geometry.Point2d(x, yAverage));
+            
+
             }
 
             if (averagePressurePtList.Count > 4)
@@ -226,6 +247,48 @@
             return sortedData[lower] * (1 - fraction) + sortedData[upper] * fraction;
         }
 
+
+        public List<Yw.Geometry.Point2d> FilterByStdDev(List<Yw.Geometry.Point2d> group)
+        {
+
+            var filteredData = new List<Yw.Geometry.Point2d>();
+
+
+            // 灏忔牱鏈暟鎹笉澶勭悊锛堥槇鍊艰涓�10锛�
+            if (group.Count() < 3)
+            {
+                filteredData.AddRange(group);
+                return default;
+            }
+
+            // 璁$畻缁熻閲�
+            var pressures = group.Select(p => p.Y).ToList();
+            double mean = pressures.Average();
+            double stdDev = CalculateSampleStdDev(pressures); // 鏍锋湰鏍囧噯宸�
+
+            // 璁剧疆3蟽杈圭晫[1,3,4](@ref)
+            double lowerBound = mean - 3 * stdDev;
+            double upperBound = mean + 3 * stdDev;
+
+            // 杩囨护寮傚父鍊�
+            filteredData.AddRange(
+                group.Where(p => p.Y >= lowerBound && p.Y <= upperBound)
+            );
+
+
+            return filteredData;
+        }
+
+        // 鏍锋湰鏍囧噯宸绠楋紙n-1锛塠7,8](@ref)
+        private double CalculateSampleStdDev(List<double> values)
+        {
+            if (values.Count < 2) return 0;
+
+            double mean = values.Average();
+            double sumSquares = values.Sum(v => Math.Pow(v - mean, 2));
+            return Math.Sqrt(sumSquares / (values.Count - 1));
+        }
+
         #region Set Axis
 
 

--
Gitblit v1.9.3