Changeset 8387
- Timestamp:
- 08/02/12 14:48:20 (12 years ago)
- Location:
- branches/HeuristicLab.DataImporter
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeColumnGroup/SplitDictionaryStyleDataCommand.cs
r7267 r8387 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Text;26 25 using HeuristicLab.DataImporter.Data; 27 26 using HeuristicLab.DataImporter.Data.CommandBase; … … 32 31 [StorableClass] 33 32 [ViewableCommandInfo("Split Dictionary-style Data", 1, ColumnGroupState.ColumnSelected | ColumnGroupState.Sorted, "Column Commands", 34 Position = 15 , SelectedColumns = 2)]33 Position = 15)] 35 34 public class SplitDictionaryStyleDataCommand : ColumnGroupCommandWithAffectedColumnsBase { 36 35 private int addedColumnsCount; … … 50 49 public override void Execute() { 51 50 base.Execute(); 52 Dictionary<IComparable, ColumnBase> newColumns = new Dictionary<IComparable, ColumnBase>(); ;53 51 if (ColumnGroup.SortedColumnIndexes.Except(AffectedColumns).Count() != 1 && 54 52 ColumnGroup.SortedColumnIndexes.Except(AffectedColumns).FirstOrDefault() == ColumnGroup.SortedColumnIndexes.ElementAt(0)) … … 56 54 if (AffectedColumns.Intersect(ColumnGroup.SortedColumnIndexes).Count() != 1) 57 55 throw new CommandExecutionException("Exactly one column must be sorted and selected to define the column which holds the grouping value.", this); 58 if ( AffectedColumns.Except(ColumnGroup.SortedColumnIndexes).Count() != 1)56 if (!AffectedColumns.Except(ColumnGroup.SortedColumnIndexes).Any()) 59 57 throw new CommandExecutionException("At least one column must not be sorted but selected to define the column which holds the values for new columns.", this); 60 58 61 ColumnBase equalityColumn = ColumnGroup.GetColumn(ColumnGroup.SortedColumnIndexes.Except(AffectedColumns).ElementAt(0)); 62 if (equalityColumn.ContainsNullValues) 63 throw new CommandExecutionException("Column which defines the equality (" + equalityColumn.Name + ") must not contain NULL values.", this); 59 Dictionary<IComparable, List<ColumnBase>> newColumns = new Dictionary<IComparable, List<ColumnBase>>(); 64 60 65 ColumnBase groupColumn = ColumnGroup.GetColumn(ColumnGroup.SortedColumnIndexes. Intersect(AffectedColumns).ElementAt(0));66 ColumnBase valueColumn = ColumnGroup.GetColumn(AffectedColumns.Except(ColumnGroup.SortedColumnIndexes).ElementAt(0));61 ColumnBase groupColumn = ColumnGroup.GetColumn(ColumnGroup.SortedColumnIndexes.Except(AffectedColumns).First()); 62 if (groupColumn.ContainsNullValues) throw new CommandExecutionException("Column which defines the equality (" + groupColumn.Name + ") must not contain NULL values.", this); 67 63 68 IComparable equalityValue = equalityColumn.GetValue(0); ; 69 IComparable groupValue; 64 ColumnBase splitColumn = ColumnGroup.GetColumn(ColumnGroup.SortedColumnIndexes.Intersect(AffectedColumns).First()); 65 var valueColumns = AffectedColumns.Except(ColumnGroup.SortedColumnIndexes).Select(index => ColumnGroup.GetColumn(index)).ToList(); 66 67 IComparable groupValue = groupColumn.GetValue(0); ; 68 IComparable splitValue; 70 69 int groupStartIndex = 0; 71 70 for (int row = 0; row < ColumnGroup.RowCount; row++) { 72 71 //check if equality value is still the same 73 if ( equalityValue.CompareTo(equalityColumn.GetValue(row)) != 0) {74 equalityValue = equalityColumn.GetValue(row);72 if (groupValue.CompareTo(groupColumn.GetValue(row)) != 0) { 73 groupValue = groupColumn.GetValue(row); 75 74 groupStartIndex = row; 76 75 } 77 groupValue = groupColumn.GetValue(row); 76 splitValue = splitColumn.GetValue(row); 77 78 78 //create new column if new group value was detected 79 if (!newColumns.ContainsKey(groupValue)) { 80 newColumns.Add(groupValue, valueColumn.CreateCopyOfColumnWithoutValues()); 81 newColumns[groupValue].Resize(ColumnGroup.RowCount); 82 newColumns[groupValue].Name += "_" + groupValue; 79 if (!newColumns.ContainsKey(splitValue)) { 80 newColumns.Add(splitValue, new List<ColumnBase>(valueColumns.Count)); 81 int i = 0; 82 foreach (var valueColumn in valueColumns) { 83 var newColumn = valueColumn.CreateCopyOfColumnWithoutValues(valueColumn.TotalValuesCount); 84 newColumn.Name += "_" + splitValue; 85 newColumn.Resize(ColumnGroup.RowCount); 86 newColumns[splitValue].Add(newColumn); 87 i++; 88 } 83 89 } 84 90 85 for (int i = groupStartIndex; i < row; i++) 86 newColumns[groupValue].ChangeValue(i, valueColumn.GetValue(row)); 87 for (int i = row; i < ColumnGroup.RowCount && equalityValue.CompareTo(equalityColumn.GetValue(i)) == 0; i++) 88 newColumns[groupValue].ChangeValue(i, valueColumn.GetValue(row)); 91 92 for (int i = groupStartIndex; i < ColumnGroup.RowCount && groupValue.CompareTo(groupColumn.GetValue(i)) == 0; i++) { 93 for (int col = 0; col < valueColumns.Count; col++) 94 newColumns[splitValue][col].ChangeValue(i, valueColumns[col].GetValue(row)); 95 } 89 96 } 90 97 91 ColumnGroup.AddColumns(newColumns.Values );92 addedColumnsCount = newColumns. Count;98 ColumnGroup.AddColumns(newColumns.Values.SelectMany(col => col)); 99 addedColumnsCount = newColumns.Values.Sum(columns => columns.Count); 93 100 this.ColumnGroup.FireChanged(); 94 101 this.ColumnGroup = null; -
branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Command/DeleteColumnCommand.cs
r7625 r8387 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; 25 using System.Text;26 24 using System.Windows.Forms; 27 25 using HeuristicLab.DataImporter.Data.CommandBase; … … 51 49 52 50 ColumnBase column; 53 foreach (int columnIndex in AffectedColumns. Reverse()) {51 foreach (int columnIndex in AffectedColumns.OrderByDescending(i => i)) { 54 52 column = ColumnGroup.GetColumn(columnIndex); 55 53 deletedColumns.Insert(0, column); -
branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/CommandBase/ColumnGroupCommandBase.cs
r7267 r8387 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using System.Linq; 25 using System.Text;26 using System.Xml;27 23 using HeuristicLab.DataImporter.Data.Model; 28 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 47 43 48 44 protected void UpdateColumnGroup() { 49 this.columnGroup = this.DataSet.ColumnGroups. Where(cg => cg.Name == this.columnGroupName).FirstOrDefault();45 this.columnGroup = this.DataSet.ColumnGroups.FirstOrDefault(cg => cg.Name == this.columnGroupName); 50 46 } 51 47 -
branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Model/ColumnBase.cs
r7267 r8387 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Collections; 25 using System.Linq;26 using System.Text;27 using System.Xml;28 using System.Globalization;29 24 using System.Windows.Forms; 30 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
Note: See TracChangeset
for help on using the changeset viewer.