- Timestamp:
- 10/18/18 16:16:31 (6 years ago)
- Location:
- branches/2915-AbsoluteSymbol
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2915-AbsoluteSymbol
- Property svn:mergeinfo changed
-
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis (added) merged: 16057,16092 /trunk/HeuristicLab.Problems.DataAnalysis (added) merged: 16059,16063,16084,16117-16118,16120
- Property svn:mergeinfo changed
-
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r15829 r16240 116 116 117 117 public ModifiableDataset ToModifiable() { 118 var values = new List<IList>(); 119 foreach (var v in variableNames) { 120 if (VariableHasType<double>(v)) { 121 values.Add(new List<double>((IList<double>)variableValues[v])); 122 } else if (VariableHasType<string>(v)) { 123 values.Add(new List<string>((IList<string>)variableValues[v])); 124 } else if (VariableHasType<DateTime>(v)) { 125 values.Add(new List<DateTime>((IList<DateTime>)variableValues[v])); 126 } else { 127 throw new ArgumentException("Unknown variable type."); 128 } 129 } 130 return new ModifiableDataset(variableNames, values); 118 return new ModifiableDataset(variableNames, variableNames.Select(v => variableValues[v]), true); 131 119 } 132 120 … … 141 129 } 142 130 143 protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { } 131 144 132 145 133 #region Backwards compatible code, remove with 3.5 … … 318 306 #region IStringConvertibleMatrix Members 319 307 [Storable] 320 pr otectedint rows;308 private int rows; 321 309 public int Rows { 322 310 get { return rows; } 311 protected set { rows = value; } 323 312 } 324 313 int IStringConvertibleMatrix.Rows { -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r15583 r16240 163 163 164 164 var variables = dataset.VariableNames.Where(variable => dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable)); 165 var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x) ));165 var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x).AsReadOnly())); 166 166 foreach (StringValue x in inputVariables) 167 167 inputVariables.SetItemCheckedState(x, allowedInputVariables.Contains(x.Value)); -
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
r15829 r16240 47 47 public ModifiableDataset() { } 48 48 49 public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) : 50 base(variableNames, variableValues, cloneValues: false) { } 49 public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues, bool cloneValues = false) : 50 base(variableNames, variableValues, cloneValues) { } 51 52 public Dataset ToDataset() { 53 return new Dataset(variableNames, variableNames.Select(v => variableValues[v])); 54 } 55 56 57 public IEnumerable<object> GetRow(int row) { 58 return variableValues.Select(x => x.Value[row]); 59 } 60 61 public void AddRow(IEnumerable<object> values) { 62 var list = values.ToList(); 63 if (list.Count != variableNames.Count) 64 throw new ArgumentException("The number of values must be equal to the number of variable names."); 65 // check if all the values are of the correct type 66 for (int i = 0; i < list.Count; ++i) { 67 if (list[i].GetType() != GetVariableType(variableNames[i])) { 68 throw new ArgumentException("The type of the provided value does not match the variable type."); 69 } 70 } 71 // add values 72 for (int i = 0; i < list.Count; ++i) { 73 variableValues[variableNames[i]].Add(list[i]); 74 } 75 Rows++; 76 OnRowsChanged(); 77 OnReset(); 78 } 51 79 52 80 public void ReplaceRow(int row, IEnumerable<object> values) { … … 64 92 variableValues[variableNames[i]][row] = list[i]; 65 93 } 94 OnReset(); 95 } 96 97 // slow, avoid using this 98 public void RemoveRow(int row) { 99 foreach (var list in variableValues.Values) 100 list.RemoveAt(row); 101 Rows--; 102 OnRowsChanged(); 103 OnReset(); 104 } 105 106 // adds a new variable to the dataset 107 public void AddVariable(string variableName, IList values) { 108 InsertVariable(variableName, Columns, values); 109 } 110 111 public void InsertVariable(string variableName, int position, IList values) { 112 if (variableValues.ContainsKey(variableName)) 113 throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName)); 114 115 if (position < 0 || position > Columns) 116 throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns)); 117 118 if (values == null) 119 throw new ArgumentNullException("values", "Values must not be null. At least an empty list of values has to be provided."); 120 121 if (values.Count != Rows) 122 throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows)); 123 124 if (!IsAllowedType(values)) 125 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName)); 126 127 variableNames.Insert(position, variableName); 128 variableValues[variableName] = values; 129 130 OnColumnsChanged(); 131 OnColumnNamesChanged(); 66 132 OnReset(); 67 133 } … … 77 143 } 78 144 79 public void AddRow(IEnumerable<object> values) {80 var list = values.ToList();81 if (list.Count != variableNames.Count)82 throw new ArgumentException("The number of values must be equal to the number of variable names.");83 // check if all the values are of the correct type84 for (int i = 0; i < list.Count; ++i) {85 if (list[i].GetType() != GetVariableType(variableNames[i])) {86 throw new ArgumentException("The type of the provided value does not match the variable type.");87 }88 }89 // add values90 for (int i = 0; i < list.Count; ++i) {91 variableValues[variableNames[i]].Add(list[i]);92 }93 rows++;94 OnRowsChanged();95 OnReset();96 }97 98 // adds a new variable to the dataset99 public void AddVariable(string variableName, IList values) {100 if (variableValues.ContainsKey(variableName))101 throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));102 103 if (values == null || values.Count == 0)104 throw new ArgumentException("Cannot add variable with no values.");105 106 if (!IsAllowedType(values))107 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));108 109 variableValues[variableName] = values;110 variableNames.Add(variableName);111 112 OnColumnsChanged();113 OnColumnNamesChanged();114 OnReset();115 }116 145 117 146 public void RemoveVariable(string variableName) { … … 125 154 } 126 155 127 // slow, avoid using this128 public void RemoveRow(int row) {129 foreach (var list in variableValues.Values)130 list.RemoveAt(row);131 rows--;156 public void ClearValues() { 157 foreach (var list in variableValues.Values) { 158 list.Clear(); 159 } 160 Rows = 0; 132 161 OnRowsChanged(); 133 162 OnReset(); 134 163 } 164 135 165 136 166 public void SetVariableValue(object value, string variableName, int row) {
Note: See TracChangeset
for help on using the changeset viewer.