- Timestamp:
- 03/07/17 16:55:03 (8 years ago)
- Location:
- branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs
r14581 r14725 20 20 #endregion 21 21 22 using System; 22 23 using System.Drawing; 24 using System.Linq; 25 using HeuristicLab.Analysis; 23 26 using HeuristicLab.Common; 24 27 using HeuristicLab.Core; … … 49 52 } 50 53 54 public static DataTable CreateHistogram(IFilteredPreprocessingData preprocessingData, string variableName, string groupingVariableName, DataRowVisualProperties.DataRowHistogramAggregation aggregation) { 55 { 56 var dataTable = new DataTable(); 57 58 if (string.IsNullOrEmpty(groupingVariableName)) { 59 var row = PreprocessingChartContent.CreateDataRow(preprocessingData, variableName, DataRowVisualProperties.DataRowChartType.Histogram); 60 dataTable.Rows.Add(row); 61 return dataTable; 62 } 63 64 dataTable.VisualProperties.Title = variableName; 65 66 int variableIndex = preprocessingData.GetColumnIndex(variableName); 67 var variableValues = preprocessingData.GetValues<double>(variableIndex); 68 int groupVariableIndex = preprocessingData.GetColumnIndex(groupingVariableName); 69 var groupingValues = Enumerable.Empty<string>(); 70 71 if (preprocessingData.VariableHasType<double>(groupVariableIndex)) { 72 groupingValues = preprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString()); 73 } else if (preprocessingData.VariableHasType<string>(groupVariableIndex)) { 74 groupingValues = preprocessingData.GetValues<string>(groupVariableIndex); 75 } else if (preprocessingData.VariableHasType<DateTime>(groupVariableIndex)) { 76 groupingValues = preprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString()); 77 } 78 79 var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2); 80 81 foreach (var group in groups) { 82 var classRow = new DataRow(); 83 classRow.Name = group.Key; 84 classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 85 classRow.VisualProperties.Aggregation = aggregation; 86 classRow.Values.AddRange(group); 87 dataTable.Rows.Add(classRow); 88 } 89 return dataTable; 90 } 91 } 92 51 93 52 94 } -
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs
r14581 r14725 66 66 67 67 public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) { 68 IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName)); 68 return CreateDataRow(PreprocessingData, variableName, chartType); 69 } 70 71 public static DataRow CreateDataRow(IFilteredPreprocessingData preprocessingData, string variableName, DataRowVisualProperties.DataRowChartType chartType) { 72 IList<double> values = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableName)); 69 73 DataRow row = new DataRow(variableName, "", values); 70 74 row.VisualProperties.ChartType = chartType; … … 81 85 return new ReadOnlyCheckedItemList<StringValue>(itemList); 82 86 } 87 88 private const int MAX_DISTINCT_VALUES_FOR_GROUPING = 20; 89 public static IEnumerable<string> GetVariableNamesForGrouping(IPreprocessingData preprocessingData) { 90 var variableNames = new List<string>(); 91 92 for (int i = 0; i < preprocessingData.Columns; ++i) { 93 int distinctValues = Int32.MaxValue; 94 if (preprocessingData.VariableHasType<double>(i)) 95 distinctValues = preprocessingData.GetValues<double>(i).GroupBy(x => x).Count(); 96 else if (preprocessingData.VariableHasType<string>(i)) 97 distinctValues = preprocessingData.GetValues<string>(i).GroupBy(x => x).Count(); 98 else if (preprocessingData.VariableHasType<DateTime>(i)) 99 distinctValues = preprocessingData.GetValues<DateTime>(i).GroupBy(x => x).Count(); 100 101 if (distinctValues <= MAX_DISTINCT_VALUES_FOR_GROUPING) 102 variableNames.Add(preprocessingData.GetVariableName(i)); 103 } 104 return variableNames; 105 } 83 106 } 84 107 } -
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs
r14724 r14725 30 30 31 31 public abstract class ScatterPlotContent : PreprocessingChartContent { 32 public string GroupingVariable { get; set; } 33 32 34 protected ScatterPlotContent(IFilteredPreprocessingData preprocessingData) 33 35 : base(preprocessingData) { … … 38 40 } 39 41 40 public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameGroup = "-") {42 public static ScatterPlot CreateScatterPlot(IFilteredPreprocessingData preprocessingData, string variableNameX, string variableNameY, string variableNameGroup = "-") { 41 43 ScatterPlot scatterPlot = new ScatterPlot(); 42 44 43 IList<double> xValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameX));44 IList<double> yValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameY));45 IList<double> xValues = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableNameX)); 46 IList<double> yValues = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableNameY)); 45 47 46 48 var points = xValues.Zip(yValues, (x, y) => new Point2D<double>(x, y)).ToList(); … … 77 79 78 80 //Grouping 79 int groupVariableIndex = PreprocessingData.GetColumnIndex(variableNameGroup);81 int groupVariableIndex = preprocessingData.GetColumnIndex(variableNameGroup); 80 82 var groupingValues = Enumerable.Empty<string>(); 81 83 82 if ( PreprocessingData.VariableHasType<double>(groupVariableIndex)) {83 groupingValues = PreprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString());84 } else if ( PreprocessingData.VariableHasType<string>(groupVariableIndex)) {85 groupingValues = PreprocessingData.GetValues<string>(groupVariableIndex);86 } else if ( PreprocessingData.VariableHasType<DateTime>(groupVariableIndex)) {87 groupingValues = PreprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString());84 if (preprocessingData.VariableHasType<double>(groupVariableIndex)) { 85 groupingValues = preprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString()); 86 } else if (preprocessingData.VariableHasType<string>(groupVariableIndex)) { 87 groupingValues = preprocessingData.GetValues<string>(groupVariableIndex); 88 } else if (preprocessingData.VariableHasType<DateTime>(groupVariableIndex)) { 89 groupingValues = preprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString()); 88 90 } 89 91 var groups = groupingValues.Zip(validPoints, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2); -
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/SingleScatterPlotContent.cs
r14467 r14725 31 31 public string SelectedXVariable { get; set; } 32 32 public string SelectedYVariable { get; set; } 33 public string SelectedGroupVariable { get; set; }34 33 35 34 public SingleScatterPlotContent(IFilteredPreprocessingData preprocessingData) … … 41 40 this.SelectedXVariable = content.SelectedXVariable; 42 41 this.SelectedYVariable = content.SelectedYVariable; 43 this. SelectedGroupVariable = content.SelectedGroupVariable;42 this.GroupingVariable = content.GroupingVariable; 44 43 } 45 44
Note: See TracChangeset
for help on using the changeset viewer.