ningshuxia
2025-04-16 a67da735b33be01b24845ce03ae7551cf55ddbbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
using IStation.Model;
using System.Data;
using System.Text;
 
namespace IStation.Test
{
    internal class Program
    {
        // 过滤无效数据
        // 1输模型修正
        // 2输数据修正
        // 修正组合偏差
        static void Main(string[] args)
        {
            //Station1Helper.Start();  //1 数据修正
            //Station2Helper.Start();  //2 模型修正
            // 3  python修正
            //Completion();            //4 修正后相似换算修正
 
            //StationCombineHelper.Start(1);// 5 组合偏差修正
            //StationCombineHelper.Start(2);// 5 组合偏差修正
 
            StationCombineHelper.Start(3);// 6 分析泵频谱系数
            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);
                }
            }
 
        }
 
 
        //static void Main(string[] args)
        //{
        //    var splineList = new List<CurvePoint>();
        //    var measuredList = new List<CurvePoint>();
 
        //    var path = AppDomain.CurrentDomain.BaseDirectory;
        //    var lienPaht = path + @"\pumpcsv\23_44_old_curve.csv";
        //    var measuredPath = path + @"\pumpcsv\23_44.csv";
 
        //    using (var fs = new FileStream(lienPaht, 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]);
        //            splineList.Add(new CurvePoint(x, y));
        //        }
        //    }
 
        //    using (var fs = new FileStream(measuredPath, 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[4]);
        //            var y = double.Parse(strList[5]);
        //            measuredList.Add(new CurvePoint(x, y));
        //        }
        //    }
 
 
        //    // 样条曲线处理
        //    double[] splineX = splineList.Select(x => x.X).ToArray();
        //    double[] splineY = splineList.Select(x => x.Y).ToArray();
 
        //    // 实测数据处理
        //    double[] measuredXAll = measuredList.Select(x => x.X).ToArray();
        //    double[] measuredYAll = measuredList.Select(x => x.Y).ToArray();
 
 
 
        //    var helper = new PumpCurveDataFusionCorrectorHelper();
        //    (double[] mergedX, double[] mergedY, double[] optimizedX, double[] optimizedY) = helper.Corrent(splineX, splineY, measuredXAll, measuredYAll);
 
        //    var pt_list = new List<CurvePoint>();
        //    for (int i = 0; i < optimizedX.Length; i++)
        //    {
        //        var x = optimizedX[i];
        //        var y = optimizedY[i];
        //        pt_list.Add(new CurvePoint(x, y));
        //    }
        //    var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pumpcsv");
        //    CsvHelper.ExportToCsv(pt_list, Path.Combine(fullPath, $"23_44_update_curve.csv"));
 
        //    Console.WriteLine("ok");
        //    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;
        }
    }
 
 
 
 
}