Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14581


Ignore:
Timestamp:
01/18/17 11:25:43 (7 years ago)
Author:
mkommend
Message:

#2709: Refactored get variables for grouping (extracted method to another class).

Location:
branches/DataPreprocessing Enhancements
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/HistogramView.cs

    r14579 r14581  
    4444
    4545      if (Content != null) {
    46         foreach (string var in Content.GetVariableNamesForGrouping()) {
     46        foreach (string var in GetVariableNamesForGrouping(Content.PreprocessingData)) {
    4747          classifierComboBox.Items.Add(var);
    4848        }
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingChartView.cs

    r14511 r14581  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Drawing;
     
    3536  [Content(typeof(PreprocessingChartContent), false)]
    3637  public partial class PreprocessingChartView : PreprocessingCheckedVariablesView {
    37 
     38    private const int MAX_DISTINCT_VALUES_FOR_GROUPING = 20;
    3839    protected Dictionary<string, DataTable> dataTables;
    3940    protected Dictionary<string, DataTableControl> dataTableControls;
     
    5455      InitializeComponent();
    5556      dataTables = new Dictionary<string, DataTable>();
    56       dataTableControls= new Dictionary<string, DataTableControl>();
     57      dataTableControls = new Dictionary<string, DataTableControl>();
    5758    }
    5859
     
    6364        GenerateLayout();
    6465      }
     66    }
     67
     68    protected static IEnumerable<string> GetVariableNamesForGrouping(IPreprocessingData preprocessingData) {
     69      var variableNames = new List<string>();
     70
     71      for (int i = 0; i < preprocessingData.Columns; ++i) {
     72        int distinctValues = Int32.MaxValue;
     73        if (preprocessingData.VariableHasType<double>(i))
     74          distinctValues = preprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
     75        else if (preprocessingData.VariableHasType<string>(i))
     76          distinctValues = preprocessingData.GetValues<string>(i).GroupBy(x => x).Count();
     77        else if (preprocessingData.VariableHasType<DateTime>(i))
     78          distinctValues = preprocessingData.GetValues<DateTime>(i).GroupBy(x => x).Count();
     79
     80        if (distinctValues <= MAX_DISTINCT_VALUES_FOR_GROUPING)
     81          variableNames.Add(preprocessingData.GetVariableName(i));
     82      }
     83      return variableNames;
    6584    }
    6685
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs

    r14579 r14581  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using System.Drawing;
    25 using System.Linq;
    2623using HeuristicLab.Common;
    2724using HeuristicLab.Core;
     
    3027  [Item("Histogram", "Represents the histogram grid.")]
    3128  public class HistogramContent : PreprocessingChartContent {
    32 
    3329    public static new Image StaticItemImage {
    3430      get { return HeuristicLab.Common.Resources.VSImageLibrary.Statistics; }
    3531    }
    36 
    37     private const int MAX_DISTINCT_VALUES_FOR_GROUPING = 20;
    3832
    3933    public string GroupingVariableName { get; set; }
     
    5549    }
    5650
    57     public IEnumerable<string> GetVariableNamesForGrouping() {
    58       var variableNames = new List<string>();
    5951
    60       for (int i = 0; i < PreprocessingData.Columns; ++i) {
    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));
    71       }
    72       return variableNames;
    73     }
    7452  }
    7553}
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs

    r14511 r14581  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Drawing;
     25using System.Linq;
    2426using HeuristicLab.Analysis;
    2527using HeuristicLab.Common;
     28using HeuristicLab.Common.Resources;
    2629using HeuristicLab.Core;
    2730using HeuristicLab.Data;
     
    3134  public class PreprocessingChartContent : Item, IViewShortcut {
    3235    public static new Image StaticItemImage {
    33       get { return HeuristicLab.Common.Resources.VSImageLibrary.PieChart; }
     36      get { return VSImageLibrary.PieChart; }
    3437    }
    3538
     
    3841      get {
    3942        if (variableItemList == null)
    40           variableItemList = CreateVariableItemList();
     43          variableItemList = CreateVariableItemList(PreprocessingData);
    4144        return this.variableItemList;
    4245      }
    43       //set { this.variableItemList = value; }
    4446    }
    4547
    4648    public IFilteredPreprocessingData PreprocessingData { get; private set; }
     49    public event DataPreprocessingChangedEventHandler Changed {
     50      add { PreprocessingData.Changed += value; }
     51      remove { PreprocessingData.Changed -= value; }
     52    }
    4753
    4854    public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
     
    6672    }
    6773
    68 
    69 
    70 
    71     public ICheckedItemList<StringValue> CreateVariableItemList() {
     74    private static ICheckedItemList<StringValue> CreateVariableItemList(IPreprocessingData preprocessingData) {
    7275      ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
    73       foreach (string name in PreprocessingData.GetDoubleVariableNames()) {
     76      foreach (string name in preprocessingData.GetDoubleVariableNames()) {
    7477        var n = new StringValue(name);
    75         bool isInputTarget = PreprocessingData.InputVariables.Contains(name) || PreprocessingData.TargetVariable == name;
     78        bool isInputTarget = preprocessingData.InputVariables.Contains(name) || preprocessingData.TargetVariable == name;
    7679        itemList.Add(n, isInputTarget);
    7780      }
    7881      return new ReadOnlyCheckedItemList<StringValue>(itemList);
    7982    }
    80 
    81     public event DataPreprocessingChangedEventHandler Changed {
    82       add { PreprocessingData.Changed += value; }
    83       remove { PreprocessingData.Changed -= value; }
    84     }
    85 
    8683  }
    8784}
Note: See TracChangeset for help on using the changeset viewer.