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
using IStation.Model;
using MathNet.Numerics;
using MathNet.Numerics.Interpolation;
using MathNet.Numerics.LinearRegression;
using MathNet.Numerics.Statistics;
using NPOI.HPSF;
using System.Data;
using System.Text;
namespace IStation.Test
{
    internal class Program
    {
        static string _dataName = ".csv";
 
        static string _oldCurveurveName = "_old_curve.csv";
        static string _newCurveName = "_update_curve.csv";
        static void Main(string[] args)
        {
            var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pumpcsv");
            var list = GetFileInfoList(fullPath);
            foreach (var item in list)
            { 
                var key = item.Key;
                var dataFile = item.DataFile;
                var oldCurveFile = item.OldCurveFile;
                var updateCurveFile = Path.Combine(fullPath, $"{key}{_newCurveName}");
         
                  
                var splineList = new List<CurvePoint>();
                var dataList = new List<CurvePoint>();
                using (var fs = new FileStream(oldCurveFile, 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(dataFile, 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]);
                        dataList.Add(new CurvePoint(x, y));
                    }
                }
 
 
                var splineX = splineList.Select(x => x.X).ToArray();
                var splineY = splineList.Select(x => x.Y).ToArray();
                dataList = dataList.OrderBy(x => x.X).ToList();
                var dataXAll = dataList.Select(x => x.X).ToArray();
                var dataYAll = dataList.Select(x => x.Y).ToArray();
 
                var dataCount = dataXAll.Length;
                if (dataCount < 20)
                {
                    Console.WriteLine($"{key} Count:{dataCount} <20 skip");
                }
 
 
                var helper = new PumpCurveDataFusionCorrectorHelper2(); //PumpCurveDataFusionCorrectorHelper2DeepSeek
                (double[] mergedX, double[] mergedY, double[] optimizedX, double[] optimizedY) = helper.Corrent(splineX, splineY, dataXAll, dataYAll);
 
                var optimizedCount = optimizedX?.Length ?? 0;
                Console.WriteLine($"{key} Count:{dataCount} OptimizedCount:{optimizedCount}");
                if (optimizedCount < 1)
                {
                    Console.WriteLine($"{key}  skip");
                    continue;
                }
                var optimizedPtList = new List<CurvePoint>();
                for (int i = 0; i < optimizedCount; i++)
                {
                    var x = optimizedX[i];
                    var y = optimizedY[i];
                    optimizedPtList.Add(new CurvePoint(x, y));
                }
 
                CsvHelper.ExportToCsv(optimizedPtList, updateCurveFile);
 
            }
 
 
 
 
            Console.WriteLine("ok");
            Console.ReadKey();
        } 
 
 
        static List<(string Key, string DataFile, string OldCurveFile)> GetFileInfoList(string folder)
        {
            if (!Directory.Exists(folder))
                return default;
            var files = Directory.GetFiles(folder);
            if (files == null || files.Count() < 1)
                return default;
 
            var list = new List<(string Key, string dataFile, string oldCurveFile)>(files.Count());
            var group = files.GroupBy(x => Path.GetFileName(x).Substring(0, 5));
            foreach (var item in group)
            {
                var name = item.Key;
                var dataFile = $"{folder}\\{name}{_dataName}";
                var oldCurveFile = $"{folder}\\{name}{_oldCurveurveName}";
                list.Add((item.Key, dataFile, oldCurveFile));
            }
 
            return list;
        }
 
    }
}