public void CalcInfo() { if (Data == null || Data.Length == 0) { foreach (var spec in TestSpecList) { spec.PassFail = null; } return; } foreach (var spec in TestSpecList) { #region foreach (var marker in spec.TestMarkerList) { if (marker is XYTestMarker) { var xyMarker = marker as XYTestMarker; xyMarker.MarkerResult.Clear(); switch (xyMarker.Type) { case XYTestMarkerTypeEnum.ABSMax: double yAbsMax = GeneFun.GetTwoArraryMax(Data, true); double xAbsMax = FreqList[0]; xyMarker.MarkerResult.Add(new XYData(xAbsMax, yAbsMax)); break; case XYTestMarkerTypeEnum.ABSMin: double yAbsMin = GeneFun.GetTwoArrayMin(Data, true); double xAbsMin = FreqList[0]; xyMarker.MarkerResult.Add(new XYData(xAbsMin, yAbsMin)); break; case XYTestMarkerTypeEnum.Max: double yMax = GeneFun.GetTwoArraryMax(Data, false); double xMax = FreqList[0]; xyMarker.MarkerResult.Add(new XYData(xMax, yMax)); break; case XYTestMarkerTypeEnum.Min: double yMin = GeneFun.GetTwoArrayMin(Data, false); double xMin = FreqList[0]; xyMarker.MarkerResult.Add(new XYData(xMin, yMin)); break; case XYTestMarkerTypeEnum.Peak: double y1Max = GeneFun.GetTwoArraryMax(Data, false); double y1Min = GeneFun.GetTwoArrayMin(Data, false); if (Math.Abs(y1Max) >= Math.Abs(y1Min)) { xyMarker.MarkerResult.Add(new XYData(FreqList[0], y1Max)); } else { xyMarker.MarkerResult.Add(new XYData(FreqList[0], y1Min)); } break; default: break; } } marker.JudgePassFail(); } #endregion #region List <bool> boolList = new List <bool>(); CalcEngine.CalcEngine ce = new CalcEngine.CalcEngine(); ce.Variables.Add("att", null); ce.Variables.Add("phase", null); ce.Variables.Add("freq", null); for (int i = 0; i < Data.GetLength(0); i++) { for (int j = 0; j < Data.GetLength(1); j++) { ce.Variables["att"] = StateList[i].Att; ce.Variables["phase"] = StateList[i].Phase; ce.Variables["freq"] = FreqList[j]; object highLimitStr; object lowLimitStr; if (string.IsNullOrWhiteSpace(spec.HighLimit)) { highLimitStr = null; } else { highLimitStr = ce.Evaluate(spec.HighLimit); } if (string.IsNullOrWhiteSpace(spec.LowLimit)) { lowLimitStr = null; } else { lowLimitStr = ce.Evaluate(spec.LowLimit); } double?highLimitValue = highLimitStr.ToNullDouble(); double?lowLimitValue = lowLimitStr.ToNullDouble(); bool passFail = GeneFun.IsPassFail(Data[i, j], highLimitValue, lowLimitValue); boolList.Add(passFail); } } spec.PassFail = GeneFun.NullBoolAndList(boolList); spec.PassFail = GeneFun.NullBoolAnd(GeneFun.NullBoolAndList(spec.TestMarkerList.Select(x => x.PassFail).ToList()), spec.PassFail); #endregion } PassFail = GeneFun.NullBoolAndList(TestSpecList.Select(x => x.PassFail).ToList()); }
//[System.Xml.Serialization.XmlIgnore] //public bool IsTest { get; set; } //[System.Xml.Serialization.XmlIgnore] //[Newtonsoft.Json.JsonIgnore] //public bool? PassFail { get; set; } //public string Unit { get; set; } public void CalcInfo() { if (ResultData == null || ResultData.Count == 0) { return; } for (int i = 0; i < ResultData.Count(); i++) { ResultData[i] = new XYData() { X = ResultData[i].X, Y = ResultData[i].Y + Compensation }; } foreach (var spec in TestSpecList) { foreach (var marker in spec.TestMarkerList) { #region if (marker is XYTestMarker) { var xyMarker = marker as XYTestMarker; xyMarker.MarkerResult.Clear(); switch (xyMarker.Type) { case XYTestMarkerTypeEnum.Normal: double[] lstXData = ResultData.Select(x => x.X).ToArray(); double[] lstYData = ResultData.Select(x => x.Y).ToArray(); double xData = xyMarker.Start; double yData = GeneFun.LinearInterp(lstXData, lstYData, xData); xyMarker.MarkerResult.Add(new XYData(xData, yData)); break; case XYTestMarkerTypeEnum.Max: double ymax = ResultData.Select(x => x.Y).Max(); double xmax = ResultData.Find(x => x.Y == ymax).X; xyMarker.MarkerResult.Add(new XYData(xmax, ymax)); break; case XYTestMarkerTypeEnum.Min: double ymin = ResultData.Select(x => x.Y).Min(); double xmin = ResultData.Find(x => x.Y == ymin).X; xyMarker.MarkerResult.Add(new XYData(xmin, ymin)); break; case XYTestMarkerTypeEnum.ABSMax: double yAbsmax = ResultData.Select(x => Math.Abs(x.Y)).Max(); double xAbsmax = ResultData.Find(x => Math.Abs(x.Y) == yAbsmax).X; xyMarker.MarkerResult.Add(new XYData(xAbsmax, yAbsmax)); break; case XYTestMarkerTypeEnum.ABSMin: double yAbsmin = ResultData.Select(x => Math.Abs(x.Y)).Min(); double xAbsmin = ResultData.Find(x => Math.Abs(x.Y) == yAbsmin).X; xyMarker.MarkerResult.Add(new XYData(xAbsmin, yAbsmin)); break; case XYTestMarkerTypeEnum.Peak: double y1Max = ResultData.Select(x => x.Y).Max(); double x1Max = ResultData.Find(x => x.Y == y1Max).X; double y1Min = ResultData.Select(x => x.Y).Min(); double x1Min = ResultData.Find(x => x.Y == y1Min).X; if (Math.Abs(y1Max) >= Math.Abs(y1Min)) { xyMarker.MarkerResult.Add(new XYData(x1Max, y1Max)); } else { xyMarker.MarkerResult.Add(new XYData(x1Min, y1Max)); } break; case XYTestMarkerTypeEnum.Mean: double avg = ResultData.Select(x => x.Y).Average(); double xx = ResultData.Select(x => x.X).First(); xyMarker.MarkerResult.Add(new XYData(xx, avg)); break; case XYTestMarkerTypeEnum.PhaseRipple: double phaseNolin = GeneFun.CalcPhaseNonlin(ResultData.Select(x => x.Y).ToArray(), 10000, 0.01); xyMarker.MarkerResult.Add(new XYData(ResultData.Select(x => x.X).First(), phaseNolin)); break; case XYTestMarkerTypeEnum.Ripple: double ymin1 = ResultData.Select(x => x.Y).Min(); double ymax1 = ResultData.Select(x => x.Y).Max(); xyMarker.MarkerResult.Add(new XYData(ResultData.Select(x => x.X).First(), ymax1 - ymin1)); break; case XYTestMarkerTypeEnum.InRange: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.Target: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.Q_Value: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.BandWidth: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.LeftFreq: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.RightFreq: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.CenterFreq: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.InsertionLoss: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.Pin_NdB: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.Po_NdB: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.RippleInRange: xyMarker.MarkerResult.Add(new XYData(0, 0)); break; case XYTestMarkerTypeEnum.RippleHalf: double ymin2 = ResultData.Select(x => x.Y).Min(); double ymax2 = ResultData.Select(x => x.Y).Max(); xyMarker.MarkerResult.Add(new XYData(ResultData.Select(x => x.X).First(), (ymax2 - ymin2) / 2)); break; case XYTestMarkerTypeEnum.PowerMean: double avg1 = ResultData.Select(x => Math.Pow(10, ((x.Y - 30) / 10))).Average(); double xx1 = ResultData.Select(x => x.Y).First(); xyMarker.MarkerResult.Add(new XYData(xx1, avg1)); break; default: break; } } marker.JudgePassFail(); #endregion } if (!spec.TestLimit.Enable) { bool?specPassFail = null; if (spec.UpLimit != null && spec.LowLimit != null) { int upCount = ResultData.Where(x => x.Y > spec.UpLimit).Count(); int lowCount = ResultData.Where(x => x.Y < spec.LowLimit).Count(); if (upCount > 0 || lowCount > 0) { specPassFail = false; } else { specPassFail = true; } } else if (spec.UpLimit != null && spec.LowLimit == null) { int upCount = ResultData.Where(x => x.Y > spec.UpLimit).Count(); if (upCount > 0) { specPassFail = false; } else { specPassFail = true; } } else if (spec.UpLimit == null && spec.LowLimit != null) { int lowCount = ResultData.Where(x => x.Y < spec.LowLimit).Count(); if (lowCount > 0) { specPassFail = false; } else { specPassFail = true; } } else { specPassFail = null; } spec.PassFail = GeneFun.NullBoolAnd(GeneFun.NullBoolAndList(spec.TestMarkerList.Select(x => x.PassFail).ToList()), specPassFail); } } PassFail = GeneFun.NullBoolAndList(TestSpecList.Select(x => x.PassFail).ToList()); }