Changeset 14579
- Timestamp:
- 01/18/17 11:17:19 (8 years ago)
- Location:
- branches/DataPreprocessing Enhancements
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/HistogramView.cs
r14474 r14579 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Analysis; … … 27 26 28 27 namespace HeuristicLab.DataPreprocessing.Views { 29 30 28 [View("Histogram View")] 31 29 [Content(typeof(HistogramContent), true)] 32 30 public partial class HistogramView : PreprocessingChartView { 33 34 public List<double> Classification { get; set; } 35 public bool IsDetailedChartViewEnabled { get; set; } 31 public new HistogramContent Content { 32 get { return (HistogramContent)base.Content; } 33 set { base.Content = value; } 34 } 36 35 37 36 public HistogramView() { … … 41 40 protected override void OnContentChanged() { 42 41 base.OnContentChanged(); 42 classifierComboBox.Items.Clear(); 43 classifierComboBox.Items.Add(""); 44 43 45 if (Content != null) { 44 classifierComboBox.Items.Clear(); 45 classifierComboBox.Items.Add("None"); 46 47 foreach (string var in Content.GetVariableNamesForHistogramClassification()) { 46 foreach (string var in Content.GetVariableNamesForGrouping()) { 48 47 classifierComboBox.Items.Add(var); 49 48 } 50 49 51 if (classifierComboBox.SelectedItem == null && Content.ClassifierVariableIndex < classifierComboBox.Items.Count) { 52 classifierComboBox.SelectedIndex = Content.ClassifierVariableIndex; 53 } 50 classifierComboBox.SelectedItem = Content.GroupingVariableName; 54 51 } 55 52 } 56 53 57 54 protected override DataTable CreateDataTable(string variableName) { 58 var dt = new DataTable(); 59 var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Histogram); 60 if (Classification == null) { 61 dt.Rows.Add(row); 62 } else { 63 dt.VisualProperties.Title = variableName; 64 var valuesPerClass = row.Values.Zip(Classification, (value, @class) => new { value, @class }) 65 .GroupBy(x => x.@class) 66 .ToDictionary(x => x.Key, x => x.Select(v => v.value)); 67 foreach (var entry in valuesPerClass) { 68 var classRow = new DataRow(string.Format("{0} ({1})", classifierComboBox.SelectedItem, entry.Key)); 69 classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 70 classRow.Values.AddRange(entry.Value); 71 dt.Rows.Add(classRow); 72 } 55 var dataTable = new DataTable(); 56 57 if (string.IsNullOrEmpty(Content.GroupingVariableName)) { 58 var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Histogram); 59 dataTable.Rows.Add(row); 60 return dataTable; 73 61 } 74 return dt; 62 63 dataTable.VisualProperties.Title = variableName; 64 65 int variableIndex = Content.PreprocessingData.GetColumnIndex(variableName); 66 var variableValues = Content.PreprocessingData.GetValues<double>(variableIndex); 67 int groupVariableIndex = Content.PreprocessingData.GetColumnIndex(Content.GroupingVariableName); 68 var groupingValues = Enumerable.Empty<string>(); 69 70 if (Content.PreprocessingData.VariableHasType<double>(groupVariableIndex)) { 71 groupingValues = Content.PreprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString()); 72 } else if (Content.PreprocessingData.VariableHasType<string>(groupVariableIndex)) { 73 groupingValues = Content.PreprocessingData.GetValues<string>(groupVariableIndex); 74 } else if (Content.PreprocessingData.VariableHasType<DateTime>(groupVariableIndex)) { 75 groupingValues = Content.PreprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString()); 76 } 77 78 var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2); 79 80 foreach (var group in groups) { 81 var classRow = new DataRow(); 82 classRow.Name = group.Key; 83 classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 84 classRow.Values.AddRange(group); 85 dataTable.Rows.Add(classRow); 86 } 87 return dataTable; 75 88 } 76 89 77 public new HistogramContent Content {78 get { return (HistogramContent)base.Content; }79 set { base.Content = value; }80 }81 90 82 91 private void classifierComboBox_SelectedIndexChanged(object sender, EventArgs e) { 83 if (classifierComboBox.SelectedItem == null) 84 return; 85 86 if (classifierComboBox.SelectedIndex != 0) { 87 int columndIndex = Content.PreprocessingData.GetColumnIndex(classifierComboBox.SelectedItem.ToString()); 88 Classification = Content.PreprocessingData.GetValues<double>(columndIndex).ToList(); 89 } else { 90 Classification = null; 91 } 92 93 Content.ClassifierVariableIndex = classifierComboBox.SelectedIndex; 92 Content.GroupingVariableName = classifierComboBox.SelectedItem.ToString(); 94 93 95 94 // rebuild datatables -
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs
r14459 r14579 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Drawing; … … 33 34 get { return HeuristicLab.Common.Resources.VSImageLibrary.Statistics; } 34 35 } 35 private const int MAX_DISTINCT_VALUES_FOR_CLASSIFCATION = 20;36 36 37 public int ClassifierVariableIndex { get; set; } 37 private const int MAX_DISTINCT_VALUES_FOR_GROUPING = 20; 38 39 public string GroupingVariableName { get; set; } 38 40 39 41 public int Bins { get; set; } … … 53 55 } 54 56 55 public IEnumerable<string> GetVariableNamesFor HistogramClassification() {56 List<string> doubleVariableNames = new List<string>();57 public IEnumerable<string> GetVariableNamesForGrouping() { 58 var variableNames = new List<string>(); 57 59 58 //only return variable names from type double59 60 for (int i = 0; i < PreprocessingData.Columns; ++i) { 60 if (PreprocessingData.VariableHasType<double>(i)) { 61 double distinctValueCount = PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count(); 62 bool distinctValuesOk = distinctValueCount <= MAX_DISTINCT_VALUES_FOR_CLASSIFCATION; 63 if (distinctValuesOk) 64 doubleVariableNames.Add(PreprocessingData.GetVariableName(i)); 65 } 61 int distinctValues = int.MaxValue; 62 if (PreprocessingData.VariableHasType<double>(i)) 63 distinctValues = PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count(); 64 else if (PreprocessingData.VariableHasType<string>(i)) 65 distinctValues = PreprocessingData.GetValues<string>(i).GroupBy(x => x).Count(); 66 else if (PreprocessingData.VariableHasType<DateTime>(i)) 67 distinctValues = PreprocessingData.GetValues<DateTime>(i).GroupBy(x => x).Count(); 68 69 if (distinctValues <= MAX_DISTINCT_VALUES_FOR_GROUPING) 70 variableNames.Add(PreprocessingData.GetVariableName(i)); 66 71 } 67 return doubleVariableNames;72 return variableNames; 68 73 } 69 74 }
Note: See TracChangeset
for help on using the changeset viewer.