Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB (trunk integration)/HeuristicLab.Services.OKB.DataAccess/3.3/Tests/DBTests.cs @ 7331

Last change on this file since 7331 was 7331, checked in by ascheibe, 13 years ago

#1174

  • switched to new build style for branches and improved config merging
  • updated year in license headers and assembly infos
  • updated version in plugin files and assembly infos
File size: 32.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Data.Linq;
25using System.Linq;
26using HeuristicLab.Services.OKB.DataAccess;
27using HeuristicLab.Services.OKB.Query;
28using Microsoft.VisualStudio.TestTools.UnitTesting;
29
30namespace HeuristicLab.Services.OKB.DataAccess_33.Tests {
31  /// <summary>
32  /// Summary description for DBTests
33  /// </summary>
34  [TestClass]
35  public class DBTests {
36    private const int PLATFORMS = 1;
37    private const int DATATYPES_PER_PLATFORM = 500;
38    private const int ALGORITHMCLASSES_PER_PLATFORM = 10;
39    private const int ALGORITHMS_PER_CLASS = 10;
40    private const int PROBLEMCLASSES_PER_PLATFORM = 10;
41    private const int PROBLEMS_PER_CLASS = 10;
42    private const int PARAMETERS_PER_ALGORITHM = 10;
43    private const int RESULTS_PER_ALGORITHM = 10;
44    private const int PARAMETERS_PER_PROBLEM = 10;
45    private const int EXPERIMENTS_PER_PLATFORM = 1000;
46    private const int RUNS_PER_EXPERIMENT = 10;
47    private const int ALGORITHMDATA_SIZE = 1024 * 1024;
48    private const int PROBLEMDATA_SIZE = 1024 * 1024;
49    private const int BLOBVALUE_SIZE = 1024;
50
51    private string[] sqlNames = new string[] { "varbinary", "nvarchar", "float", "bit", "bigint" };
52    private Random random = new Random();
53    private DataType[] varbinaryTypes;
54    private DataType[] nvarcharTypes;
55    private DataType[] floatTypes;
56    private DataType[] bitTypes;
57    private DataType[] bigintTypes;
58
59    public DBTests() {
60      //
61      // TODO: Add constructor logic here
62      //
63    }
64
65    private TestContext testContextInstance;
66
67    /// <summary>
68    ///Gets or sets the test context which provides
69    ///information about and functionality for the current test run.
70    ///</summary>
71    public TestContext TestContext {
72      get {
73        return testContextInstance;
74      }
75      set {
76        testContextInstance = value;
77      }
78    }
79
80    #region Additional test attributes
81    //
82    // You can use the following additional attributes as you write your tests:
83    //
84    // Use ClassInitialize to run code before running the first test in the class
85    // [ClassInitialize()]
86    // public static void MyClassInitialize(TestContext testContext) { }
87    //
88    // Use ClassCleanup to run code after all tests in a class have run
89    // [ClassCleanup()]
90    // public static void MyClassCleanup() { }
91    //
92    // Use TestInitialize to run code before running each test
93    // [TestInitialize()]
94    // public void MyTestInitialize() { }
95    //
96    // Use TestCleanup to run code after each test has run
97    // [TestCleanup()]
98    // public void MyTestCleanup() { }
99    //
100    #endregion
101
102    [TestMethod]
103    public void FetchRunsTest() {
104      long[] ids;
105      using (OKBDataContext okb = new OKBDataContext()) {
106        ids = okb.Runs.Skip(100).Take(50).Select(x => x.Id).ToArray();
107      }
108
109      QueryService qs = new QueryService();
110      qs.GetQueryResults(ids);
111    }
112
113    [TestMethod]
114    public void GetFiltersTest() {
115      List<DataTransfer.Filter> filters = new List<DataTransfer.Filter>();
116      using (OKBDataContext okb = new OKBDataContext()) {
117        // run filters
118        filters.Add(new DataTransfer.OrdinalComparisonLongFilter(typeof(RunRandomSeedFilter).AssemblyQualifiedName, "Run Random Seed"));
119        filters.Add(new DataTransfer.OrdinalComparisonDateTimeFilter(typeof(RunCreatedDateFilter).AssemblyQualifiedName, "Run Created Date"));
120        filters.Add(new DataTransfer.SetComparisonStringFilter(typeof(RunUserNameFilter).AssemblyQualifiedName, "Run User Name"));
121        filters.Add(new DataTransfer.SetComparisonStringFilter(typeof(RunClientNameFilter).AssemblyQualifiedName, "Run Client Name"));
122
123        // result filters
124        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ResultNameFilter).AssemblyQualifiedName, "Result Name", okb.Results.Select(x => x.Name).Distinct().ToArray()));
125        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
126          filters.Add(new DataTransfer.NameSetComparisonStringAvailableValuesFilter(typeof(ResultBlobValueDataTypeNameFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value Data Type Name", entity.Name, okb.ResultBlobValues.Where(x => x.Result.Name == entity.Name).Select(x => x.DataType.Name).Distinct().ToArray()));
127        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
128          filters.Add(new DataTransfer.NameEqualityComparisonByteArrayFilter(typeof(ResultBlobValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
129        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "bit").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
130          filters.Add(new DataTransfer.NameEqualityComparisonBoolFilter(typeof(ResultBoolValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
131        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "float").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
132          filters.Add(new DataTransfer.NameOrdinalComparisonDoubleFilter(typeof(ResultFloatValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
133        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "bigint").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
134          filters.Add(new DataTransfer.NameOrdinalComparisonLongFilter(typeof(ResultIntValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
135        foreach (Result entity in okb.Results.Where(x => x.DataType.SqlName == "nvarchar").AsEnumerable().Distinct<Result>(new GenericEqualityComparer<Result>((x, y) => x.Name == y.Name)))
136          filters.Add(new DataTransfer.NameSetComparisonStringFilter(typeof(ResultStringValueValueFilter).AssemblyQualifiedName, "Result " + entity.Name + " Value", entity.Name));
137
138        // algorithm parameter filters
139        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmParameterNameFilter).AssemblyQualifiedName, "Algorithm Parameter Name", okb.AlgorithmParameters.Select(x => x.Name).Distinct().ToArray()));
140        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
141          filters.Add(new DataTransfer.NameSetComparisonStringAvailableValuesFilter(typeof(AlgorithmParameterBlobValueDataTypeNameFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value Data Type Name", entity.Name, okb.AlgorithmParameterBlobValues.Where(x => x.AlgorithmParameter.Name == entity.Name).Select(x => x.DataType.Name).Distinct().ToArray()));
142        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
143          filters.Add(new DataTransfer.NameEqualityComparisonByteArrayFilter(typeof(AlgorithmParameterBlobValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
144        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "bit").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
145          filters.Add(new DataTransfer.NameEqualityComparisonBoolFilter(typeof(AlgorithmParameterBoolValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
146        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "float").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
147          filters.Add(new DataTransfer.NameOrdinalComparisonDoubleFilter(typeof(AlgorithmParameterFloatValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
148        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "bigint").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
149          filters.Add(new DataTransfer.NameOrdinalComparisonLongFilter(typeof(AlgorithmParameterIntValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
150        foreach (AlgorithmParameter entity in okb.AlgorithmParameters.Where(x => x.DataType.SqlName == "nvarchar").AsEnumerable().Distinct<AlgorithmParameter>(new GenericEqualityComparer<AlgorithmParameter>((x, y) => x.Name == y.Name)))
151          filters.Add(new DataTransfer.NameSetComparisonStringFilter(typeof(AlgorithmParameterStringValueValueFilter).AssemblyQualifiedName, "Algorithm Parameter " + entity.Name + " Value", entity.Name));
152
153        // algorithm filters
154        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmNameFilter).AssemblyQualifiedName, "Algorithm Name", okb.Algorithms.Select(x => x.Name).Distinct().ToArray()));
155        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmClassNameFilter).AssemblyQualifiedName, "Algorithm Class Name", okb.AlgorithmClasses.Select(x => x.Name).Distinct().ToArray()));
156        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmPlatformNameFilter).AssemblyQualifiedName, "Algorithm Platform Name", okb.Platforms.Select(x => x.Name).Distinct().ToArray()));
157        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(AlgorithmDataDataTypeNameFilter).AssemblyQualifiedName, "Algorithm Data Type Name", okb.Algorithms.Select(x => x.AlgorithmData.DataType.Name).Distinct().ToArray()));
158
159        // problem parameter filters
160        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemParameterNameFilter).AssemblyQualifiedName, "Problem Parameter Name", okb.ProblemParameters.Select(x => x.Name).Distinct().ToArray()));
161        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
162          filters.Add(new DataTransfer.NameSetComparisonStringAvailableValuesFilter(typeof(ProblemParameterBlobValueDataTypeNameFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value Data Type Name", entity.Name, okb.ProblemParameterBlobValues.Where(x => x.ProblemParameter.Name == entity.Name).Select(x => x.DataType.Name).Distinct().ToArray()));
163        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "varbinary").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
164          filters.Add(new DataTransfer.NameEqualityComparisonByteArrayFilter(typeof(ProblemParameterBlobValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
165        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "bit").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
166          filters.Add(new DataTransfer.NameEqualityComparisonBoolFilter(typeof(ProblemParameterBoolValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
167        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "float").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
168          filters.Add(new DataTransfer.NameOrdinalComparisonDoubleFilter(typeof(ProblemParameterFloatValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
169        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "bigint").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
170          filters.Add(new DataTransfer.NameOrdinalComparisonLongFilter(typeof(ProblemParameterIntValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
171        foreach (ProblemParameter entity in okb.ProblemParameters.Where(x => x.DataType.SqlName == "nvarchar").AsEnumerable().Distinct<ProblemParameter>(new GenericEqualityComparer<ProblemParameter>((x, y) => x.Name == y.Name)))
172          filters.Add(new DataTransfer.NameSetComparisonStringFilter(typeof(ProblemParameterStringValueValueFilter).AssemblyQualifiedName, "Problem Parameter " + entity.Name + " Value", entity.Name));
173
174        // problem filters
175        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemNameFilter).AssemblyQualifiedName, "Problem Name", okb.Problems.Select(x => x.Name).Distinct().ToArray()));
176        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemClassNameFilter).AssemblyQualifiedName, "Problem Class Name", okb.ProblemClasses.Select(x => x.Name).Distinct().ToArray()));
177        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemPlatformNameFilter).AssemblyQualifiedName, "Problem Platform Name", okb.Platforms.Select(x => x.Name).Distinct().ToArray()));
178        filters.Add(new DataTransfer.SetComparisonStringAvailableValuesFilter(typeof(ProblemDataDataTypeNameFilter).AssemblyQualifiedName, "Problem Data Type Name", okb.Problems.Select(x => x.ProblemData.DataType.Name).Distinct().ToArray()));
179
180        // and/or filters
181        filters.Add(new DataTransfer.CombinedFilter(typeof(AndFilter).AssemblyQualifiedName, "And", DataTransfer.BooleanOperation.And));
182        filters.Add(new DataTransfer.CombinedFilter(typeof(OrFilter).AssemblyQualifiedName, "Or", DataTransfer.BooleanOperation.Or));
183      }
184    }
185
186    [TestMethod]
187    public void ClearDB() {
188      using (OKBDataContext okb = new OKBDataContext()) {
189        okb.ExecuteCommand("DELETE FROM dbo.ResultBlobValue");
190        okb.ExecuteCommand("DELETE FROM dbo.ResultBoolValue");
191        okb.ExecuteCommand("DELETE FROM dbo.ResultFloatValue");
192        okb.ExecuteCommand("DELETE FROM dbo.ResultIntValue");
193        okb.ExecuteCommand("DELETE FROM dbo.ResultStringValue");
194
195        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmParameterBlobValue");
196        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmParameterBoolValue");
197        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmParameterFloatValue");
198        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmParameterIntValue");
199        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmParameterStringValue");
200
201        okb.ExecuteCommand("DELETE FROM dbo.ProblemParameterBlobValue");
202        okb.ExecuteCommand("DELETE FROM dbo.ProblemParameterBoolValue");
203        okb.ExecuteCommand("DELETE FROM dbo.ProblemParameterFloatValue");
204        okb.ExecuteCommand("DELETE FROM dbo.ProblemParameterIntValue");
205        okb.ExecuteCommand("DELETE FROM dbo.ProblemParameterStringValue");
206
207        okb.ExecuteCommand("DELETE FROM dbo.Run");
208        okb.ExecuteCommand("DELETE FROM dbo.Experiment");
209        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmData");
210        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmUser");
211        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmParameter");
212        okb.ExecuteCommand("DELETE FROM dbo.Result");
213        okb.ExecuteCommand("DELETE FROM dbo.Algorithm");
214        okb.ExecuteCommand("DELETE FROM dbo.AlgorithmClass");
215        okb.ExecuteCommand("DELETE FROM dbo.ProblemData");
216        okb.ExecuteCommand("DELETE FROM dbo.ProblemUser");
217        okb.ExecuteCommand("DELETE FROM dbo.ProblemParameter");
218        okb.ExecuteCommand("DELETE FROM dbo.Problem");
219        okb.ExecuteCommand("DELETE FROM dbo.ProblemClass");
220        okb.ExecuteCommand("DELETE FROM dbo.DataType");
221        okb.ExecuteCommand("DELETE FROM dbo.Platform");
222      }
223    }
224
225    [TestMethod]
226    public void InitDummyDB() {
227      using (OKBDataContext okb = new OKBDataContext()) {
228        for (int i = 0; i < PLATFORMS; i++) {
229          CreatePlatform(okb);
230        }
231        okb.SubmitChanges();
232      }
233    }
234
235    [TestMethod]
236    public void CreateDummyExperiments() {
237      using (OKBDataContext okb = new OKBDataContext()) {
238        foreach (Platform platform in okb.Platforms) {
239          for (int i = 0; i < EXPERIMENTS_PER_PLATFORM; i++) {
240            Algorithm[] algorithms = okb.Algorithms.Where(x => x.PlatformId == platform.Id).ToArray();
241            Problem[] problems = okb.Problems.Where(x => x.PlatformId == platform.Id).ToArray();
242            varbinaryTypes = null;
243            nvarcharTypes = null;
244            floatTypes = null;
245            bitTypes = null;
246            bigintTypes = null;
247
248            CreateExperiment(okb, algorithms[random.Next(algorithms.Length)], problems[random.Next(problems.Length)], platform);
249          }
250          okb.SubmitChanges();
251        }
252      }
253    }
254
255    private void CreatePlatform(OKBDataContext okb) {
256      Platform entity = new Platform();
257      entity.Name = Guid.NewGuid().ToString();
258      entity.Description = Guid.NewGuid().ToString();
259      okb.Platforms.InsertOnSubmit(entity);
260
261      for (int i = 0; i < DATATYPES_PER_PLATFORM; i++) {
262        CreateDataType(okb, entity);
263      }
264      okb.SubmitChanges();
265
266      varbinaryTypes = null;
267      nvarcharTypes = null;
268      floatTypes = null;
269      bitTypes = null;
270      bigintTypes = null;
271
272      for (int i = 0; i < ALGORITHMCLASSES_PER_PLATFORM; i++) {
273        CreateAlgorithmClass(okb, entity);
274      }
275      for (int i = 0; i < PROBLEMCLASSES_PER_PLATFORM; i++) {
276        CreateProblemClass(okb, entity);
277      }
278    }
279    private void CreateDataType(OKBDataContext okb, Platform platform) {
280      DataType entity = new DataType();
281      entity.Name = Guid.NewGuid().ToString();
282      entity.TypeName = Guid.NewGuid().ToString();
283      entity.SqlName = sqlNames[random.Next(sqlNames.Length)];
284      entity.Platform = platform;
285      okb.DataTypes.InsertOnSubmit(entity);
286    }
287    private DataType GetDataType(OKBDataContext okb, Platform platform, string sqlName) {
288      if (varbinaryTypes == null) varbinaryTypes = okb.DataTypes.Where(x => (x.PlatformId == platform.Id) && (x.SqlName == "varbinary")).ToArray();
289      if (nvarcharTypes == null) nvarcharTypes = okb.DataTypes.Where(x => (x.PlatformId == platform.Id) && (x.SqlName == "nvarchar")).ToArray();
290      if (floatTypes == null) floatTypes = okb.DataTypes.Where(x => (x.PlatformId == platform.Id) && (x.SqlName == "float")).ToArray();
291      if (bitTypes == null) bitTypes = okb.DataTypes.Where(x => (x.PlatformId == platform.Id) && (x.SqlName == "bit")).ToArray();
292      if (bigintTypes == null) bigintTypes = okb.DataTypes.Where(x => (x.PlatformId == platform.Id) && (x.SqlName == "bigint")).ToArray();
293
294      switch (sqlName) {
295        case "varbinary": return varbinaryTypes[random.Next(varbinaryTypes.Length)];
296        case "nvarchar": return nvarcharTypes[random.Next(nvarcharTypes.Length)];
297        case "float": return floatTypes[random.Next(floatTypes.Length)];
298        case "bit": return bitTypes[random.Next(bitTypes.Length)];
299        case "bigint": return bigintTypes[random.Next(bigintTypes.Length)];
300        default: return null;
301      }
302    }
303    private void CreateAlgorithmClass(OKBDataContext okb, Platform platform) {
304      AlgorithmClass entity = new AlgorithmClass();
305      entity.Name = Guid.NewGuid().ToString();
306      entity.Description = Guid.NewGuid().ToString();
307      for (int i = 0; i < ALGORITHMS_PER_CLASS; i++) {
308        CreateAlgorithm(okb, entity, platform);
309      }
310      okb.AlgorithmClasses.InsertOnSubmit(entity);
311    }
312    private void CreateProblemClass(OKBDataContext okb, Platform platform) {
313      ProblemClass entity = new ProblemClass();
314      entity.Name = Guid.NewGuid().ToString();
315      entity.Description = Guid.NewGuid().ToString();
316      for (int i = 0; i < PROBLEMS_PER_CLASS; i++) {
317        CreateProblem(okb, entity, platform);
318      }
319      okb.ProblemClasses.InsertOnSubmit(entity);
320    }
321    private void CreateAlgorithm(OKBDataContext okb, AlgorithmClass algorithmClass, Platform platform) {
322      Algorithm entity = new Algorithm();
323      entity.Name = Guid.NewGuid().ToString();
324      entity.Description = Guid.NewGuid().ToString();
325      entity.AlgorithmClass = algorithmClass;
326      entity.Platform = platform;
327      CreateAlgorithmData(okb, entity, platform);
328      for (int i = 0; i < PARAMETERS_PER_ALGORITHM; i++) {
329        CreateAlgorithmParameter(okb, entity, platform);
330      }
331      for (int i = 0; i < RESULTS_PER_ALGORITHM; i++) {
332        CreateResult(okb, entity, platform);
333      }
334      okb.Algorithms.InsertOnSubmit(entity);
335    }
336    private void CreateAlgorithmData(OKBDataContext okb, Algorithm algorithm, Platform platform) {
337      AlgorithmData entity = new AlgorithmData();
338      entity.Algorithm = algorithm;
339      entity.Data = new System.Data.Linq.Binary(new byte[ALGORITHMDATA_SIZE]);
340      entity.DataType = GetDataType(okb, platform, "varbinary");
341      okb.AlgorithmDatas.InsertOnSubmit(entity);
342    }
343    private void CreateAlgorithmParameter(OKBDataContext okb, Algorithm algorithm, Platform platform) {
344      AlgorithmParameter entity = new AlgorithmParameter();
345      entity.Name = Guid.NewGuid().ToString();
346      entity.Alias = Guid.NewGuid().ToString();
347      entity.Description = Guid.NewGuid().ToString();
348      entity.Algorithm = algorithm;
349      entity.DataType = GetDataType(okb, platform, sqlNames[random.Next(sqlNames.Length)]);
350      okb.AlgorithmParameters.InsertOnSubmit(entity);
351    }
352    private void CreateResult(OKBDataContext okb, Algorithm algorithm, Platform platform) {
353      Result entity = new Result();
354      entity.Name = Guid.NewGuid().ToString();
355      entity.Alias = Guid.NewGuid().ToString();
356      entity.Description = Guid.NewGuid().ToString();
357      entity.Algorithm = algorithm;
358      entity.DataType = GetDataType(okb, platform, sqlNames[random.Next(sqlNames.Length)]);
359      okb.Results.InsertOnSubmit(entity);
360    }
361    private void CreateProblem(OKBDataContext okb, ProblemClass problemClass, Platform platform) {
362      Problem entity = new Problem();
363      entity.Name = Guid.NewGuid().ToString();
364      entity.Description = Guid.NewGuid().ToString();
365      entity.ProblemClass = problemClass;
366      entity.Platform = platform;
367      CreateProblemData(okb, entity, platform);
368      for (int i = 0; i < PARAMETERS_PER_PROBLEM; i++) {
369        CreateProblemParameter(okb, entity, platform);
370      }
371      okb.Problems.InsertOnSubmit(entity);
372    }
373    private void CreateProblemData(OKBDataContext okb, Problem problem, Platform platform) {
374      ProblemData entity = new ProblemData();
375      entity.Problem = problem;
376      entity.Data = new System.Data.Linq.Binary(new byte[PROBLEMDATA_SIZE]);
377      entity.DataType = GetDataType(okb, platform, "varbinary");
378      okb.ProblemDatas.InsertOnSubmit(entity);
379    }
380    private void CreateProblemParameter(OKBDataContext okb, Problem problem, Platform platform) {
381      ProblemParameter entity = new ProblemParameter();
382      entity.Name = Guid.NewGuid().ToString();
383      entity.Alias = Guid.NewGuid().ToString();
384      entity.Description = Guid.NewGuid().ToString();
385      entity.Problem = problem;
386      entity.DataType = GetDataType(okb, platform, sqlNames[random.Next(sqlNames.Length)]);
387      okb.ProblemParameters.InsertOnSubmit(entity);
388    }
389    private void CreateExperiment(OKBDataContext okb, Algorithm algorithm, Problem problem, Platform platform) {
390      Experiment entity = new Experiment();
391      entity.Algorithm = algorithm;
392      entity.Problem = problem;
393
394      foreach (AlgorithmParameter algorithmParameter in okb.AlgorithmParameters.Where(x => x.AlgorithmId == algorithm.Id)) {
395        CreateAlgorithmParameterValue(okb, algorithmParameter, entity, platform);
396      }
397      foreach (ProblemParameter problemParameter in okb.ProblemParameters.Where(x => x.ProblemId == problem.Id)) {
398        CreateProblemParameterValue(okb, problemParameter, entity, platform);
399      }
400
401      for (int i = 0; i < RUNS_PER_EXPERIMENT; i++) {
402        CreateRun(okb, entity, platform);
403      }
404      okb.Experiments.InsertOnSubmit(entity);
405    }
406    private void CreateAlgorithmParameterValue(OKBDataContext okb, AlgorithmParameter algorithmParameter, Experiment experiment, Platform platform) {
407      switch (algorithmParameter.DataType.SqlName) {
408        case "varbinary":
409          AlgorithmParameterBlobValue v1 = new AlgorithmParameterBlobValue();
410          v1.AlgorithmParameter = algorithmParameter;
411          v1.Experiment = experiment;
412          v1.Value = new Binary(new byte[BLOBVALUE_SIZE]);
413          v1.DataType = GetDataType(okb, platform, "varbinary");
414          okb.AlgorithmParameterBlobValues.InsertOnSubmit(v1);
415          return;
416        case "bit":
417          AlgorithmParameterBoolValue v2 = new AlgorithmParameterBoolValue();
418          v2.AlgorithmParameter = algorithmParameter;
419          v2.Experiment = experiment;
420          v2.Value = random.Next(2) == 0;
421          v2.DataType = GetDataType(okb, platform, "bit");
422          okb.AlgorithmParameterBoolValues.InsertOnSubmit(v2);
423          return;
424        case "float":
425          AlgorithmParameterFloatValue v3 = new AlgorithmParameterFloatValue();
426          v3.AlgorithmParameter = algorithmParameter;
427          v3.Experiment = experiment;
428          v3.Value = random.NextDouble();
429          v3.DataType = GetDataType(okb, platform, "float");
430          okb.AlgorithmParameterFloatValues.InsertOnSubmit(v3);
431          return;
432        case "bigint":
433          AlgorithmParameterIntValue v4 = new AlgorithmParameterIntValue();
434          v4.AlgorithmParameter = algorithmParameter;
435          v4.Experiment = experiment;
436          v4.Value = random.Next();
437          v4.DataType = GetDataType(okb, platform, "bigint");
438          okb.AlgorithmParameterIntValues.InsertOnSubmit(v4);
439          return;
440        case "nvarchar":
441          AlgorithmParameterStringValue v5 = new AlgorithmParameterStringValue();
442          v5.AlgorithmParameter = algorithmParameter;
443          v5.Experiment = experiment;
444          v5.Value = Guid.NewGuid().ToString();
445          v5.DataType = GetDataType(okb, platform, "nvarchar");
446          okb.AlgorithmParameterStringValues.InsertOnSubmit(v5);
447          return;
448      }
449    }
450    private void CreateProblemParameterValue(OKBDataContext okb, ProblemParameter problemParameter, Experiment experiment, Platform platform) {
451      switch (problemParameter.DataType.SqlName) {
452        case "varbinary":
453          ProblemParameterBlobValue v1 = new ProblemParameterBlobValue();
454          v1.ProblemParameter = problemParameter;
455          v1.Experiment = experiment;
456          v1.Value = new Binary(new byte[BLOBVALUE_SIZE]);
457          v1.DataType = GetDataType(okb, platform, "varbinary");
458          okb.ProblemParameterBlobValues.InsertOnSubmit(v1);
459          return;
460        case "bit":
461          ProblemParameterBoolValue v2 = new ProblemParameterBoolValue();
462          v2.ProblemParameter = problemParameter;
463          v2.Experiment = experiment;
464          v2.Value = random.Next(2) == 0;
465          v2.DataType = GetDataType(okb, platform, "bit");
466          okb.ProblemParameterBoolValues.InsertOnSubmit(v2);
467          return;
468        case "float":
469          ProblemParameterFloatValue v3 = new ProblemParameterFloatValue();
470          v3.ProblemParameter = problemParameter;
471          v3.Experiment = experiment;
472          v3.Value = random.NextDouble();
473          v3.DataType = GetDataType(okb, platform, "float");
474          okb.ProblemParameterFloatValues.InsertOnSubmit(v3);
475          return;
476        case "bigint":
477          ProblemParameterIntValue v4 = new ProblemParameterIntValue();
478          v4.ProblemParameter = problemParameter;
479          v4.Experiment = experiment;
480          v4.Value = random.Next();
481          v4.DataType = GetDataType(okb, platform, "bigint");
482          okb.ProblemParameterIntValues.InsertOnSubmit(v4);
483          return;
484        case "nvarchar":
485          ProblemParameterStringValue v5 = new ProblemParameterStringValue();
486          v5.ProblemParameter = problemParameter;
487          v5.Experiment = experiment;
488          v5.Value = Guid.NewGuid().ToString();
489          v5.DataType = GetDataType(okb, platform, "nvarchar");
490          okb.ProblemParameterStringValues.InsertOnSubmit(v5);
491          return;
492      }
493    }
494    private void CreateRun(OKBDataContext okb, Experiment experiment, Platform platform) {
495      Run entity = new Run();
496      entity.RandomSeed = random.Next();
497      entity.CreatedDate = DateTime.Now;
498      entity.UserId = Guid.NewGuid();
499      entity.ClientId = Guid.NewGuid();
500      entity.Experiment = experiment;
501
502      foreach (Result result in okb.Results.Where(x => x.AlgorithmId == experiment.AlgorithmId)) {
503        CreateResultValue(okb, result, entity, platform);
504      }
505      okb.Runs.InsertOnSubmit(entity);
506    }
507    private void CreateResultValue(OKBDataContext okb, Result result, Run run, Platform platform) {
508      switch (result.DataType.SqlName) {
509        case "varbinary":
510          ResultBlobValue v1 = new ResultBlobValue();
511          v1.Result = result;
512          v1.Run = run;
513          v1.Value = new Binary(new byte[BLOBVALUE_SIZE]);
514          v1.DataType = GetDataType(okb, platform, "varbinary");
515          okb.ResultBlobValues.InsertOnSubmit(v1);
516          return;
517        case "bit":
518          ResultBoolValue v2 = new ResultBoolValue();
519          v2.Result = result;
520          v2.Run = run;
521          v2.Value = random.Next(2) == 0;
522          v2.DataType = GetDataType(okb, platform, "bit");
523          okb.ResultBoolValues.InsertOnSubmit(v2);
524          return;
525        case "float":
526          ResultFloatValue v3 = new ResultFloatValue();
527          v3.Result = result;
528          v3.Run = run;
529          v3.Value = random.NextDouble();
530          v3.DataType = GetDataType(okb, platform, "float");
531          okb.ResultFloatValues.InsertOnSubmit(v3);
532          return;
533        case "bigint":
534          ResultIntValue v4 = new ResultIntValue();
535          v4.Result = result;
536          v4.Run = run;
537          v4.Value = random.Next();
538          v4.DataType = GetDataType(okb, platform, "bigint");
539          okb.ResultIntValues.InsertOnSubmit(v4);
540          return;
541        case "nvarchar":
542          ResultStringValue v5 = new ResultStringValue();
543          v5.Result = result;
544          v5.Run = run;
545          v5.Value = Guid.NewGuid().ToString();
546          v5.DataType = GetDataType(okb, platform, "nvarchar");
547          okb.ResultStringValues.InsertOnSubmit(v5);
548          return;
549      }
550    }
551  }
552}
Note: See TracBrowser for help on using the repository browser.