From 8c68ab4be4bff7981e745cc2b41c7bba5257a2d3 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期三, 16 四月 2025 20:37:38 +0800
Subject: [PATCH] 流量偏差 辅助类

---
 02-desktop/Desktop/IStation.Test/Program.cs |  150 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 148 insertions(+), 2 deletions(-)

diff --git a/02-desktop/Desktop/IStation.Test/Program.cs b/02-desktop/Desktop/IStation.Test/Program.cs
index ced42cd..f707e4e 100644
--- a/02-desktop/Desktop/IStation.Test/Program.cs
+++ b/02-desktop/Desktop/IStation.Test/Program.cs
@@ -1,6 +1,7 @@
 锘縰sing IStation.Model;
 using System.Data;
 using System.Text;
+
 namespace IStation.Test
 {
     internal class Program
@@ -11,11 +12,130 @@
         // 淇缁勫悎鍋忓樊
         static void Main(string[] args)
         {
-            Station2Helper.Start();
-            Console.WriteLine();
+            //Station1Helper.Start();  //1 鏁版嵁淇
+            //Station2Helper.Start();  //2 妯″瀷淇
+            // 3  python淇 ,鐩墠鏈変簺鏁版嵁闂杩橀渶瑕佽В鍐�
+            //Completion();            //4 淇鍚庣浉浼兼崲绠椾慨姝�
+
+            //StationCombineHelper.Start(1);// 5 缁勫悎鍋忓樊淇
+            //StationCombineHelper.Start(2);// 5 缁勫悎鍋忓樊淇
+
+            // 6 鍒嗘瀽娉甸璋辩郴鏁�
+            // 7 
+           // Station2TotalFlowDiffHelper.Start();// 8 琛ュ叏娴侀噺鍋忓樊 + python
+
             Console.WriteLine();
             Console.WriteLine("ok");
             Console.ReadKey();
+
+        }
+
+
+        public static void Completion()
+        {
+            var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pumpcsv");
+
+            var fileNameList = Directory.GetFiles(fullPath).Select(x => Path.GetFileNameWithoutExtension(x)).ToList();
+            fileNameList = fileNameList.Where(x => x.Contains("update_curve")).ToList();
+            if (fileNameList == null || fileNameList.Count() < 1)
+                return; 
+            var deleteList = fileNameList.Where(x => x.Contains("similar") || x.Contains("def")).ToList();
+            deleteList?.ForEach(x => File.Delete(x));
+
+            var flagCurveDict = GetFlagCurveDict();
+
+            fileNameList.RemoveAll(x => x.Contains("similar") ||x.Contains("def"));
+            var group = fileNameList.Where(x => x.Contains("update_curve")).GroupBy(x => x.Substring(0, 2));
+            foreach (var flagItem in group)
+            {
+                if (!int.TryParse(flagItem.Key, out int flag))
+                    continue;
+             
+                var files = flagItem.OrderBy(x => x).ToList();
+                var fileInfoList = new List<(int Hz, string FileName)>();
+                foreach (var fileName in files)
+                {
+                    var hz = fileName.Substring(3, 2);
+                    if (!int.TryParse(hz, out int hzInt))
+                        continue;
+                    if (hzInt > 50)
+                    {
+                        continue;
+                    }
+                    fileInfoList.Add((hzInt, fileName));
+                }
+                if (fileInfoList.Count == 1 && fileInfoList[0].Hz==50)
+                {
+                    continue;
+                }
+                for (int i = 25; i <= 50; i++)
+                {
+                    var maxHz = fileInfoList.Max(x => x.Hz);
+                    var curvePointList = new List<CurvePoint>();
+                    var fileName = string.Empty;
+                    var currentHz = i;
+                    var newFileName = "";
+                    if (fileInfoList.Exists(x => x.Hz == i))
+                    {
+                        continue;
+                    }
+                    else if (currentHz == 50)
+                    {
+                        var curve = flagCurveDict[flag];
+                        curvePointList = curve.GetFitPoints(100).ToList();
+                        newFileName = $"{flagItem.Key}_{50}_update_curve_def.csv";
+                    }
+                    else if (currentHz > maxHz)
+                    {
+                        var curve = flagCurveDict[flag];
+                        var similar_qh = Model.CurveCalcuHelper.CalculateSimilarQH(curve, 50, currentHz);
+                        if (similar_qh == null)
+                        {
+                            continue;
+                        }
+                        curvePointList = similar_qh.GetFitPoints(100).ToList();
+                        newFileName = $"{flagItem.Key}_{currentHz}_update_curve_similar_def.csv";
+                    }
+                    else
+                    {
+                        var (Hz, FileName) = fileInfoList.FirstOrDefault(x => x.Hz > i);
+                        if (Hz < 1)
+                            continue;
+
+                        var updateCurvePtList = new List<CurvePoint>();
+                        var updateCurveFile = Path.Combine(fullPath, $"{flagItem.Key}_{Hz}_update_curve.csv");
+                        using (var fs = new FileStream(updateCurveFile, FileMode.Open, FileAccess.Read))
+                        using (var sr = new StreamReader(fs, Encoding.UTF8))
+                        {
+                            var strLine = string.Empty;
+                            sr.ReadLine();
+                            while (!string.IsNullOrEmpty(strLine = sr.ReadLine()))
+                            {
+                                var strList = strLine.Split(',');
+                                var x = double.Parse(strList[0]);
+                                var y = double.Parse(strList[1]);
+                                updateCurvePtList.Add(new CurvePoint(x, y));
+                            }
+                        }
+
+                        var similar_qh = Model.CurveCalcuHelper.CalculateSimilarQH(new CurveExpress(updateCurvePtList), Hz, currentHz);
+                        if (similar_qh == null)
+                        {
+                            continue;
+                        }
+                        curvePointList = similar_qh.GetFitPoints(100).ToList();
+                        newFileName = $"{flagItem.Key}_{currentHz}_update_curve_similar_{Hz}.csv";
+                    }
+                    if (!curvePointList.Any())
+                    {
+                        continue;
+                    }
+                    var currentCurveFile = Path.Combine(fullPath, newFileName);
+                    CsvHelper.ExportToCsv(curvePointList, currentCurveFile);
+                    Console.WriteLine(newFileName);
+                }
+            }
+
         }
 
 
@@ -84,7 +204,33 @@
         //    Console.ReadKey();
         //}
 
+        private static Dictionary<int, IStation.Model.CurveExpress> GetFlagCurveDict()
+        {
+            var dict = new Dictionary<int, IStation.Model.CurveExpress>();
+            var bll_curve = new IStation.BLL.PumpCurve();
+            var station_list = new IStation.BLL.Station().GetAll();
+            foreach (var station in station_list)
+            {
+                var eq_list = new IStation.BLL.Equipment().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID);
+                if (eq_list == null || !eq_list.Any())
+                {
+                    continue;
+                }
 
+                foreach (var eq in eq_list)
+                {
+                    IStation.Model.CurveExpress qh = null;
+                    var curve_info = bll_curve.GetDefaultWorkingByPumpID(eq.ID)?.CurveInfo;
+                    if (curve_info != null)
+                    {
+                        qh = curve_info.CurveQH;
+                    }
+                    dict.Add(eq.SortCode, qh);
+                }
+            }
+
+            return dict;
+        }
     }
 
 

--
Gitblit v1.9.3