Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/11/14 15:43:05 (10 years ago)
Author:
mleitner
Message:

Refactoring

Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4
Files:
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/HeuristicLab.DataPreprocessing-3.4.csproj

    r10992 r11002  
    7878    <Compile Include="Implementations\PreprocessingChartContent.cs" />
    7979    <Compile Include="Implementations\PreprocessingData.cs" />
    80     <Compile Include="Implementations\DataGridLogic.cs" />
    8180    <Compile Include="Implementations\PreprocessingDataTable.cs" />
    8281    <Compile Include="Interfaces\IViewChartShortcut.cs" />
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/CorrelationMatrixContent.cs

    r10982 r11002  
    5050    public CorrelationMatrixContent(CorrelationMatrixContent original, Cloner cloner)
    5151      : base(original, cloner) {
     52        Context = original.Context;
    5253    }
    5354
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/DataCompletenessChartContent.cs

    r10999 r11002  
    55namespace HeuristicLab.DataPreprocessing {
    66  [Item("DataCompletenessChart", "Represents a datacompleteness chart.")]
    7   public class DataCompletenessChartContent : Item, IViewChartShortcut {
    87
     8  public class DataCompletenessChartContent : Item, IViewChartShortcut
     9  {
    910    public static new Image StaticItemImage {
    1011      get { return HeuristicLab.Common.Resources.VSImageLibrary.EditBrightnessContrast; }
    1112    }
    1213
     14    private readonly SearchLogic searchLogic;
     15
    1316    public IDataGridLogic DataGridLogic { get; private set; }
    1417    public ISearchLogic SearchLogic { get; private set; }
    1518
    16     public DataCompletenessChartContent(DataGridLogic dataGridLogic, SearchLogic searchLogic) {
    17       DataGridLogic = dataGridLogic;
    18       SearchLogic = searchLogic;
     19    public DataCompletenessChartContent(SearchLogic searchLogic)
     20    {
     21      this.searchLogic = searchLogic;
    1922    }
    20 
     23   
    2124    public DataCompletenessChartContent(DataCompletenessChartContent content, Cloner cloner)
    22       : base(content, cloner) {
    23       DataGridLogic = content.DataGridLogic;
    24       SearchLogic = content.SearchLogic;
     25      : base(content, cloner)
     26    {
     27      this.searchLogic = content.searchLogic;
    2528    }
    2629
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridContent.cs

    r10999 r11002  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using System.Globalization;
     26using System.Linq;
    2527using HeuristicLab.Common;
    2628using HeuristicLab.Core;
     29using HeuristicLab.Data;
    2730
    2831namespace HeuristicLab.DataPreprocessing {
     
    3134  public class DataGridContent : Item, IViewShortcut, IDataGridContent {
    3235
     36    public ITransactionalPreprocessingData PreProcessingData { get; private set; }
     37
    3338    public static new Image StaticItemImage {
    3439      get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; }
     
    3641
    3742    public IManipulationLogic ManipulationLogic { get; private set; }
    38     public IDataGridLogic DataGridLogic { get; private set; }
    3943    public IFilterLogic FilterLogic { get; private set; }
     44
     45    private IEnumerable<string> rowNames;
    4046
    4147    public int Rows {
    4248      get {
    43         return DataGridLogic.Rows;
     49        return PreProcessingData.Rows;
    4450      }
    4551      set {
     
    5056    public int Columns {
    5157      get {
    52         return DataGridLogic.Columns;
     58        return PreProcessingData.Columns;
    5359      }
    5460      set {
     
    5965    public IEnumerable<string> ColumnNames {
    6066      get {
    61         return DataGridLogic.ColumnNames;
     67        return PreProcessingData.VariableNames;
    6268      }
    6369      set {
     
    6874    public IEnumerable<string> RowNames {
    6975      get {
    70         return DataGridLogic.RowNames;
     76        return rowNames;
    7177      }
    7278      set {
     
    8894    }
    8995
    90     public DataGridContent(IDataGridLogic theDataGridLogic, IManipulationLogic theManipulationLogic, IFilterLogic theFilterLogic) {
    91       DataGridLogic = theDataGridLogic;
     96
     97    private IDictionary<int, IList<int>> selection;
     98    public IDictionary<int, IList<int>> Selection {
     99      get { return PreProcessingData.Selection; }
     100      set { PreProcessingData.Selection = value; }
     101    }
     102
     103
     104    public DataGridContent(ITransactionalPreprocessingData preProcessingData, IManipulationLogic theManipulationLogic, IFilterLogic theFilterLogic) {
    92105      ManipulationLogic = theManipulationLogic;
    93106      FilterLogic = theFilterLogic;
     107      PreProcessingData = preProcessingData;
     108      createRowNames();
    94109    }
    95110
     
    102117    }
    103118
     119    public void DeleteRow(IEnumerable<int> rows) {
     120      PreProcessingData.DeleteRowsWithIndices(rows);
     121      createRowNames();
     122    }
     123
     124    public bool Validate(string value, out string errorMessage, int columnIndex) {
     125      return PreProcessingData.Validate(value, out errorMessage, columnIndex);
     126    }
     127
    104128    public string GetValue(int rowIndex, int columnIndex) {
    105       return DataGridLogic.GetValue(columnIndex, rowIndex);
     129      return PreProcessingData.GetCellAsString(columnIndex, rowIndex);
    106130    }
    107131
    108132    public bool SetValue(string value, int rowIndex, int columnIndex) {
    109       return DataGridLogic.SetValue(value, columnIndex, rowIndex);
     133      return PreProcessingData.SetValue(value, columnIndex, rowIndex);
     134    }
     135
     136    private void createRowNames() {
     137      rowNames = Enumerable.Range(1, Rows).Select(n => n.ToString());
    110138    }
    111139
    112140    public event DataPreprocessingChangedEventHandler Changed {
    113       add { DataGridLogic.Changed += value; }
    114       remove { DataGridLogic.Changed -= value; }
     141      add { PreProcessingData.Changed += value; }
     142      remove { PreProcessingData.Changed -= value; }
    115143    }
    116144
     
    126154
    127155    public event EventHandler ColumnsChanged;
    128 
    129156    public event EventHandler RowsChanged;
    130 
    131157    public event EventHandler ColumnNamesChanged;
    132 
    133158    public event EventHandler RowNamesChanged;
    134 
    135159    public event EventHandler SortableViewChanged;
    136 
    137160    public event EventHandler<EventArgs<int, int>> ItemChanged;
    138 
    139161    public event EventHandler Reset;
    140162    #endregion
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/ManipulationContent.cs

    r10970 r11002  
    3131    private IManipulationLogic manipulationLogic;
    3232    private ISearchLogic searchLogic;
    33     private IDataGridLogic dataGridLogic;
    3433    private IFilterLogic filterLogic;
    3534
    3635    public IManipulationLogic ManipulationLogic { get { return manipulationLogic; } }
    3736    public ISearchLogic SearchLogic { get { return searchLogic; } }
    38     public IDataGridLogic DataGridLogic { get { return dataGridLogic; } }
    3937    public IFilterLogic FilterLogic { get { return filterLogic; } }
    4038
     
    4341    }
    4442
    45     public ManipulationContent(IManipulationLogic theManipulationLogic, ISearchLogic theSearchLogic, IDataGridLogic theDataGridLogic, IFilterLogic theFitlerLogic) {
     43    public ManipulationContent(IManipulationLogic theManipulationLogic, ISearchLogic theSearchLogic, IFilterLogic theFitlerLogic) {
    4644      manipulationLogic = theManipulationLogic;
    4745      searchLogic = theSearchLogic;
    48       dataGridLogic = theDataGridLogic;
    4946      filterLogic = theFitlerLogic;
    5047    }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/ManipulationLogic.cs

    r10820 r11002  
    3030    private IStatisticsLogic statisticsLogic;
    3131    private ISearchLogic searchLogic;
    32     private IDataGridLogic dataGridLogic;
    33 
    34     public ManipulationLogic(ITransactionalPreprocessingData _prepocessingData, ISearchLogic theSearchLogic, IStatisticsLogic theStatisticsLogic, IDataGridLogic theDataGridLogic) {
     32
     33    public IEnumerable<string> VariableNames {
     34      get { return preprocessingData.VariableNames; }
     35    }
     36
     37    public ITransactionalPreprocessingData PreProcessingData {
     38      get { return preprocessingData; }
     39    }
     40
     41    public ManipulationLogic(ITransactionalPreprocessingData _prepocessingData, ISearchLogic theSearchLogic, IStatisticsLogic theStatisticsLogic) {
    3542      preprocessingData = _prepocessingData;
    3643      searchLogic = theSearchLogic;
    3744      statisticsLogic = theStatisticsLogic;
    38       dataGridLogic = theDataGridLogic;
    3945    }
    4046
     
    316322        foreach (var column in cells) {
    317323          foreach (var rowIdx in column.Value) {
    318             dataGridLogic.SetValue(value, column.Key, rowIdx);
     324            preprocessingData.SetValue(value, column.Key, rowIdx);
    319325          }
    320326        }
     
    396402    }
    397403
    398     public event DataPreprocessingChangedEventHandler Changed {
    399       add { dataGridLogic.Changed += value; }
    400       remove { dataGridLogic.Changed -= value; }
    401     }
     404    public event DataPreprocessingChangedEventHandler Changed;
    402405  }
    403406}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs

    r10994 r11002  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.Globalization;
    2526using System.Linq;
    2627using HeuristicLab.Common;
     
    9596      selection = new Dictionary<int, IList<int>>();
    9697
     98      Dataset dataset = problemData.Dataset;
    9799      variableNames = new List<string>(problemData.Dataset.VariableNames);
    98100
     
    100102      variableValues = new List<IList>();
    101103      foreach (var variableName in problemData.Dataset.VariableNames) {
    102         if (problemData.Dataset.IsType<double>(variableName)) {
    103           variableValues.Insert(columnIndex, problemData.Dataset.GetDoubleValues(variableName).ToList());
    104         } else if (problemData.Dataset.IsType<string>(variableName)) {
    105           variableValues.Insert(columnIndex, CreateColumn<string>(problemData.Dataset, columnIndex, x => x));
    106         } else if (problemData.Dataset.IsType<DateTime>(variableName)) {
    107           variableValues.Insert(columnIndex, CreateColumn<DateTime>(problemData.Dataset, columnIndex, x => DateTime.Parse(x)));
     104        if (dataset.IsType<double>(variableName)) {
     105          variableValues.Insert(columnIndex, dataset.GetDoubleValues(variableName).ToList());
     106        } else if (dataset.IsType<string>(variableName)) {
     107          variableValues.Insert(columnIndex, dataset.GetStringValues(variableName).ToList());
     108        } else if (dataset.IsType<DateTime>(variableName)) {
     109          variableValues.Insert(columnIndex, dataset.GetDateTimeValues(variableName).ToList());
    108110        } else {
    109111          throw new ArgumentException("The datatype of column " + variableName + " must be of type double, string or DateTime");
     
    180182    public abstract void SetValues<T>(int columnIndex, IList<T> values);
    181183
     184    public abstract bool SetValue(string value, int columnIndex, int rowIndex);
     185
     186    public abstract bool Validate(string value, out string errorMessage, int columnIndex);
     187
     188    public abstract bool AreAllStringColumns(IEnumerable<int> columnIndices);
     189
     190    public abstract void DeleteRowsWithIndices(IEnumerable<int> rows);
     191
    182192    public abstract void InsertRow(int rowIndex);
    183193
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/SearchLogic.cs

    r10978 r11002  
    3131    private Dictionary<int, IList<int>> MissingValueIndicies { get; set; }
    3232    private Dictionary<int, IList> ValuesWithoutNaN { get; set; }
     33
     34    public IEnumerable<string> VariableNames {
     35      get { return preprocessingData.VariableNames; }
     36    }
     37
     38    public int Columns {
     39      get { return preprocessingData.Columns; }
     40    }
     41
     42    public int Rows {
     43      get { return preprocessingData.Rows; }
     44    }
    3345
    3446    public SearchLogic(ITransactionalPreprocessingData thePreprocessingData) {
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs

    r10994 r11002  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.Globalization;
     26using System.Linq;
    2527using HeuristicLab.Common;
    2628using HeuristicLab.Core;
     
    159161      if (!IsInTransaction)
    160162        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
     163    }
     164
     165    public override bool SetValue(string value, int columnIndex, int rowIndex) {
     166      bool valid = false;
     167      if (IsType<double>(columnIndex)) {
     168        double val;
     169        valid = double.TryParse(value, out val);
     170        SetValueIfValid(columnIndex, rowIndex, valid, val);
     171      } else if (IsType<string>(columnIndex)) {
     172        valid = value != null;
     173        SetValueIfValid(columnIndex, rowIndex, valid, value);
     174      } else if (IsType<DateTime>(columnIndex)) {
     175        DateTime date;
     176        valid = DateTime.TryParse(value, out date);
     177        SetValueIfValid(columnIndex, rowIndex, valid, date);
     178      } else {
     179        throw new ArgumentException("column " + columnIndex + " contains a non supported type.");
     180      }
     181
     182      if (!IsInTransaction)
     183        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
     184
     185      return valid;
     186    }
     187   
     188    public override bool Validate(string value, out string errorMessage, int columnIndex){
     189     if (columnIndex < 0 || columnIndex > VariableNames.Count()) {
     190        throw new ArgumentOutOfRangeException("column index is out of range");
     191      }
     192
     193      bool valid = false;
     194      errorMessage = string.Empty;
     195      if (IsType<double>(columnIndex)) {
     196        double val;
     197        valid = double.TryParse(value, out val);
     198        if (!valid) {
     199          errorMessage = "Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")";
     200        }
     201      } else if (IsType<string>(columnIndex)) {
     202        valid = value != null;
     203        if (!valid) {
     204          errorMessage = "Invalid Value (string must not be null)";
     205        }
     206      } else if (IsType<DateTime>(columnIndex)) {
     207        DateTime date;
     208        valid = DateTime.TryParse(value, out date);
     209        if (!valid) {
     210          errorMessage = "Invalid Value (Valid Value Format: \"" + CultureInfo.CurrentCulture.DateTimeFormat + "\"";
     211        }
     212      } else {
     213        throw new ArgumentException("column " + columnIndex + " contains a non supported type.");
     214      }
     215
     216      return valid;
     217    }
     218
     219    private void SetValueIfValid<T>(int columnIndex, int rowIndex, bool valid, T value) {
     220      if (valid)
     221        SetCell<T>(columnIndex, rowIndex, value);
     222    }
     223
     224    public override bool AreAllStringColumns(IEnumerable<int> columnIndices) {
     225      return columnIndices.All(x => IsType<string>(x));
     226    }
     227
     228    public override void DeleteRowsWithIndices(IEnumerable<int> rows) {
     229      foreach (int rowIndex in rows) {
     230        DeleteRow(rowIndex);
     231      }
    161232    }
    162233
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IDataGridContent.cs

    r10809 r11002  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Data;
    2324
    2425namespace HeuristicLab.DataPreprocessing {
    2526  public interface IDataGridContent : IStringConvertibleMatrix {
    26     IDataGridLogic DataGridLogic { get; }
     27    ITransactionalPreprocessingData PreProcessingData { get; }
    2728    IManipulationLogic ManipulationLogic { get; }
    2829    IFilterLogic FilterLogic { get; }
     30
     31    IDictionary<int, IList<int>> Selection { get; set; }
     32
     33    void DeleteRow(IEnumerable<int> rows);
     34    bool Validate(string value, out string errorMessage, int columnIndex);
    2935
    3036    event DataPreprocessingChangedEventHandler Changed;
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IDataGridLogic.cs

    r10804 r11002  
    4040    void DeleteRow(List<int> rows);
    4141
    42     void SetSelection(IDictionary<int, IList<int>> selection);
    43     IDictionary<int, IList<int>> GetSelection();
     42    IDictionary<int, IList<int>> Selection { get; set; }
    4443    void ClearSelection();
    4544
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IFilterLogic.cs

    r10930 r11002  
    2323using System.Collections.Generic;
    2424using HeuristicLab.DataPreprocessing.Filter;
     25using HeuristicLab.DataPreprocessing.Interfaces;
    2526namespace HeuristicLab.DataPreprocessing {
    2627  public interface IFilterLogic {
     
    3435    bool[] Preview(IList<IFilter> filters, bool isAndCombination);
    3536    void Apply(IList<IFilter> filters, bool isAndCombination);
    36     IPreprocessingData PreprocessingData { get; }
     37    IFilteredPreprocessingData PreprocessingData { get; }
    3738    void Reset();
    3839    bool IsFiltered { get; }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IManipulationLogic.cs

    r10820 r11002  
    2525namespace HeuristicLab.DataPreprocessing {
    2626  public interface IManipulationLogic {
     27    IEnumerable<string> VariableNames { get; }
     28    ITransactionalPreprocessingData PreProcessingData { get; }
    2729    void ReOrderToIndices(IEnumerable<int> indices);
    2830    void ReOrderToIndices(IList<Tuple<int, int>> indices);
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IPreprocessingData.cs

    r10992 r11002  
    4141
    4242    void SetValues<T>(int columnIndex, IList<T> values);
     43    bool SetValue(string value, int columnIndex, int rowIndex);
    4344
    4445    void InsertRow(int rowIndex);
    4546    void DeleteRow(int rowIndex);
    46 
     47    void DeleteRowsWithIndices(IEnumerable<int> rows);
    4748    void InsertColumn<T>(string variableName, int columnIndex);
    4849
    4950    void DeleteColumn(int columnIndex);
    5051
    51     IntRange TrainingPartition { get; }
     52    bool AreAllStringColumns(IEnumerable<int> columnIndices);
     53    bool Validate(string value, out string errorMessage, int columnIndex);
     54   
     55      IntRange TrainingPartition { get; }
    5256    IntRange TestPartition { get; }
    5357
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/ISearchLogic.cs

    r10811 r11002  
    2424namespace HeuristicLab.DataPreprocessing {
    2525  public interface ISearchLogic {
     26
     27    int Rows { get; }
     28    int Columns { get; }
     29    IEnumerable<string> VariableNames { get; }
     30
    2631    /// <summary>
    2732    /// Return the indices of the missing values where the key
Note: See TracChangeset for help on using the changeset viewer.