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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Data.Linq;
|
---|
25 | using System.Linq;
|
---|
26 | using System.ServiceModel;
|
---|
27 | using HeuristicLab.Services.OKB.DataAccess;
|
---|
28 | using HeuristicLab.Services.OKB.Query.DataTransfer;
|
---|
29 | using HeuristicLab.Services.OKB.Query.Filters;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Services.OKB.Query {
|
---|
32 | /// <summary>
|
---|
33 | /// Implementation of the OKB query service (interface <see cref="IQueryService"/>).
|
---|
34 | /// </summary>
|
---|
35 | [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
|
---|
36 | public class QueryService : IQueryService {
|
---|
37 | public IEnumerable<Filter> GetFilters() {
|
---|
38 | List<Filter> filters = new List<Filter>();
|
---|
39 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
40 | #region Run Filters
|
---|
41 | filters.Add(new OrdinalComparisonDateTimeFilter(typeof(RunCreatedDateFilter).AssemblyQualifiedName, "Run Created Date"));
|
---|
42 | filters.Add(new StringComparisonFilter(typeof(RunUserNameFilter).AssemblyQualifiedName, "Run User Name"));
|
---|
43 | filters.Add(new StringComparisonFilter(typeof(RunClientNameFilter).AssemblyQualifiedName, "Run Client Name"));
|
---|
44 | #endregion
|
---|
45 |
|
---|
46 | #region Parameter Filters
|
---|
47 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
48 | typeof(ValueNameFilter).AssemblyQualifiedName,
|
---|
49 | "Parameter Name",
|
---|
50 | okb.ValueNames.Where(x => x.Category == ValueNameCategory.Parameter).Select(x => x.Name).Distinct().ToArray()
|
---|
51 | ));
|
---|
52 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Binary)).Select(x => x.Name).Distinct())
|
---|
53 | filters.Add(new NameStringComparisonAvailableValuesFilter(
|
---|
54 | typeof(ValueDataTypeNameFilter).AssemblyQualifiedName,
|
---|
55 | "Parameter " + name + " Value Data Type Name",
|
---|
56 | name,
|
---|
57 | okb.Values.Where(x => (x.ValueName.Name == name) && (x.ValueName.Category == ValueNameCategory.Parameter) && (x.ValueName.Type == ValueNameType.Binary)).Select(x => x.DataType.Name).Distinct().ToArray()
|
---|
58 | ));
|
---|
59 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Bool)).Select(x => x.Name).Distinct())
|
---|
60 | filters.Add(new NameEqualityComparisonBoolFilter(
|
---|
61 | typeof(BoolValueFilter).AssemblyQualifiedName,
|
---|
62 | "Parameter " + name + " Value",
|
---|
63 | name
|
---|
64 | ));
|
---|
65 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Int)).Select(x => x.Name).Distinct())
|
---|
66 | filters.Add(new NameOrdinalComparisonIntFilter(
|
---|
67 | typeof(IntValueFilter).AssemblyQualifiedName,
|
---|
68 | "Parameter " + name + " Value",
|
---|
69 | name
|
---|
70 | ));
|
---|
71 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Long)).Select(x => x.Name).Distinct())
|
---|
72 | filters.Add(new NameOrdinalComparisonLongFilter(
|
---|
73 | typeof(LongValueFilter).AssemblyQualifiedName,
|
---|
74 | "Parameter " + name + " Value",
|
---|
75 | name
|
---|
76 | ));
|
---|
77 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.TimeSpan)).Select(x => x.Name).Distinct())
|
---|
78 | filters.Add(new NameOrdinalComparisonTimeSpanFilter(
|
---|
79 | typeof(TimeSpanValueFilter).AssemblyQualifiedName,
|
---|
80 | "Parameter " + name + " Value",
|
---|
81 | name
|
---|
82 | ));
|
---|
83 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Float)).Select(x => x.Name).Distinct())
|
---|
84 | filters.Add(new NameOrdinalComparisonFloatFilter(
|
---|
85 | typeof(FloatValueFilter).AssemblyQualifiedName,
|
---|
86 | "Parameter " + name + " Value",
|
---|
87 | name
|
---|
88 | ));
|
---|
89 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Double)).Select(x => x.Name).Distinct())
|
---|
90 | filters.Add(new NameOrdinalComparisonDoubleFilter(
|
---|
91 | typeof(DoubleValueFilter).AssemblyQualifiedName,
|
---|
92 | "Parameter " + name + " Value",
|
---|
93 | name
|
---|
94 | ));
|
---|
95 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Percent)).Select(x => x.Name).Distinct())
|
---|
96 | filters.Add(new NameOrdinalComparisonPercentFilter(
|
---|
97 | typeof(PercentValueFilter).AssemblyQualifiedName,
|
---|
98 | "Parameter " + name + " Value",
|
---|
99 | name
|
---|
100 | ));
|
---|
101 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.String)).Select(x => x.Name).Distinct())
|
---|
102 | filters.Add(new NameStringComparisonFilter(
|
---|
103 | typeof(StringValueFilter).AssemblyQualifiedName,
|
---|
104 | "Parameter " + name + " Value",
|
---|
105 | name
|
---|
106 | ));
|
---|
107 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Parameter) && (x.Type == ValueNameType.Binary)).Select(x => x.Name).Distinct())
|
---|
108 | filters.Add(new NameEqualityComparisonByteArrayFilter(
|
---|
109 | typeof(BinaryValueFilter).AssemblyQualifiedName,
|
---|
110 | "Parameter " + name + " Value",
|
---|
111 | name
|
---|
112 | ));
|
---|
113 | #endregion
|
---|
114 |
|
---|
115 | #region Result Filters
|
---|
116 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
117 | typeof(ValueNameFilter).AssemblyQualifiedName,
|
---|
118 | "Result Name",
|
---|
119 | okb.ValueNames.Where(x => x.Category == ValueNameCategory.Result).Select(x => x.Name).Distinct().ToArray()
|
---|
120 | ));
|
---|
121 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Binary)).Select(x => x.Name).Distinct())
|
---|
122 | filters.Add(new NameStringComparisonAvailableValuesFilter(
|
---|
123 | typeof(ValueDataTypeNameFilter).AssemblyQualifiedName,
|
---|
124 | "Result " + name + " Value Data Type Name",
|
---|
125 | name,
|
---|
126 | okb.Values.Where(x => (x.ValueName.Name == name) && (x.ValueName.Category == ValueNameCategory.Result) && (x.ValueName.Type == ValueNameType.Binary)).Select(x => x.DataType.Name).Distinct().ToArray()
|
---|
127 | ));
|
---|
128 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Bool)).Select(x => x.Name).Distinct())
|
---|
129 | filters.Add(new NameEqualityComparisonBoolFilter(
|
---|
130 | typeof(BoolValueFilter).AssemblyQualifiedName,
|
---|
131 | "Result " + name + " Value",
|
---|
132 | name
|
---|
133 | ));
|
---|
134 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Int)).Select(x => x.Name).Distinct())
|
---|
135 | filters.Add(new NameOrdinalComparisonIntFilter(
|
---|
136 | typeof(IntValueFilter).AssemblyQualifiedName,
|
---|
137 | "Result " + name + " Value",
|
---|
138 | name
|
---|
139 | ));
|
---|
140 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Long)).Select(x => x.Name).Distinct())
|
---|
141 | filters.Add(new NameOrdinalComparisonLongFilter(
|
---|
142 | typeof(LongValueFilter).AssemblyQualifiedName,
|
---|
143 | "Result " + name + " Value",
|
---|
144 | name
|
---|
145 | ));
|
---|
146 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.TimeSpan)).Select(x => x.Name).Distinct())
|
---|
147 | filters.Add(new NameOrdinalComparisonTimeSpanFilter(
|
---|
148 | typeof(TimeSpanValueFilter).AssemblyQualifiedName,
|
---|
149 | "Result " + name + " Value",
|
---|
150 | name
|
---|
151 | ));
|
---|
152 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Float)).Select(x => x.Name).Distinct())
|
---|
153 | filters.Add(new NameOrdinalComparisonFloatFilter(
|
---|
154 | typeof(FloatValueFilter).AssemblyQualifiedName,
|
---|
155 | "Result " + name + " Value",
|
---|
156 | name
|
---|
157 | ));
|
---|
158 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Double)).Select(x => x.Name).Distinct())
|
---|
159 | filters.Add(new NameOrdinalComparisonDoubleFilter(
|
---|
160 | typeof(DoubleValueFilter).AssemblyQualifiedName,
|
---|
161 | "Result " + name + " Value",
|
---|
162 | name
|
---|
163 | ));
|
---|
164 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Percent)).Select(x => x.Name).Distinct())
|
---|
165 | filters.Add(new NameOrdinalComparisonPercentFilter(
|
---|
166 | typeof(PercentValueFilter).AssemblyQualifiedName,
|
---|
167 | "Result " + name + " Value",
|
---|
168 | name
|
---|
169 | ));
|
---|
170 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.String)).Select(x => x.Name).Distinct())
|
---|
171 | filters.Add(new NameStringComparisonFilter(
|
---|
172 | typeof(StringValueFilter).AssemblyQualifiedName,
|
---|
173 | "Result " + name + " Value",
|
---|
174 | name
|
---|
175 | ));
|
---|
176 | foreach (string name in okb.ValueNames.Where(x => (x.Category == ValueNameCategory.Result) && (x.Type == ValueNameType.Binary)).Select(x => x.Name).Distinct())
|
---|
177 | filters.Add(new NameEqualityComparisonByteArrayFilter(
|
---|
178 | typeof(BinaryValueFilter).AssemblyQualifiedName,
|
---|
179 | "Result " + name + " Value",
|
---|
180 | name
|
---|
181 | ));
|
---|
182 | #endregion
|
---|
183 |
|
---|
184 | #region Algorithm Filters
|
---|
185 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
186 | typeof(AlgorithmNameFilter).AssemblyQualifiedName,
|
---|
187 | "Algorithm Name",
|
---|
188 | okb.Algorithms.Select(x => x.Name).Distinct().ToArray()
|
---|
189 | ));
|
---|
190 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
191 | typeof(AlgorithmClassNameFilter).AssemblyQualifiedName,
|
---|
192 | "Algorithm Class Name",
|
---|
193 | okb.AlgorithmClasses.Select(x => x.Name).Distinct().ToArray()
|
---|
194 | ));
|
---|
195 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
196 | typeof(AlgorithmPlatformNameFilter).AssemblyQualifiedName,
|
---|
197 | "Algorithm Platform Name",
|
---|
198 | okb.Platforms.Select(x => x.Name).Distinct().ToArray()
|
---|
199 | ));
|
---|
200 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
201 | typeof(AlgorithmDataTypeNameFilter).AssemblyQualifiedName,
|
---|
202 | "Algorithm Data Type Name",
|
---|
203 | okb.Algorithms.Select(x => x.DataType.Name).Distinct().ToArray()
|
---|
204 | ));
|
---|
205 | #endregion
|
---|
206 |
|
---|
207 | #region Problem Filters
|
---|
208 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
209 | typeof(ProblemNameFilter).AssemblyQualifiedName,
|
---|
210 | "Problem Name",
|
---|
211 | okb.Problems.Select(x => x.Name).Distinct().ToArray()
|
---|
212 | ));
|
---|
213 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
214 | typeof(ProblemClassNameFilter).AssemblyQualifiedName,
|
---|
215 | "Problem Class Name",
|
---|
216 | okb.ProblemClasses.Select(x => x.Name).Distinct().ToArray()
|
---|
217 | ));
|
---|
218 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
219 | typeof(ProblemPlatformNameFilter).AssemblyQualifiedName,
|
---|
220 | "Problem Platform Name",
|
---|
221 | okb.Platforms.Select(x => x.Name).Distinct().ToArray()
|
---|
222 | ));
|
---|
223 | filters.Add(new StringComparisonAvailableValuesFilter(
|
---|
224 | typeof(ProblemDataTypeNameFilter).AssemblyQualifiedName,
|
---|
225 | "Problem Data Type Name",
|
---|
226 | okb.Problems.Select(x => x.DataType.Name).Distinct().ToArray()
|
---|
227 | ));
|
---|
228 | #endregion
|
---|
229 |
|
---|
230 | #region Combined Filters
|
---|
231 | filters.Add(new CombinedFilter(typeof(AndFilter).AssemblyQualifiedName, "AND", BooleanOperation.And));
|
---|
232 | filters.Add(new CombinedFilter(typeof(OrFilter).AssemblyQualifiedName, "OR", BooleanOperation.Or));
|
---|
233 | #endregion
|
---|
234 | }
|
---|
235 | return filters.OrderBy(x => x.Label);
|
---|
236 | }
|
---|
237 |
|
---|
238 | public long GetNumberOfRuns(Filter filter) {
|
---|
239 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
240 | return FilterRuns(okb.Runs, filter).LongCount();
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | public IEnumerable<long> GetRunIds(Filter filter) {
|
---|
245 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
246 | return FilterRuns(okb.Runs, filter).Select(x => x.Id).ToArray();
|
---|
247 | }
|
---|
248 | }
|
---|
249 |
|
---|
250 | public IEnumerable<DataTransfer.Run> GetRuns(IEnumerable<long> ids, bool includeBinaryValues) {
|
---|
251 | using (OKBDataContext okb = new OKBDataContext()) {
|
---|
252 | DataLoadOptions dlo = new DataLoadOptions();
|
---|
253 | // TODO: specify LoadWiths
|
---|
254 | okb.LoadOptions = dlo;
|
---|
255 |
|
---|
256 | return okb.Runs.Where(x => ids.Contains(x.Id)).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray();
|
---|
257 | }
|
---|
258 | }
|
---|
259 |
|
---|
260 | private IQueryable<DataAccess.Run> FilterRuns(IQueryable<DataAccess.Run> runs, Filter filter) {
|
---|
261 | IFilter f = (IFilter)Activator.CreateInstance(Type.GetType(filter.FilterTypeName), filter);
|
---|
262 | return runs.Where(f.Expression);
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|