public void Generate(ChronoParamInjectorCorrections result, DateTime date) { IList <int> lowRpmIndexes = ExtractRpmIndexes(rpmData, LowRpm); IList <int> mediumRpmIndexes = ExtractRpmIndexes(rpmData, MediumRpm); IList <int> highRpmIndexes = ExtractRpmIndexes(rpmData, HighRpm); /*if (lowRpmIndexes.Count == 0 || mediumRpmIndexes.Count == 0 || * highRpmIndexes.Count == 0) * { * return; * }*/ IList <double> lowRpmCorrectionValues = new List <double>(); if (lowRpmIndexes.Count != 0) { lowRpmCorrectionValues = ExtractMedianCorrectionValuesForRpm( injectorData, lowRpmIndexes); } IList <double> mediumRpmCorrectionValues = new List <double>(); if (mediumRpmIndexes.Count != 0) { mediumRpmCorrectionValues = ExtractMedianCorrectionValuesForRpm( injectorData, mediumRpmIndexes); } IList <double> highRpmCorrectionValues = new List <double>(); if (highRpmIndexes.Count != 0) { highRpmCorrectionValues = ExtractMedianCorrectionValuesForRpm( injectorData, highRpmIndexes); } double totalMin = double.NaN; double totalMax = double.NaN; if (lowRpmCorrectionValues.Count != 0) { RangeInjectorCorrectionsChronoData resultComponent = result.LowRpmRangeData.FirstOrDefault( m => m.InjectorNumber == injectorNumber); if (resultComponent == null) { resultComponent = new RangeInjectorCorrectionsChronoData(); result.LowRpmRangeData.Add(resultComponent); } resultComponent.InjectorNumber = injectorNumber; resultComponent.Dates.Add(date); double min = lowRpmCorrectionValues.Min(); double max = lowRpmCorrectionValues.Max(); resultComponent.MaxValues.Add(max); resultComponent.MinValues.Add(min); totalMin = min; totalMax = max; } if (mediumRpmCorrectionValues.Count != 0) { RangeInjectorCorrectionsChronoData resultComponent = result.MediumRpmRangeData.FirstOrDefault( m => m.InjectorNumber == injectorNumber); if (resultComponent == null) { resultComponent = new RangeInjectorCorrectionsChronoData(); result.MediumRpmRangeData.Add(resultComponent); } resultComponent.InjectorNumber = injectorNumber; resultComponent.Dates.Add(date); double min = mediumRpmCorrectionValues.Min(); double max = mediumRpmCorrectionValues.Max(); resultComponent.MaxValues.Add(max); resultComponent.MinValues.Add(min); if (!double.IsNaN(totalMin)) { totalMin = Math.Min(totalMin, min); } else { totalMin = min; } if (!double.IsNaN(totalMax)) { totalMax = Math.Max(totalMax, max); } else { totalMax = max; } } if (highRpmCorrectionValues.Count != 0) { RangeInjectorCorrectionsChronoData resultComponent = result.HighRpmRangeData.FirstOrDefault( m => m.InjectorNumber == injectorNumber); if (resultComponent == null) { resultComponent = new RangeInjectorCorrectionsChronoData(); result.HighRpmRangeData.Add(resultComponent); } resultComponent.InjectorNumber = injectorNumber; resultComponent.Dates.Add(date); double max = highRpmCorrectionValues.Max(); double min = highRpmCorrectionValues.Min(); resultComponent.MaxValues.Add(max); resultComponent.MinValues.Add(min); if (!double.IsNaN(totalMin)) { totalMin = Math.Min(totalMin, min); } else { totalMin = min; } if (!double.IsNaN(totalMax)) { totalMax = Math.Max(totalMax, max); } else { totalMax = max; } } // get total range if (lowRpmIndexes.Count == 0 || mediumRpmIndexes.Count == 0 || highRpmIndexes.Count == 0) { if (!double.IsNaN(totalMax) && !double.IsNaN(totalMin)) { RangeInjectorCorrectionsChronoData data = result.RangeData.FirstOrDefault( d => d.InjectorNumber == injectorNumber); if (data == null) { data = new RangeInjectorCorrectionsChronoData(); result.RangeData.Add(data); } data.Dates.Add(date); data.InjectorNumber = injectorNumber; data.MaxValues.Add(totalMax); data.MinValues.Add(totalMin); } } }
public void Generate( ChronoParamInjectorCorrections result, DateTime date) { IList <int> lowRpmIndexes = ExtractRpmIndexes(rpmData, LowRpm); IList <int> mediumRpmIndexes = ExtractRpmIndexes(rpmData, MediumRpm); IList <int> highRpmIndexes = ExtractRpmIndexes(rpmData, HighRpm); double lowRpmCorrectionValue = double.NaN; if (lowRpmIndexes.Count != 0) { lowRpmCorrectionValue = ExtractMedianCorrectionValueForRpm( injectorData, lowRpmIndexes); } double mediumRpmCorrectionValue = double.NaN; if (mediumRpmIndexes.Count != 0) { mediumRpmCorrectionValue = ExtractMedianCorrectionValueForRpm( injectorData, mediumRpmIndexes); } double highRpmCorrectionValue = double.NaN; if (highRpmIndexes.Count != 0) { highRpmCorrectionValue = ExtractMedianCorrectionValueForRpm( injectorData, highRpmIndexes); } double totalMediumValue = double.NaN; if (lowRpmIndexes.Count != 0 || mediumRpmIndexes.Count != 0 || highRpmIndexes.Count != 0) { totalMediumValue = (lowRpmCorrectionValue + mediumRpmCorrectionValue + highRpmCorrectionValue) / 3; } // check whether any data has been generated and push it to result // for low rpm if (!double.IsNaN(lowRpmCorrectionValue)) { MedianInjectorCorrectionsChronoData medianResultComponent = result.LowRpmMedianData.FirstOrDefault( m => m.InjectorNumber == injectorNumber); if (medianResultComponent == null) { medianResultComponent = new MedianInjectorCorrectionsChronoData(); medianResultComponent.InjectorNumber = injectorNumber; result.LowRpmMedianData.Add(medianResultComponent); } medianResultComponent.Dates.Add(date); medianResultComponent.Values.Add(lowRpmCorrectionValue); } // for medium rpm if (!double.IsNaN(mediumRpmCorrectionValue)) { MedianInjectorCorrectionsChronoData medianResultComponent = result.MediumRpmMedianData.FirstOrDefault( m => m.InjectorNumber == injectorNumber); if (medianResultComponent == null) { medianResultComponent = new MedianInjectorCorrectionsChronoData(); result.MediumRpmMedianData.Add(medianResultComponent); medianResultComponent.InjectorNumber = injectorNumber; } medianResultComponent.Dates.Add(date); medianResultComponent.Values.Add(mediumRpmCorrectionValue); } // for high rpm if (!double.IsNaN(highRpmCorrectionValue)) { MedianInjectorCorrectionsChronoData medianResultComponent = result.HighRpmMedianData.FirstOrDefault( m => m.InjectorNumber == injectorNumber); if (medianResultComponent == null) { medianResultComponent = new MedianInjectorCorrectionsChronoData(); medianResultComponent.InjectorNumber = injectorNumber; result.HighRpmMedianData.Add(medianResultComponent); } medianResultComponent.Dates.Add(date); medianResultComponent.Values.Add(highRpmCorrectionValue); } // for total medium value if (!double.IsNaN(totalMediumValue)) { MedianInjectorCorrectionsChronoData medianResultComponent = result.MedianData.FirstOrDefault( m => m.InjectorNumber == injectorNumber); if (medianResultComponent == null) { medianResultComponent = new MedianInjectorCorrectionsChronoData(); result.MedianData.Add(medianResultComponent); medianResultComponent.InjectorNumber = injectorNumber; } medianResultComponent.Dates.Add(date); medianResultComponent.Values.Add(totalMediumValue); } }