- Timestamp:
- 07/03/17 10:57:53 (7 years ago)
- Location:
- trunk/sources/HeuristicLab.DataPreprocessing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.DataPreprocessing
-
Property
svn:mergeinfo
set to
/branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/sources/HeuristicLab.DataPreprocessing/3.4
-
trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs
r14185 r15110 20 20 #endregion 21 21 22 using System .Collections.Generic;22 using System; 23 23 using System.Drawing; 24 24 using System.Linq; 25 using HeuristicLab.Analysis; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 29 30 [Item("Histogram", "Represents the histogram grid.")] 30 31 public class HistogramContent : PreprocessingChartContent { 31 32 32 public static new Image StaticItemImage { 33 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.Statistics; } 34 34 } 35 private const int MAX_DISTINCT_VALUES_FOR_CLASSIFCATION = 20;36 35 37 p rivate int classifierVariableIndex = 0;36 public string GroupingVariableName { get; set; } 38 37 39 public int ClassifierVariableIndex { 40 get { return this.classifierVariableIndex; } 41 set { this.classifierVariableIndex = value; } 42 } 43 public bool IsDetailedChartViewEnabled { get; set; } 38 public int Bins { get; set; } 39 public bool ExactBins { get; set; } 44 40 41 public LegendOrder Order { get; set; } 45 42 46 43 public HistogramContent(IFilteredPreprocessingData preprocessingData) 47 44 : base(preprocessingData) { 48 AllInOneMode = false; 45 Bins = 10; 46 ExactBins = false; 49 47 } 50 48 … … 56 54 } 57 55 58 public IEnumerable<string> GetVariableNamesForHistogramClassification() { 59 List<string> doubleVariableNames = new List<string>(); 56 public static DataTable CreateHistogram(IFilteredPreprocessingData preprocessingData, string variableName, string groupingVariableName, DataTableVisualProperties.DataTableHistogramAggregation aggregation, LegendOrder legendOrder = LegendOrder.Appearance) { 57 var dataTable = new DataTable { 58 VisualProperties = { Title = variableName, HistogramAggregation = aggregation }, 59 }; 60 60 61 //only return variable names from type double 62 for (int i = 0; i < PreprocessingData.Columns; ++i) { 63 if (PreprocessingData.VariableHasType<double>(i)) { 64 double distinctValueCount = PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count(); 65 bool distinctValuesOk = distinctValueCount <= MAX_DISTINCT_VALUES_FOR_CLASSIFCATION; 66 if (distinctValuesOk) 67 doubleVariableNames.Add(PreprocessingData.GetVariableName(i)); 68 } 61 if (string.IsNullOrEmpty(groupingVariableName)) { 62 var row = PreprocessingChartContent.CreateDataRow(preprocessingData, variableName, DataRowVisualProperties.DataRowChartType.Histogram); 63 row.VisualProperties.IsVisibleInLegend = false; 64 dataTable.Rows.Add(row); 65 return dataTable; 69 66 } 70 return doubleVariableNames; 67 68 int variableIndex = preprocessingData.GetColumnIndex(variableName); 69 var variableValues = preprocessingData.GetValues<double>(variableIndex); 70 int groupVariableIndex = preprocessingData.GetColumnIndex(groupingVariableName); 71 var groupingValues = Enumerable.Empty<string>(); 72 73 if (preprocessingData.VariableHasType<double>(groupVariableIndex)) { 74 groupingValues = preprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString()); 75 } else if (preprocessingData.VariableHasType<string>(groupVariableIndex)) { 76 groupingValues = preprocessingData.GetValues<string>(groupVariableIndex); 77 } else if (preprocessingData.VariableHasType<DateTime>(groupVariableIndex)) { 78 groupingValues = preprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString()); 79 } 80 81 var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2); 82 83 if (legendOrder == LegendOrder.Alphabetically) 84 groups = groups.OrderBy(x => x.Key, new NaturalStringComparer()); 85 86 foreach (var group in groups) { 87 var classRow = new DataRow { 88 Name = group.Key, 89 VisualProperties = { 90 ChartType = DataRowVisualProperties.DataRowChartType.Histogram, 91 IsVisibleInLegend = !string.IsNullOrEmpty(groupingVariableName) 92 } 93 }; 94 classRow.Values.AddRange(group); 95 dataTable.Rows.Add(classRow); 96 } 97 return dataTable; 71 98 } 72 73 99 } 74 100 }
Note: See TracChangeset
for help on using the changeset viewer.