[2482] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Data;
|
---|
| 7 | using HeuristicLab.DataAnalysis;
|
---|
| 8 |
|
---|
| 9 | namespace 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 | }
|
---|