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