Shuxia Ning
2024-12-19 b0c978129ba55cf81e8470b6c9326745a5dbc7d1
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Eventech.Model
{
    public enum eCurveDrawType
    {
        Through=0,
        Fit=1
    }
    //既可以用穿过点也可以用拟合点产生曲线
    public class CombineCurve :Yw.Pump.CurveEqualE, ICloneable
    {
        #region 构造函数
        public CombineCurve():base()
        {
 
        }
        //拟合的方法
        public CombineCurve(CurveExpressExPara curvePara, int pointNum)
        {
            this.CurveType = eCurveDrawType.Fit;
            this.CurvePara = curvePara.CurvePara;
            this.FitCurvePara = curvePara.Clone();
            this.PointInfo = this.FitCurvePara.ToPoints(pointNum);
        }
        //拟合的方法
        public CombineCurve(CurveExpressExPara curvePara, List<Eventech.Model.FeatPoint> pointPara)
        {
            this.CurveType = eCurveDrawType.Fit;
            this.CurvePara = curvePara.CurvePara;
            this.FitCurvePara = curvePara.Clone();             
            this.PointInfo = new Eventech.Model.FeatPointList(pointPara);
        }
        public CombineCurve TransUnitQ(Eventech.Model.UnitQ thisUnit, Eventech.Model.UnitQ toUnit)
        {
            CombineCurve trnCurve = new CombineCurve(this);
            if (this.FitCurvePara != null)
            {
                trnCurve.FitCurvePara = this.FitCurvePara.TransUnitQ(thisUnit, toUnit);
            }
            if (this.PointInfo != null)
            {
                trnCurve.PointInfo = new FeatPointList();
                foreach (var pt in this.PointInfo)
                {
                    trnCurve.PointInfo.Add(
                        new FeatPoint(Eventech.Common.UnitQHelper.Convert(thisUnit, toUnit, pt.X),
                        pt.Y));
                }
            }
 
            return trnCurve;
        }
        //通过点
        public CombineCurve(ThroughParaCurve curvePara):base(curvePara)
        {
            this.CurveType = eCurveDrawType.Through;
            this.FitCurvePara = null;
        }
        public CombineCurve(double para, List<Eventech.Model.FeatPoint> curveInfo, bool isClosed , float tension):base(para,curveInfo,isClosed,tension)
        {
            this.CurveType = eCurveDrawType.Through;
            this.FitCurvePara = null;
        }
 
        //从数据库
        public CombineCurve(string rhs, int pointNum = 12)
        {
            if (string.IsNullOrEmpty(rhs))
            {
                isNull = true;
                return;
            }
            string[] strExpresses = rhs.Split(new string[] { "," }, StringSplitOptions.None);
            this.CurveType = (eCurveDrawType)Convert.ToInt32(strExpresses[0]);
            this.CurvePara = Convert.ToDouble(strExpresses[1]);
            if (this.CurveType == eCurveDrawType.Fit)
            {
                this.CurveType = eCurveDrawType.Fit;
                this.FitCurvePara = new Eventech.Model.CurveExpress(string.Join(",", strExpresses, 2, strExpresses.Count() - 2));
                this.PointInfo = this.FitCurvePara.ToPoints(pointNum); 
            }
            else
            {
                this.FitCurvePara = null;
                this.CurveType = eCurveDrawType.Through;
                ThroughCurve throughPara = new ThroughCurve(string.Join(",", strExpresses, 2, strExpresses.Count() - 2));
                this.DispTension = throughPara.DispTension;
                this.IsClosed = throughPara.IsClosed;
                this.PointInfo = throughPara.PointInfo;
                this.FitCurvePara = new Eventech.Model.CurveExpress(throughPara.PointInfo, Eventech.Model.eCurveFitType.ThroughPoint);
            }
        } 
        //
        public CombineCurve(CombineCurve rhs)
        {
            this.CurveType = rhs.CurveType;
            this.CurvePara = rhs.CurvePara;
            if (this.CurveType == eCurveDrawType.Fit)
            {
                if (rhs.FitCurvePara != null)
                this.FitCurvePara = rhs.FitCurvePara.Clone();
                if (rhs.PointInfo != null)
                this.PointInfo = rhs.PointInfo.Clone();
            }
            else
            {
                if (rhs.FitCurvePara != null)
                this.FitCurvePara = rhs.FitCurvePara.Clone();
                this.DispTension = rhs.DispTension;
                this.IsClosed = rhs.IsClosed;
                if (rhs.PointInfo != null)
                this.PointInfo = rhs.PointInfo.Clone();
            }
        }
        //
        public CombineCurve(CombineCurve2 rhs)
        {
            this.CurveType = rhs.CurveType;
            this.CurvePara = rhs.CurvePara;
            if (this.CurveType == eCurveDrawType.Fit)
            {
                this.FitCurvePara = new CurveExpress(rhs.CurveInfo);
                if (rhs.PointInfo != null)
                this.PointInfo = rhs.PointInfo.Clone();
            }
            else
            {
                if (rhs.CurveInfo != null)
                    this.FitCurvePara = new CurveExpress(rhs.CurveInfo, Eventech.Model.eCurveFitType.ThroughPoint);
                this.DispTension = rhs.DispTension;
                this.IsClosed = rhs.IsClosed;
                if (rhs.PointInfo != null)
                    this.PointInfo = rhs.PointInfo.Clone();
            }
        }
        #endregion
 
        //50HZ->60HZ
        public CombineCurve From50to60HZ( )
        {
            return SimuBySpeed(1.2);
        }
        //相似换算(speed_ratio = 新的转速 除以 老的转速)
        public CombineCurve SimuBySpeed(double speed_ratio)
        {
            CombineCurve c60 = new CombineCurve(this);
            c60.CurvePara = this.CurvePara;
            c60.CurveType = this.CurveType;
            c60.DispTension = this.DispTension;
            if (this.FitCurvePara != null)
                c60.FitCurvePara = this.FitCurvePara.SimuBySpeed(Eventech.Model.eFeatCurveType.QH, speed_ratio);
 
            c60.IsClosed = this.IsClosed;
            if (this.PointInfo != null)
            {
                Eventech.Common.SimuSpeedStdCalcer calc = new Common.SimuSpeedStdCalcer();
 
                List<Eventech.Model.FeatPoint> pointInfo60 = new List<FeatPoint>();
                for (int i = 0; i < this.PointInfo.Count; i++)
                {
                    double q50 = this.PointInfo[i].X;
                    double q60 =  q50 * speed_ratio;
                    double Y50 = this.PointInfo[i].Y;
                    double h60 = Y50 * speed_ratio * speed_ratio;
                    pointInfo60.Add(new FeatPoint() { X = q60, Y = h60 });
                }
 
                c60.PointInfo = new FeatPointList(pointInfo60);
            }
 
            return c60;
        }
 
 
        private eCurveDrawType _curveType =  eCurveDrawType.Fit;
        public eCurveDrawType CurveType { get { return _curveType; } set { _curveType = value; } }
 
 
        private CurveExpress _fitCurvePara = null;
        public CurveExpress FitCurvePara { get { return _fitCurvePara; } set { _fitCurvePara = value; } }
 
 
 
        #region Clone
        object ICloneable.Clone()
        {
            return Clone();
        }
 
        public new  CombineCurve Clone()
        {
            return new CombineCurve(this);
        }
        #endregion
 
        public void ResetCurve(CurveExpress CurveExpress, int pointNumber)
        {
            var points = Eventech.Common.FitCurveHelper.GetFitPoints(CurveExpress, pointNumber);
            _pointInfo.ResetCurve(points);
 
            if (_curveType == eCurveDrawType.Fit)
            {
                _fitCurvePara.ResetCurve(points, CurveExpress.CurveFitType,false);
            }
        }
 
        public void ResetCurve(List<Eventech.Model.FeatPoint> points)
        {
            _pointInfo.ResetCurve(points);
 
            if (_curveType == eCurveDrawType.Fit)
            {
                _fitCurvePara.ResetCurve(points, 3, false);
            }
        }
        public void ResetCurve()
        {
            if (_curveType == eCurveDrawType.Fit)
            {
                _fitCurvePara.ResetCurve(_pointInfo, 3, false);
            }
        }
        public Eventech.Model.FeatPointList ToPoints(int PointNum)
        {
            if (this.isNull)
                return null;
            if (_curveType == eCurveDrawType.Fit)
                return Eventech.Common.FitCurveHelper.GetFitPoints(_fitCurvePara, PointNum);
            else
                return _pointInfo.Clone();
        }
 
        public void ReClacPoint(int PointNum)
        {
            if (this.isNull)
                return ;
            if (_curveType == eCurveDrawType.Fit)
                _pointInfo = Eventech.Common.FitCurveHelper.GetFitPoints(_fitCurvePara, PointNum);
        }
 
        #region ToDsString
        public new string ToDsString()
        {
            return ToDsString(this);
        }
 
        public static string ToDsString(CombineCurve curve)
        {
            if (curve == null)
                return null;
            if (curve.IsNull)
                return null;
 
 
            if (curve.CurveType == eCurveDrawType.Fit)
                return string.Format("{0},{1},{2}", (int)curve.CurveType, curve.CurvePara, curve.FitCurvePara.ToDsString());
            else
                return string.Format("{0},{1},{2}", (int)curve.CurveType, curve.CurvePara, (curve as ThroughCurve).ToDsString());
        }
 
        public override string ToString()
        {
            return this.CurvePara.ToString();
        } 
        #endregion
 
 
        #region 曲线标准化
        //轴流泵QH曲线(单条线,流量从小到大排序)
        public static void Standard4FeatCurveQH(ref Eventech.Model.CombineCurve curve)
        {
            if (curve == null)
                return;
            if (curve.PointInfo == null || curve.PointInfo.Count == 0)
                return;
            if (curve.CurveType == eCurveDrawType.Fit)
            {
                curve.PointInfo = curve.ToPoints(6);//只要保证流量从小到大即可
                return;//拟合的方法不需要排序
            }
 
            //保证流量值从小到大
            if (curve.PointInfo.First().X > curve.PointInfo.Last().X)
            {
                curve.PointInfo.Reverse();
            }
        }
 
        //等效线曲线
        //C型圈:保证曲线Y值从大到小 ,开始Y值大,结束Y值小
        //一型圈:保证流量值从小到大
        public static void Standard4EqualCurveE(ref Eventech.Model.CombineCurve curve)
        {
            if (curve == null)
                return;
            if (curve.PointInfo == null || curve.PointInfo.Count == 0)
                return;
            if (curve.CurveType == eCurveDrawType.Fit)
            {
                curve.PointInfo = curve.ToPoints(6);//只要保证流量从小到大即可
                return;//拟合的方法不需要排序
            }
            if (curve.IsClosed)
                return;//封闭就保证原始状态即可
 
            //判断各种情况
            Eventech.Model.FeatPointList point = curve.PointInfo;
            if (Eventech.Common.EqualParaCurveEListHelper.IsShapeC(point))
            {//C型圈:保证曲线X值从小到大, 即开始X值小, 结束X值大
                if (point.First().X > point.Last().X)
                {
                    point.Reverse();
                }
            }
            else
            { //保证Y值从大到小(即从上到下)
                if (point.First().Y < point.Last().Y)
                {
                    point.Reverse();
                }
            }
 
            curve.PointInfo = point;
        } 
        #endregion
 
        public static CombineCurve toM3H(UnitQ unit, CombineCurve curvePara)
        {
            if (unit == UnitQ.M3H)
                return curvePara;
 
            if (curvePara == null)
                return null;
            if (curvePara.PointInfo == null)
                return curvePara;
 
            CombineCurve newCurve = curvePara.Clone();
            newCurve.PointInfo = new Eventech.Model.FeatPointList();
            for (int i = 0; i < curvePara.PointInfo.Count; i++)
            {
                Eventech.Model.FeatPoint pt = curvePara.PointInfo[i];
                newCurve.PointInfo.Add(new Eventech.Model.FeatPoint(Eventech.Common.UnitQHelper.toM3H(unit, pt.X), pt.Y));
            }
 
            return newCurve;
        }
 
        public static CombineCurve toLS(UnitQ unit, CombineCurve curvePara)
        {
            if (unit == UnitQ.LS)
                return curvePara;
 
            if (curvePara == null)
                return null;
            if (curvePara.PointInfo == null)
                return curvePara;
 
            CombineCurve newCurve = curvePara.Clone();
            newCurve.PointInfo = new Eventech.Model.FeatPointList();
            for (int i = 0; i < curvePara.PointInfo.Count; i++)
            {
                Eventech.Model.FeatPoint pt = curvePara.PointInfo[i];
                newCurve.PointInfo.Add(new Eventech.Model.FeatPoint(Eventech.Common.UnitQHelper.toLS(unit, pt.X), pt.Y));
            }
 
            return newCurve;
        }
 
 
        public new  class Comparer : IComparer<CombineCurve>
        {
            public Comparer()
            {
            }
 
            #region IComparer<Eventech.Model.FeatPoint> 成员
            private double ignoreDis = 0.001;
            int IComparer<CombineCurve>.Compare(CombineCurve obj1, CombineCurve obj2)
            {
                if (Math.Abs(obj1.CurvePara - obj2.CurvePara) < ignoreDis)
                {//参数一样 就比较Y的平均值
                    double y1_arv = (from x in obj1.PointInfo select x.Y).Average();
                    double y2_arv = (from x in obj2.PointInfo select x.Y).Average();
                    if (Math.Abs(y1_arv - y2_arv) < 0.01)
                        return 0;
                    else if (y1_arv > y2_arv)
                        return 1;
                    else
                        return -1;
                }
                else if (obj1.CurvePara > obj2.CurvePara)
                {
                    return 1;
                }
                else
                {
                    return -1;
                }
            }
 
            #endregion
        }
 
        //比较相同:主要用与LIST的Contains方法和Distinct
        public new class EqualComparer : IEqualityComparer<CombineCurve>
        {
            private double ignoreDis = 0.001;
            public EqualComparer()
            {
                ignoreDis = 0.001;
            }
            public EqualComparer(double dis)
            {
                ignoreDis = dis;
            }
 
            public bool Equals(CombineCurve lhs, CombineCurve rhs)
            {
                if (Math.Abs(lhs.CurvePara - rhs.CurvePara) < ignoreDis)
                    return true;
                else
                    return false;
            }
 
            public int GetHashCode(CombineCurve obj)
            {
                //return obj.X.GetHashCode() + obj.Y.GetHashCode(); 
                return 0;
            }
        }
 
    
    }
 
 
}