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