using IStation.Model; using System; using System.Collections.Generic; using System.Linq; namespace IStation.WinFrmUI.Curve { /// /// 离心泵拟合曲线辅助类 /// public class LxpFeatCurveHelper { /// /// 计算效率 对其功率 /// public static List CalculateE_AlignPointP(List pointQH, List pointQP, double midu, bool isFromZero) { return CalculateE_AlignPointP(eCurveFitType.CubicCurve, eCurveFitType.CubicCurve, pointQH, pointQP, midu, isFromZero); } /// /// 计算效率 对其功率 /// public static List CalculateE_AlignPointP(eCurveFitType CurveFitTypeQH, eCurveFitType CurveFitTypeQP, List pointQH, List pointQP, double midu, bool isFromZero) { if (pointQH == null || pointQH.Count < 3) { return null; } if (pointQP == null || pointQP.Count < 3) { return null; } List list = new List(); if (IsEqualValueX(pointQH, pointQP)) { for (int i = 0; i < pointQP.Count; i++) { double x = pointQP[i].X; double y = pointQP[i].Y; double y2 = pointQH[i].Y; double y3 = Model.CurveCalcuHelper.CalculateE(x, y2, y, midu); list.Add(new CurvePoint(x, y3)); } } else { FitCurveHelper fitCurveHelper = new FitCurveHelper(pointQP, CurveFitTypeQP); FitCurveHelper fitCurveHelper2 = new FitCurveHelper(pointQH, CurveFitTypeQH); for (int j = 0; j < pointQP.Count; j++) { double x2 = pointQP[j].X; double fitPointY = fitCurveHelper.GetFitPointY(x2); double fitPointY2 = fitCurveHelper2.GetFitPointY(x2); double y4 = Model.CurveCalcuHelper.CalculateE(x2, fitPointY2, fitPointY, midu); list.Add(new Model.CurvePoint(x2, y4)); } } if (isFromZero) { list[0] = new CurvePoint(0, 0); } return list; } /// /// 计算效率 对其效率 /// public static List CalculateP_AlignPointE(eCurveFitType CurveFitTypeQH, eCurveFitType CurveFitTypeQE, List pointQH, List pointQE, double midu, double ref_zero_power, bool isFromZero) { if (pointQH == null || pointQH.Count < 3) { return null; } if (pointQE == null || pointQE.Count < 3) { return null; } List list = new List(); if (IsEqualValueX(pointQH, pointQE)) { for (int i = 0; i < pointQE.Count(); i++) { double x = pointQE[i].X; double y = pointQE[i].Y; double y2 = pointQH[i].Y; if (!(y2 < 0.1) && !(y < 0.5)) { double num = Model.CurveCalcuHelper.CalculateP(x, y2, y, midu); num = ((num < 2.0) ? Math.Round(num, 3) : ((num < 30.0) ? Math.Round(num, 2) : ((!(num < 100.0)) ? Math.Round(num, 0) : Math.Round(num, 1)))); list.Add(new Model.CurvePoint(x, num)); } } } else { FitCurveHelper fitCurveHelper = new FitCurveHelper(pointQE, CurveFitTypeQE); FitCurveHelper fitCurveHelper2 = new FitCurveHelper(pointQH, CurveFitTypeQH); for (int j = 0; j < pointQE.Count(); j++) { if (j == pointQE.Count() - 2) { //测试代码 } double x2 = pointQE[j].X; double fitPointY = fitCurveHelper.GetFitPointY(x2); double fitPointY2 = fitCurveHelper2.GetFitPointY(x2); if (!(fitPointY2 < 0.09) && !(fitPointY < 0.5)) { double num2 = Model.CurveCalcuHelper.CalculateP(x2, fitPointY2, fitPointY, midu); num2 = ((num2 < 2.0) ? Math.Round(num2, 3) : ((num2 < 30.0) ? Math.Round(num2, 2) : ((!(num2 < 100.0)) ? Math.Round(num2, 0) : Math.Round(num2, 1)))); list.Add(new Model.CurvePoint(x2, num2)); } } } if (isFromZero) { if (list[0].X < 1.0) { if (ref_zero_power > 0.0) { list[0].X = 0.0; list[0].Y = ref_zero_power; } else { list.RemoveAt(0); var fitPoints = FitCurveHelper.GetFitPoints(list); if (fitPoints[0].Y >= fitPoints[1].Y) { fitPoints[0].Y = fitPoints[1].Y * 0.95; } double num3 = Model.CurveLineHelper.GetYbyX(fitPoints[0].X, fitPoints[0].Y, fitPoints[1].X, fitPoints[1].Y, 0.0); if (num3 < 0.001) { num3 = fitPoints[0].Y; } num3 = ((num3 < 2.0) ? Math.Round(num3, 3) : ((num3 < 30.0) ? Math.Round(num3, 2) : ((!(num3 < 100.0)) ? Math.Round(num3, 0) : Math.Round(num3, 1)))); list.Insert(0, new Model.CurvePoint(0.0, num3)); } } else if (ref_zero_power > 0.0) { list.Insert(0, new Model.CurvePoint(0.0, ref_zero_power)); } else { var fitPoints2 = FitCurveHelper.GetFitPoints(list); if (fitPoints2[0].Y >= fitPoints2[1].Y) { fitPoints2[0].Y = fitPoints2[1].Y * 0.95; } double num4 = Model.CurveLineHelper.GetYbyX(fitPoints2[0].X, fitPoints2[0].Y, fitPoints2[1].X, fitPoints2[1].Y, 0.0); if (num4 < 0.001) { num4 = fitPoints2[0].Y; } num4 = ((num4 < 2.0) ? Math.Round(num4, 3) : ((num4 < 30.0) ? Math.Round(num4, 2) : ((!(num4 < 100.0)) ? Math.Round(num4, 0) : Math.Round(num4, 1)))); list.Insert(0, new Model.CurvePoint(0.0, num4)); } } return list; } /// /// 计算效率 对其效率 /// public static List CalculateP_AlignPointE(List pointQH, List pointQE, double midu, double ref_zero_power, bool isFromZero) { if (pointQH == null || pointQH.Count < 3) { return null; } if (pointQE == null || pointQE.Count < 3) { return null; } List list = new List(); if (IsEqualValueX(pointQH, pointQE)) { for (int i = 0; i < pointQE.Count(); i++) { double x = pointQE[i].X; double y = pointQE[i].Y; double y2 = pointQH[i].Y; if (!(y2 < 0.1) && !(y < 0.5)) { double num = Model.CurveCalcuHelper.CalculateP(x, y2, y, midu); num = ((num < 2.0) ? Math.Round(num, 3) : ((num < 30.0) ? Math.Round(num, 2) : ((!(num < 100.0)) ? Math.Round(num, 0) : Math.Round(num, 1)))); list.Add(new Model.CurvePoint(x, num)); } } } else { FitCurveHelper fitCurveHelper = new FitCurveHelper(pointQE); FitCurveHelper fitCurveHelper2 = new FitCurveHelper(pointQH); for (int j = 0; j < pointQE.Count(); j++) { double x2 = pointQE[j].X; double fitPointY = fitCurveHelper.GetFitPointY(x2); double fitPointY2 = fitCurveHelper2.GetFitPointY(x2); if (!(fitPointY2 < 0.1) && !(fitPointY < 0.5)) { double num2 = Model.CurveCalcuHelper.CalculateP(x2, fitPointY2, fitPointY, midu); num2 = ((num2 < 2.0) ? Math.Round(num2, 3) : ((num2 < 30.0) ? Math.Round(num2, 2) : ((!(num2 < 100.0)) ? Math.Round(num2, 0) : Math.Round(num2, 1)))); list.Add(new Model.CurvePoint(x2, num2)); } } } if (isFromZero) { if (list[0].X < 1.0) { if (ref_zero_power > 0.0) { list[0].X = 0.0; list[0].Y = ref_zero_power; } else { list.RemoveAt(0); var fitPoints = FitCurveHelper.GetFitPoints(list); if (fitPoints[0].Y >= fitPoints[1].Y) { fitPoints[0].Y = fitPoints[1].Y * 0.95; } double num3 = Model.CurveLineHelper.GetYbyX(fitPoints[0].X, fitPoints[0].Y, fitPoints[1].X, fitPoints[1].Y, 0.0); if (num3 < 0.001) { num3 = fitPoints[0].Y; } num3 = ((num3 < 2.0) ? Math.Round(num3, 3) : ((num3 < 30.0) ? Math.Round(num3, 2) : ((!(num3 < 100.0)) ? Math.Round(num3, 0) : Math.Round(num3, 1)))); list.Insert(0, new Model.CurvePoint(0.0, num3)); } } else if (ref_zero_power > 0.0) { list.Insert(0, new Model.CurvePoint(0.0, ref_zero_power)); } else { var fitPoints2 = FitCurveHelper.GetFitPoints(list); if (fitPoints2[0].Y >= fitPoints2[1].Y) { fitPoints2[0].Y = fitPoints2[1].Y * 0.95; } double num4 = Model.CurveLineHelper.GetYbyX(fitPoints2[0].X, fitPoints2[0].Y, fitPoints2[1].X, fitPoints2[1].Y, 0.0); if (num4 < 0.001) { num4 = fitPoints2[0].Y; } num4 = ((num4 < 2.0) ? Math.Round(num4, 3) : ((num4 < 30.0) ? Math.Round(num4, 2) : ((!(num4 < 100.0)) ? Math.Round(num4, 0) : Math.Round(num4, 1)))); list.Insert(0, new Model.CurvePoint(0.0, num4)); } } return list; } /// /// 是否完全相同 /// public static bool IsEqualValueX(List point1, List point2) { if (point1 == null || point1.Count() == 0) { if (point2 == null || point2.Count() == 0) { return true; } return false; } if (point2 == null || point2.Count() == 0) { if (point1 == null || point1.Count() == 0) { return true; } return false; } if (point1.Count != point2.Count) { return false; } for (int i = 0; i < point1.Count; i++) { if (Math.Abs(point1[i].X - point2[i].X) > 0.001) { return false; } } return true; } } }