Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7868


Ignore:
Timestamp:
05/22/12 15:27:19 (13 years ago)
Author:
sforsten
Message:

#1820: DataImporter can now save RegressionProblemData and ClassificationProblemData

Location:
branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DataProcessor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DataProcessor/DataProcessorView.cs

    r7267 r7868  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using System.ComponentModel;
    2526using System.Drawing;
    2627using System.Linq;
    27 using System.Text;
    2828using System.Windows.Forms;
    29 using System.IO;
    30 using System.Reflection;
    31 using HeuristicLab.PluginInfrastructure;
    32 using HeuristicLab.DataImporter.DbExplorer.Interfaces;
     29using System.Xml;
    3330using HeuristicLab.DataImporter.Data;
    3431using HeuristicLab.DataImporter.Data.CommandBase;
     
    3633using HeuristicLab.DataImporter.Data.View;
    3734using HeuristicLab.DataImporter.DataProcessor.Command;
    38 using System.Xml;
     35using HeuristicLab.DataImporter.DbExplorer.Interfaces;
    3936using HeuristicLab.Persistence.Default.Xml;
     37using HeuristicLab.PluginInfrastructure;
     38using HeuristicLab.Problems.DataAnalysis;
    4039
    4140namespace HeuristicLab.DataImporter.DataProcessor {
     
    357356        this.SaveAs();
    358357      else
    359         this.Save(this.lastSavedFile);
    360     }
    361 
    362     private void Save(string filename) {
     358        this.Save(dataProcessor, this.lastSavedFile);
     359    }
     360
     361    private void Save(object serialize, string filename) {
    363362      try {
    364363        this.Cursor = Cursors.WaitCursor;
    365         XmlGenerator.Serialize(this.dataProcessor, filename,9);
     364        XmlGenerator.Serialize(serialize, filename, 9);
    366365        this.Cursor = Cursors.Default;
    367366        this.Text = "Data Importer - " + lastSavedFile;
     
    377376      saveFileDialog.AddExtension = true;
    378377      saveFileDialog.RestoreDirectory = true;
     378      saveFileDialog.Filter = "Regression Problem file (*.hl)|*.hl|Classification Problem file (*.hl)|*.hl|DataImporter file (*.dhl)|*.dhl|All files (*.*)|*.*";
    379379      saveFileDialog.DefaultExt = "dhl";
    380       saveFileDialog.Filter = "DataImporter file (*.dhl)|*.dhl|All files (*.*)|*.*";
     380      saveFileDialog.FilterIndex = 3;
    381381
    382382      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
    383383        this.lastSavedFile = saveFileDialog.FileName;
    384         this.Save(this.lastSavedFile);
    385       }
     384        if (saveFileDialog.FilterIndex <= 2) {
     385          Dataset dataset = ConvertDataset(dataProcessor.DataSet);
     386          DataAnalysisProblemData problemData = null;
     387          if (saveFileDialog.FilterIndex == 1) {
     388            problemData = new RegressionProblemData(dataset, dataset.VariableNames, dataset.VariableNames.First());
     389          } else if (saveFileDialog.FilterIndex == 2) {
     390            problemData = new ClassificationProblemData(dataset, dataset.VariableNames, dataset.VariableNames.First());
     391          } else {
     392            throw new ArgumentException("File extension doesn't exist");
     393          }
     394          Save(problemData, lastSavedFile);
     395        } else {
     396          Save(dataProcessor, lastSavedFile);
     397        }
     398      }
     399    }
     400
     401    private Dataset ConvertDataset(DataSet dataSet) {
     402      ColumnGroup cg;
     403      if (dataSet.ActiveColumnGroups.Count() > 0) {
     404        cg = dataSet.ActiveColumnGroups.First();
     405      } else if (dataSet.ColumnGroups.Count() > 0) {
     406        cg = dataSet.ColumnGroups.First();
     407      } else {
     408        throw new ArgumentException("There exists no ColumnGroup which could be saved!");
     409      }
     410      List<IList> values = new List<IList>();
     411      foreach (var column in cg.Columns) {
     412        if (column.DataType.Equals(typeof(double?))) {
     413          values.Add(column.ValuesEnumerable.Cast<double?>().Select(x => x == null ? double.NaN : x).Cast<double>().ToList());
     414        } else if (column.DataType.Equals(typeof(string))) {
     415          values.Add(column.ValuesEnumerable.Cast<string>().ToList());
     416        } else if (column.DataType.Equals(typeof(DateTime?))) {
     417          values.Add(column.ValuesEnumerable.Cast<DateTime?>().Select(x => x == null ? new DateTime() : x).Cast<DateTime>().ToList());
     418        } else {
     419          throw new ArgumentException("The variable values must be of type List<double>, List<string> or List<DateTime>");
     420        }
     421      }
     422      IEnumerable<string> variableNames = cg.Columns.Select(x => x.Name);
     423      return new Dataset(variableNames, values);
    386424    }
    387425
     
    425463        try {
    426464          this.Cursor = Cursors.WaitCursor;
    427           XmlGenerator.Serialize(this.dataProcessor.CommandChain, saveFileDialog.FileName,9);
     465          XmlGenerator.Serialize(this.dataProcessor.CommandChain, saveFileDialog.FileName, 9);
    428466        }
    429467        finally {
  • branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DataProcessor/HeuristicLab.DataImporter.DataProcessor.csproj

    r7632 r7868  
    9494  </PropertyGroup>
    9595  <ItemGroup>
     96    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    9697    <Reference Include="HeuristicLab.Common.Resources-3.3">
    9798      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
    9899      <Private>False</Private>
    99100    </Reference>
     101    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
     102    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    100103    <Reference Include="HeuristicLab.Persistence-3.3">
    101104      <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
     
    106109      <Private>False</Private>
    107110    </Reference>
     111    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" />
    108112    <Reference Include="System" />
    109113    <Reference Include="System.Core">
Note: See TracChangeset for help on using the changeset viewer.