Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/PredictorPersister.cs @ 2591

Last change on this file since 2591 was 2530, checked in by mkommend, 15 years ago

changed modeling database backend to use a shared read connection => notification by exception if another program is connected to the database (ticket #759)

File size: 2.1 KB
RevLine 
[2482]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.DataAnalysis;
8
9namespace HeuristicLab.Modeling.Database.SQLServerCompact {
10  public class PredictorPersister : OperatorBase {
11
12    public PredictorPersister()
13      : base() {
14      AddVariableInfo(new VariableInfo("DatabaseFile", "Database file", typeof(StringData), VariableKind.In));     
15      AddVariableInfo(new VariableInfo("ModelType", "The ModelType", typeof(StringData), VariableKind.In));
16      AddVariableInfo(new VariableInfo("Dataset", "The input dataset", typeof(Dataset), VariableKind.In));
17      AddVariableInfo(new VariableInfo("AlgorithmName", "", typeof(StringData), VariableKind.In));
18    }
19
20    public override string Description {
21      get { return "Saves a predictor to a given database"; }
22    }
23
24    public override IOperation Apply(IScope scope) {
25      string database = GetVariableValue<StringData>("DatabaseFile", scope, true).Data;   
26      Dataset ds = GetVariableValue<Dataset>("Dataset", scope, true);
27      string mt = GetVariableValue<StringData>("ModelType",scope,true).Data;
28      string algorithm = GetVariableValue<StringData>("AlgorithmName",scope,true).Data;
29
30      ModelType modelType = ModelType.Regression;
31      if (Enum.IsDefined(typeof(ModelType), mt))
32        modelType = (ModelType)Enum.Parse(typeof(ModelType), mt);
33      else
34        throw new ArgumentException("Passed model type " + mt + " is not defined.\n Possible Values are: " +
35          string.Join(",",Enum.GetNames(typeof(ModelType))));
36
37      DatabaseService db = new DatabaseService(database);
38      db.Connect();
[2525]39      Dataset temp = db.GetDataset();
[2530]40      if (temp == null) {
41        db.PersistProblem(ds);
42        db.Commit();
43      }
[2482]44
[2525]45      IAnalyzerModel model = new AnalyzerModel();                 
[2482]46      DefaultModelAnalyzerOperators.PopulateAnalyzerModel(scope, model, modelType);
47      db.Persist(model, algorithm, algorithm);
[2530]48      db.Commit();
[2482]49      db.Disconnect();
[2525]50     
[2482]51
52      return null;
53    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.