Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7741


Ignore:
Timestamp:
04/18/12 20:01:42 (12 years ago)
Author:
ascheibe
Message:

#1174

  • prevent uploading of double parameters/results that are NaN
  • when adding a run don't generate duplicate binary datas
Location:
branches/OKB (trunk integration)
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBRun.cs

    r7634 r7741  
    190190    List<Value> ConvertToValues(IDictionary<string, IItem> items) {
    191191      List<Value> values = new List<Value>();
     192      bool add = true;
    192193      foreach (var item in items) {
    193194        Value value;
     
    208209          v.Value = ((Data.PercentValue)item.Value).Value;
    209210          value = v;
     211          if (double.IsNaN(v.Value)) {
     212            add = false;
     213          }
    210214        } else if (item.Value is Data.DoubleValue) {
    211215          DoubleValue v = new DoubleValue();
    212216          v.Value = ((Data.DoubleValue)item.Value).Value;
    213217          value = v;
     218          if (double.IsNaN(v.Value)) {
     219            add = false;
     220          }
    214221        } else if (item.Value is Data.StringValue) {
    215222          StringValue v = new StringValue();
     
    225232          value = v;
    226233        }
    227         value.Name = item.Key;
    228         value.DataType = new DataType();
    229         value.DataType.Name = item.Value.GetType().Name;
    230         value.DataType.TypeName = item.Value.GetType().AssemblyQualifiedName;
    231         values.Add(value);
     234        if (add) {
     235          value.Name = item.Key;
     236          value.DataType = new DataType();
     237          value.DataType.Name = item.Value.GetType().Name;
     238          value.DataType.TypeName = item.Value.GetType().AssemblyQualifiedName;
     239          values.Add(value);
     240        } else {
     241          add = true;
     242        }
    232243      }
    233244      return values;
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs

    r7574 r7741  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Security.Cryptography;
     
    5859    public static DA.Run ToEntity(DT.Run source, DA.OKBDataContext okb) {
    5960      if (source == null) return null;
     61
     62      List<DA.BinaryData> binCache = new List<DA.BinaryData>();
     63
    6064      DA.Run entity = new DA.Run { Id = 0, AlgorithmId = source.AlgorithmId, ProblemId = source.ProblemId, CreatedDate = source.CreatedDate, UserId = source.UserId, ClientId = source.ClientId };
    6165      foreach (var value in source.ParameterValues)
    62         entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Parameter, okb));
     66        entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Parameter, okb, binCache));
    6367      foreach (var value in source.ResultValues)
    64         entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb));
     68        entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb, binCache));
    6569      return entity;
    6670    }
    6771
    68     private static DA.Value ToEntity(DT.Value source, DA.Run run, DA.ValueNameCategory category, DA.OKBDataContext okb) {
     72    private static DA.Value ToEntity(DT.Value source, DA.Run run, DA.ValueNameCategory category, DA.OKBDataContext okb, List<DA.BinaryData> binCache) {
    6973      if (source == null) return null;
    7074      var entity = new DA.Value();
     
    97101      } else if (source is DT.BinaryValue) {
    98102        entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Binary, okb);
    99         entity.BinaryData = Convert.ToEntity(((DT.BinaryValue)source).Value, okb);
     103        entity.BinaryData = Convert.ToEntity(((DT.BinaryValue)source).Value, okb, binCache);
    100104      } else {
    101105        throw new ArgumentException("Unknown value type.", "source");
     
    120124    }
    121125
    122     private static DA.BinaryData ToEntity(byte[] data, DA.OKBDataContext okb) {
     126    private static DA.BinaryData ToEntity(byte[] data, DA.OKBDataContext okb, List<DA.BinaryData> binCache) {
    123127      if (data == null) return null;
    124128      byte[] hash;
     
    126130        hash = sha1.ComputeHash(data);
    127131      }
     132
     133      var cachedBinaryData = binCache.Where(x => x.Hash.SequenceEqual(hash)).FirstOrDefault();
     134      if (cachedBinaryData != null)
     135        return cachedBinaryData;
     136
    128137      var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault();
    129       if (entity == null)
     138      if (entity == null) {
    130139        entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash };
     140        binCache.Add(entity);
     141      }
     142
    131143      return entity;
    132144    }
Note: See TracChangeset for help on using the changeset viewer.