Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Core/3.3/Console.cs @ 2321

Last change on this file since 2321 was 2321, checked in by gkronber, 15 years ago

Fixed #730 (Variable impacts of models can't be displayed in CEDMA console).

File size: 4.5 KB
RevLine 
[372]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
22using System;
[357]23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Xml;
28using System.ServiceModel;
29using System.ServiceModel.Description;
[2223]30using HeuristicLab.PluginInfrastructure;
31using HeuristicLab.Modeling.Database.SQLServerCompact;
[2289]32using HeuristicLab.SparseMatrix;
33using HeuristicLab.Modeling.Database;
34using HeuristicLab.CEDMA.Charting;
[357]35
[377]36namespace HeuristicLab.CEDMA.Core {
[357]37  public class Console : ItemBase, IEditable {
[2273]38    private static readonly string sqlServerCompactConnectionString = @"Data Source=";
[357]39
[2289]40    public Console()
41      : base() {
42    }
43
[2273]44    private string database;
45    public string Database {
46      get {
47        return database;
48      }
49      set {
50        if (value != database) {
51          database = value;
[2289]52          matrix = null;
53          visualMatrix = null;
[2273]54        }
55      }
56    }
57
[2289]58    private Matrix matrix;
59    public Matrix Matrix {
[2223]60      get {
[2289]61        if (matrix == null) LoadResults();
62        return matrix;
[2223]63      }
[357]64    }
[2289]65
66    private VisualMatrix visualMatrix;
67    public VisualMatrix VisualMatrix {
68      get {
69        if (matrix == null)
70          visualMatrix = CreateVisualMatrix();
71        return visualMatrix;
72      }
[357]73    }
74
75    public IEditor CreateEditor() {
76      return new ConsoleEditor(this);
77    }
78
[383]79    public override IView CreateView() {
[357]80      return new ConsoleEditor(this);
81    }
82
[2289]83    private void LoadResults() {
84      matrix = new Matrix();
85      DatabaseService db = new DatabaseService(sqlServerCompactConnectionString + database);
86      db.Connect();
87
88      foreach (var model in db.GetAllModels()) {
89        MatrixRow row = new MatrixRow();
90        foreach (var modelResult in db.GetModelResults(model)) {
91          row.Set(modelResult.Result.Name, modelResult.Value);
92        }
[2321]93        Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow> inputVariableResultsEntries =
94          new Dictionary<HeuristicLab.Modeling.Database.IVariable, MatrixRow>();
95        foreach (IInputVariableResult inputVariableResult in db.GetInputVariableResults(model)) {
96          if (!inputVariableResultsEntries.ContainsKey(inputVariableResult.Variable)) {
97            inputVariableResultsEntries[inputVariableResult.Variable] = new MatrixRow();
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
[2289]104        row.Set("PersistedData", db.GetModelData(model));
105        row.Set("TargetVariable", model.TargetVariable.Name);
106        row.Set("Algorithm", model.Algorithm.Name);
[2321]107
[2289]108        matrix.AddRow(row);
109      }
110      db.Disconnect();
[357]111    }
[2289]112
[2321]113    private VisualMatrix CreateVisualMatrix() {
[2289]114      DatabaseService db = new DatabaseService(sqlServerCompactConnectionString + database);
115      db.Connect();
[2295]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" };
[2289]120
121      db.Disconnect();
122      VisualMatrix m = new VisualMatrix(Matrix, categoricalVariables, ordinalVariables, multiDimensionalCategoricalVariables, multiDimensionalOrdinalVariables);
123      return m;
124    }
[357]125  }
126}
Note: See TracBrowser for help on using the repository browser.