Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2525 was 2525, checked in by mkommend, 13 years ago

adapted SQLServerCompact database backend to meet new requirements regarding multiple connections (ticket #800)

File size: 2.1 KB
Line 
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();
39      Dataset temp = db.GetDataset();
40      if(temp == null)     
41        db.PersistProblem(ds);     
42
43      IAnalyzerModel model = new AnalyzerModel();                 
44      DefaultModelAnalyzerOperators.PopulateAnalyzerModel(scope, model, modelType);
45      db.Persist(model, algorithm, algorithm);
46      db.Disconnect();
47     
48
49      return null;
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.