Changeset 16247
- Timestamp:
- 10/22/18 09:17:44 (6 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 16084,16118,16120,16242
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis merged: 16084,16118,16120,16242
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs
r16125 r16247 116 116 117 117 public ModifiableDataset ToModifiable() { 118 return new ModifiableDataset(variableNames, variableNames.Select(v => variableValues[v]), true);118 return new ModifiableDataset(variableNames, variableNames.Select(v => variableValues[v]), true); 119 119 } 120 120 -
stable/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs
r16125 r16247 53 53 return new Dataset(variableNames, variableNames.Select(v => variableValues[v])); 54 54 } 55 56 57 public IEnumerable<object> GetRow(int row) { 58 if (row < 0 || row >= Rows) 59 throw new ArgumentException(string.Format("Invalid row {0} specified. The dataset contains {1} row(s).", row, Rows)); 60 61 return variableValues.Select(x => x.Value[row]); 62 } 63 64 public void AddRow(IEnumerable<object> values) { 65 var list = values.ToList(); 66 if (list.Count != variableNames.Count) 67 throw new ArgumentException("The number of values must be equal to the number of variable names."); 68 // check if all the values are of the correct type 69 for (int i = 0; i < list.Count; ++i) { 70 if (list[i].GetType() != GetVariableType(variableNames[i])) { 71 throw new ArgumentException("The type of the provided value does not match the variable type."); 72 } 73 } 74 // add values 75 for (int i = 0; i < list.Count; ++i) { 76 variableValues[variableNames[i]].Add(list[i]); 77 } 78 Rows++; 79 OnRowsChanged(); 80 OnReset(); 81 } 82 55 83 public void ReplaceRow(int row, IEnumerable<object> values) { 56 84 var list = values.ToList(); … … 67 95 variableValues[variableNames[i]][row] = list[i]; 68 96 } 97 OnReset(); 98 } 99 100 // slow, avoid using this 101 public void RemoveRow(int row) { 102 foreach (var list in variableValues.Values) 103 list.RemoveAt(row); 104 Rows--; 105 OnRowsChanged(); 106 OnReset(); 107 } 108 109 // adds a new variable to the dataset 110 public void AddVariable(string variableName, IList values) { 111 InsertVariable(variableName, Columns, values); 112 } 113 114 public void InsertVariable(string variableName, int position, IList values) { 115 if (variableValues.ContainsKey(variableName)) 116 throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName)); 117 118 if (position < 0 || position > Columns) 119 throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns)); 120 121 if (values == null) 122 throw new ArgumentNullException("values", "Values must not be null. At least an empty list of values has to be provided."); 123 124 if (values.Count != Rows) 125 throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows)); 126 127 if (!IsAllowedType(values)) 128 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName)); 129 130 variableNames.Insert(position, variableName); 131 variableValues[variableName] = values; 132 133 OnColumnsChanged(); 134 OnColumnNamesChanged(); 69 135 OnReset(); 70 136 } … … 80 146 } 81 147 82 public void AddRow(IEnumerable<object> values) {83 var list = values.ToList();84 if (list.Count != variableNames.Count)85 throw new ArgumentException("The number of values must be equal to the number of variable names.");86 // check if all the values are of the correct type87 for (int i = 0; i < list.Count; ++i) {88 if (list[i].GetType() != GetVariableType(variableNames[i])) {89 throw new ArgumentException("The type of the provided value does not match the variable type.");90 }91 }92 // add values93 for (int i = 0; i < list.Count; ++i) {94 variableValues[variableNames[i]].Add(list[i]);95 }96 Rows++;97 OnRowsChanged();98 OnReset();99 }100 101 // adds a new variable to the dataset102 public void AddVariable(string variableName, IList values) {103 if (variableValues.ContainsKey(variableName))104 throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));105 106 if (values == null || values.Count == 0)107 throw new ArgumentException("Cannot add variable with no values.");108 109 if (values.Count != Rows)110 throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows));111 112 if (!IsAllowedType(values))113 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));114 115 variableValues[variableName] = values;116 variableNames.Add(variableName);117 118 OnColumnsChanged();119 OnColumnNamesChanged();120 OnReset();121 }122 123 124 public void InsertVariable(string variableName, int position, IList values) {125 if (variableValues.ContainsKey(variableName))126 throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));127 128 if (position < 0 || position > Columns)129 throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns));130 131 if (values == null || values.Count == 0)132 throw new ArgumentException("Cannot add variable with no values.");133 134 if (values.Count != Rows)135 throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows));136 137 if (!IsAllowedType(values))138 throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));139 140 variableNames.Insert(position, variableName);141 variableValues[variableName] = values;142 143 OnColumnsChanged();144 OnColumnNamesChanged();145 OnReset();146 }147 148 148 149 public void RemoveVariable(string variableName) { … … 156 157 } 157 158 158 // slow, avoid using this159 public void RemoveRow(int row) {160 foreach (var list in variableValues.Values)161 list.RemoveAt(row);162 Rows --;159 public void ClearValues() { 160 foreach (var list in variableValues.Values) { 161 list.Clear(); 162 } 163 Rows = 0; 163 164 OnRowsChanged(); 164 165 OnReset(); 165 166 } 167 166 168 167 169 public void SetVariableValue(object value, string variableName, int row) {
Note: See TracChangeset
for help on using the changeset viewer.