Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7337


Ignore:
Timestamp:
01/16/12 17:04:53 (12 years ago)
Author:
sforsten
Message:

#1752: some methods were added to Dataset to easier obtain string and Datetime values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r7290 r7337  
    155155    }
    156156
     157    #region Double
    157158    public IEnumerable<string> DoubleVariables {
    158159      get { return variableValues.Where(p => p.Value is List<double>).Select(p => p.Key); }
     
    196197        yield return values[index];
    197198    }
     199    #endregion
     200
     201    #region String
     202    public IEnumerable<string> StringVariables {
     203      get { return variableValues.Where(p => p.Value is List<string>).Select(p => p.Key); }
     204    }
     205
     206    public IEnumerable<string> GetStringValues(string variableName) {
     207      IList list;
     208      if (!variableValues.TryGetValue(variableName, out list))
     209        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     210      List<string> values = list as List<string>;
     211      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a string variable.");
     212
     213      //mkommend yield return used to enable lazy evaluation
     214      foreach (string value in values)
     215        yield return value;
     216    }
     217    public ReadOnlyCollection<string> GetReadOnlyStringValues(string variableName) {
     218      IList list;
     219      if (!variableValues.TryGetValue(variableName, out list))
     220        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     221      List<string> values = list as List<string>;
     222      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a string variable.");
     223      return values.AsReadOnly();
     224    }
     225    public string GetStringValue(string variableName, int row) {
     226      IList list;
     227      if (!variableValues.TryGetValue(variableName, out list))
     228        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     229      List<string> values = list as List<string>;
     230      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a string variable.");
     231      return values[row];
     232    }
     233    public IEnumerable<string> GetStringValues(string variableName, IEnumerable<int> rows) {
     234      IList list;
     235      if (!variableValues.TryGetValue(variableName, out list))
     236        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     237      List<string> values = list as List<string>;
     238      if (values == null) throw new ArgumentException("The varialbe " + variableName + " is not a string variable.");
     239
     240      foreach (int index in rows)
     241        yield return values[index];
     242    }
     243    #endregion
     244
     245    #region DateTime
     246    public IEnumerable<string> DateTimeVariables {
     247      get { return variableValues.Where(p => p.Value is List<DateTime>).Select(p => p.Key); }
     248    }
     249
     250    public IEnumerable<DateTime> GetDateTimeValues(string variableName) {
     251      IList list;
     252      if (!variableValues.TryGetValue(variableName, out list))
     253        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     254      List<DateTime> values = list as List<DateTime>;
     255      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a DateTime variable.");
     256
     257      //mkommend yield return used to enable lazy evaluation
     258      foreach (DateTime value in values)
     259        yield return value;
     260    }
     261    public ReadOnlyCollection<DateTime> GetReadOnlyDateTimeValues(string variableName) {
     262      IList list;
     263      if (!variableValues.TryGetValue(variableName, out list))
     264        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     265      List<DateTime> values = list as List<DateTime>;
     266      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a DateTime variable.");
     267      return values.AsReadOnly();
     268    }
     269    public DateTime GetDateTimeValue(string variableName, int row) {
     270      IList list;
     271      if (!variableValues.TryGetValue(variableName, out list))
     272        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     273      List<DateTime> values = list as List<DateTime>;
     274      if (values == null) throw new ArgumentException("The variable " + variableName + " is not a DateTime variable.");
     275      return values[row];
     276    }
     277    public IEnumerable<DateTime> GetDateTimeValues(string variableName, IEnumerable<int> rows) {
     278      IList list;
     279      if (!variableValues.TryGetValue(variableName, out list))
     280        throw new ArgumentException("The variable " + variableName + " does not exist in the dataset.");
     281      List<DateTime> values = list as List<DateTime>;
     282      if (values == null) throw new ArgumentException("The varialbe " + variableName + " is not a DateTime variable.");
     283
     284      foreach (int index in rows)
     285        yield return values[index];
     286    }
     287    #endregion
    198288
    199289    #region IStringConvertibleMatrix Members
Note: See TracChangeset for help on using the changeset viewer.