1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using System.Xml;
|
---|
28 | using System.ServiceModel;
|
---|
29 | using System.ServiceModel.Description;
|
---|
30 | using HeuristicLab.PluginInfrastructure;
|
---|
31 | using HeuristicLab.Modeling.Database.SQLServerCompact;
|
---|
32 | using HeuristicLab.SparseMatrix;
|
---|
33 | using HeuristicLab.Modeling.Database;
|
---|
34 | using HeuristicLab.CEDMA.Charting;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.CEDMA.Core {
|
---|
37 | public class Console : ItemBase, IEditable {
|
---|
38 | private static readonly string sqlServerCompactConnectionString = @"Data Source=";
|
---|
39 |
|
---|
40 | public Console()
|
---|
41 | : base() {
|
---|
42 | }
|
---|
43 |
|
---|
44 | private string database;
|
---|
45 | public string Database {
|
---|
46 | get {
|
---|
47 | return database;
|
---|
48 | }
|
---|
49 | set {
|
---|
50 | if (value != database) {
|
---|
51 | database = value;
|
---|
52 | matrix = null;
|
---|
53 | visualMatrix = null;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | private Matrix<string,object> matrix;
|
---|
59 | public Matrix<string,object> Matrix {
|
---|
60 | get {
|
---|
61 | if (matrix == null) LoadResults();
|
---|
62 | return matrix;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | private VisualMatrix visualMatrix;
|
---|
67 | public VisualMatrix VisualMatrix {
|
---|
68 | get {
|
---|
69 | if (matrix == null)
|
---|
70 | visualMatrix = CreateVisualMatrix();
|
---|
71 | return visualMatrix;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | public IEditor CreateEditor() {
|
---|
76 | return new ConsoleEditor(this);
|
---|
77 | }
|
---|
78 |
|
---|
79 | public override IView CreateView() {
|
---|
80 | return new ConsoleEditor(this);
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void LoadResults() {
|
---|
84 | matrix = new Matrix<string,object>();
|
---|
85 | DatabaseService db = new DatabaseService(sqlServerCompactConnectionString + database);
|
---|
86 | db.Connect();
|
---|
87 |
|
---|
88 | foreach (var model in db.GetAllModels()) {
|
---|
89 | MatrixRow<string, object> row = new MatrixRow<string, object>();
|
---|
90 | foreach (var modelResult in db.GetModelResults(model)) {
|
---|
91 | row.Set(modelResult.Result.Name, modelResult.Value);
|
---|
92 | }
|
---|
93 | Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow<string, object>> inputVariableResultsEntries =
|
---|
94 | new Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow<string, object>>();
|
---|
95 | foreach (IInputVariableResult inputVariableResult in db.GetInputVariableResults(model)) {
|
---|
96 | if (!inputVariableResultsEntries.ContainsKey(inputVariableResult.Variable)) {
|
---|
97 | inputVariableResultsEntries[inputVariableResult.Variable] = new MatrixRow<string, object>();
|
---|
98 | inputVariableResultsEntries[inputVariableResult.Variable].Set("InputVariableName", inputVariableResult.Variable.Name);
|
---|
99 | }
|
---|
100 | inputVariableResultsEntries[inputVariableResult.Variable].Set(inputVariableResult.Result.Name, inputVariableResult.Value);
|
---|
101 | }
|
---|
102 | row.Set("VariableImpacts", inputVariableResultsEntries.Values);
|
---|
103 |
|
---|
104 | row.Set("PersistedData", db.GetModelData(model));
|
---|
105 | row.Set("TargetVariable", model.TargetVariable.Name);
|
---|
106 | row.Set("Algorithm", model.Algorithm.Name);
|
---|
107 |
|
---|
108 | matrix.AddRow(row);
|
---|
109 | }
|
---|
110 | db.Disconnect();
|
---|
111 | }
|
---|
112 |
|
---|
113 | private VisualMatrix CreateVisualMatrix() {
|
---|
114 | DatabaseService db = new DatabaseService(sqlServerCompactConnectionString + database);
|
---|
115 | db.Connect();
|
---|
116 | IEnumerable<string> multiDimensionalCategoricalVariables = new List<string> { "VariableImpacts: InputVariableName" };
|
---|
117 | IEnumerable<string> multiDimensionalOrdinalVariables = db.GetAllResultsForInputVariables().Select(x => "VariableImpacts: " + x.Name);
|
---|
118 | IEnumerable<string> ordinalVariables = db.GetAllResults().Select(r => r.Name);
|
---|
119 | IEnumerable<string> categoricalVariables = new List<string> { "TargetVariable", "Algorithm" };
|
---|
120 |
|
---|
121 | db.Disconnect();
|
---|
122 | VisualMatrix m = new VisualMatrix(Matrix, categoricalVariables, ordinalVariables, multiDimensionalCategoricalVariables, multiDimensionalOrdinalVariables);
|
---|
123 | return m;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | }
|
---|