Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/07/17 16:55:03 (8 years ago)
Author:
mkommend
Message:

#2709: Added grouping for multi scatter plot view.

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  
    2020#endregion
    2121
     22using System;
    2223using System.Drawing;
     24using System.Linq;
     25using HeuristicLab.Analysis;
    2326using HeuristicLab.Common;
    2427using HeuristicLab.Core;
     
    4952    }
    5053
     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
    5193
    5294  }
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs

    r14581 r14725  
    6666
    6767    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));
    6973      DataRow row = new DataRow(variableName, "", values);
    7074      row.VisualProperties.ChartType = chartType;
     
    8185      return new ReadOnlyCheckedItemList<StringValue>(itemList);
    8286    }
     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    }
    83106  }
    84107}
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs

    r14724 r14725  
    3030
    3131  public abstract class ScatterPlotContent : PreprocessingChartContent {
     32    public string GroupingVariable { get; set; }
     33
    3234    protected ScatterPlotContent(IFilteredPreprocessingData preprocessingData)
    3335      : base(preprocessingData) {
     
    3840    }
    3941
    40     public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameGroup = "-") {
     42    public static ScatterPlot CreateScatterPlot(IFilteredPreprocessingData preprocessingData, string variableNameX, string variableNameY, string variableNameGroup = "-") {
    4143      ScatterPlot scatterPlot = new ScatterPlot();
    4244
    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));
    4547
    4648      var points = xValues.Zip(yValues, (x, y) => new Point2D<double>(x, y)).ToList();
     
    7779
    7880      //Grouping
    79       int groupVariableIndex = PreprocessingData.GetColumnIndex(variableNameGroup);
     81      int groupVariableIndex = preprocessingData.GetColumnIndex(variableNameGroup);
    8082      var groupingValues = Enumerable.Empty<string>();
    8183
    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());
    8890      }
    8991      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  
    3131    public string SelectedXVariable { get; set; }
    3232    public string SelectedYVariable { get; set; }
    33     public string SelectedGroupVariable { get; set; }
    3433
    3534    public SingleScatterPlotContent(IFilteredPreprocessingData preprocessingData)
     
    4140      this.SelectedXVariable = content.SelectedXVariable;
    4241      this.SelectedYVariable = content.SelectedYVariable;
    43       this.SelectedGroupVariable = content.SelectedGroupVariable;
     42      this.GroupingVariable = content.GroupingVariable;
    4443    }
    4544
Note: See TracChangeset for help on using the changeset viewer.