private static bool ShouldShowDialog(HistogramCreationInformation histInfo) { bool showDialog; switch (histInfo.UserInteractionLevel) { case Gui.UserInteractionLevel.None: showDialog = false; break; case Gui.UserInteractionLevel.InteractOnErrors: showDialog = histInfo.Errors.Count > 0; break; case Gui.UserInteractionLevel.InteractOnWarningsAndErrors: showDialog = histInfo.Errors.Count > 0 || histInfo.Warnings.Count > 0; break; case Gui.UserInteractionLevel.InteractAlways: showDialog = true; break; default: throw new NotImplementedException("userInteractionLevel"); } return(showDialog); }
public static void CreateHistogram(ref DataTable destinationTable, HistogramCreationInformation histInfo) { if (null == histInfo) { throw new ArgumentNullException("histInfo"); } var dataEnumerator = histInfo.OriginalDataEnsemble; var userInteractionLevel = histInfo.UserInteractionLevel; if (null == dataEnumerator) { throw new ArgumentNullException("histInfo's DataEnsemble is null."); } bool showDialog = PopulateHistogramCreationInformation(histInfo); if (showDialog) { if (!Current.Gui.ShowDialog(ref histInfo, "Binning options", true)) { return; } } CreateHistogramTable(ref destinationTable, null, histInfo.FilteredAndSortedDataEnsemble, histInfo.CreationOptions.Binning); }
public static DataTable CreateHistogram(string proposedTableName, HistogramCreationInformation histInfo) { if (null == proposedTableName) { throw new ArgumentNullException("proposedTableName"); } if (null == histInfo) { throw new ArgumentNullException("histInfo"); } DataTable destinationTable = null; bool showDialog = PopulateHistogramCreationInformation(histInfo); if (showDialog) { if (!Current.Gui.ShowDialog(ref histInfo, "Binning options", true)) { return(null); } } CreateHistogramTable(ref destinationTable, proposedTableName, histInfo.FilteredAndSortedDataEnsemble, histInfo.CreationOptions.Binning); return(destinationTable); }
/// <summary> /// Calculates statistics of selected columns. Returns a new table where the statistical data will be written to. /// </summary> /// <param name="srctable">Source table.</param> /// <param name="selectedColumns">Selected data columns in the source table.</param> /// <param name="selectedRows">Selected rows in the source table.</param> /// <param name="userInteractionLevel">Determines the level of user interaction.</param> public static DataTable CreateHistogramOnColumns( this DataTable srctable, IAscendingIntegerCollection selectedColumns, IAscendingIntegerCollection selectedRows, Gui.UserInteractionLevel userInteractionLevel ) { if (null == srctable) { throw new ArgumentNullException("srctable"); } var histInfo = new HistogramCreationInformation() { UserInteractionLevel = userInteractionLevel, OriginalDataEnsemble = new NumericTableRegionEnumerator(srctable, selectedColumns, selectedRows) }; return(CreateHistogram(srctable.Name + "-HistogramData", histInfo)); }
public static bool PopulateHistogramCreationInformation(HistogramCreationInformation histInfo) { if (null == histInfo) { throw new ArgumentNullException("histInfo"); } if (null == histInfo.OriginalDataEnsemble) { throw new ArgumentNullException("histInfo's DataEnsemble is null, but is required for this action."); } histInfo.Errors.Clear(); histInfo.Warnings.Clear(); var list = new List <double>(); histInfo.FilteredAndSortedDataEnsemble = list; Func <double, bool> IsExcluded = histInfo.CreationOptions.GetValueExcludingFunction(); var options = histInfo.CreationOptions; int numberOfNaNValues = 0; int numberOfInfiniteValues = 0; int numberOfValuesOriginal = 0; var dataEnumerator = histInfo.OriginalDataEnsemble; dataEnumerator.Reset(); while (dataEnumerator.MoveNext()) { ++numberOfValuesOriginal; double x = dataEnumerator.Current; if (double.IsNaN(x)) { ++numberOfNaNValues; } else if (!Altaxo.Calc.RMath.IsFinite(x)) { ++numberOfInfiniteValues; } else if (!IsExcluded(x)) { list.Add(x); } } if (numberOfNaNValues > 0 && !histInfo.CreationOptions.IgnoreNaN) { histInfo.Errors.Add("Data ensemble contains NaN values. Set the option 'Ignore NaN values' to ignore those values."); } if (numberOfInfiniteValues > 0 && !histInfo.CreationOptions.IgnoreInfinity) { histInfo.Errors.Add("Data ensemble contains infinite values. Set the option 'Ignore infinite values' to ignore those values."); } list.Sort(); int numberOfValues = list.Count; histInfo.NumberOfValuesOriginal = numberOfValuesOriginal; histInfo.NumberOfValuesFiltered = list.Count; histInfo.NumberOfNaNValues = numberOfNaNValues; histInfo.NumberOfInfiniteValues = numberOfInfiniteValues; double minValue = double.NaN; double maxValue = double.NaN; if (list.Count == 0) { histInfo.Errors.Add("No values available (number of selected values is zero)."); } else if (list.Count < 10) { histInfo.Warnings.Add("Number of selected values is less than 10"); } if (list.Count > 0) { minValue = list[0]; maxValue = list[numberOfValues - 1]; histInfo.MinimumValue = minValue; histInfo.MaximumValue = maxValue; // here we must decide between linear binning and logarithmic binning if (!histInfo.CreationOptions.IsUserDefinedBinningType) { Type binningType; if (minValue > 0 && maxValue > 0 && (Math.Log10(maxValue) - Math.Log10(minValue)) > 3) { binningType = typeof(LogarithmicBinning); } else { binningType = typeof(LinearBinning); } if (binningType != histInfo.CreationOptions.Binning.GetType()) { histInfo.CreationOptions.Binning = (IBinning)Activator.CreateInstance(binningType); } } } // OK, up here we have either LinearBinning or LogarithmicBinning var binning = histInfo.CreationOptions.Binning; try { // calculate number of resulting bins binning.CalculateBinPositionsFromSortedList(list); } catch (Exception ex) { histInfo.Errors.Add(ex.Message); } bool showDialog = ShouldShowDialog(histInfo); if (!showDialog && histInfo.Errors.Count > 0) { throw new InvalidOperationException(string.Join("\r\n", histInfo.Errors)); } return(showDialog); }