Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/29/18 09:44:07 (6 years ago)
Author:
jkarder
Message:

#2839: merged [16057-16091/trunk] into branch

Location:
branches/2839_HiveProjectManagement
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement

  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis

  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r16057 r16092  
    116116
    117117    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);
    131119    }
    132120
     
    141129    }
    142130
    143     protected Dataset(Dataset dataset) : this(dataset.variableNames, dataset.variableValues.Values) { }
     131
    144132
    145133    #region Backwards compatible code, remove with 3.5
     
    318306    #region IStringConvertibleMatrix Members
    319307    [Storable]
    320     protected int rows;
     308    private int rows;
    321309    public int Rows {
    322310      get { return rows; }
     311      protected set { rows = value; }
    323312    }
    324313    int IStringConvertibleMatrix.Rows {
  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r16057 r16092  
    163163
    164164      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()));
    166166      foreach (StringValue x in inputVariables)
    167167        inputVariables.SetItemCheckedState(x, allowedInputVariables.Contains(x.Value));
  • branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r16057 r16092  
    4747    public ModifiableDataset() { }
    4848
    49     public ModifiableDataset(IEnumerable<string> variableNames, IEnumerable<IList> variableValues) :
    50       base(variableNames, variableValues, cloneValues: false) { }
    51 
     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    }
    5255    public void ReplaceRow(int row, IEnumerable<object> values) {
    5356      var list = values.ToList();
     
    9194        variableValues[variableNames[i]].Add(list[i]);
    9295      }
    93       rows++;
     96      Rows++;
    9497      OnRowsChanged();
    9598      OnReset();
     
    98101    // adds a new variable to the dataset
    99102    public void AddVariable(string variableName, IList values) {
     103      InsertVariable(variableName, Columns, values);
     104    }
     105
     106
     107    public void InsertVariable(string variableName, int position, IList values) {
    100108      if (variableValues.ContainsKey(variableName))
    101109        throw new ArgumentException(string.Format("Variable {0} is already present in the dataset.", variableName));
    102110
    103       if (values == null || values.Count == 0)
    104         throw new ArgumentException("Cannot add variable with no values.");
     111      if (position < 0 || position > Columns)
     112        throw new ArgumentException(string.Format("Incorrect position {0} specified. The position must be between 0 and {1}.", position, Columns));
     113
     114      if (values == null)
     115        throw new ArgumentNullException("values", "Values must not be null. At least an empty list of values has to be provided.");
     116
     117      if (values.Count != Rows)
     118        throw new ArgumentException(string.Format("{0} values are provided, but {1} rows are present in the dataset.", values.Count, Rows));
    105119
    106120      if (!IsAllowedType(values))
    107121        throw new ArgumentException(string.Format("Unsupported type {0} for variable {1}.", GetElementType(values), variableName));
    108122
     123      variableNames.Insert(position, variableName);
    109124      variableValues[variableName] = values;
    110       variableNames.Add(variableName);
    111125
    112126      OnColumnsChanged();
     
    129143      foreach (var list in variableValues.Values)
    130144        list.RemoveAt(row);
    131       rows--;
     145      Rows--;
    132146      OnRowsChanged();
    133147      OnReset();
Note: See TracChangeset for help on using the changeset viewer.