Changeset 14725 for branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs
- Timestamp:
- 03/07/17 16:55:03 (7 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.