- Timestamp:
- 05/22/12 15:27:19 (13 years ago)
- Location:
- branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DataProcessor
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DataProcessor/DataProcessorView.cs
r7267 r7868 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using System.ComponentModel; 25 26 using System.Drawing; 26 27 using System.Linq; 27 using System.Text;28 28 using System.Windows.Forms; 29 using System.IO; 30 using System.Reflection; 31 using HeuristicLab.PluginInfrastructure; 32 using HeuristicLab.DataImporter.DbExplorer.Interfaces; 29 using System.Xml; 33 30 using HeuristicLab.DataImporter.Data; 34 31 using HeuristicLab.DataImporter.Data.CommandBase; … … 36 33 using HeuristicLab.DataImporter.Data.View; 37 34 using HeuristicLab.DataImporter.DataProcessor.Command; 38 using System.Xml;35 using HeuristicLab.DataImporter.DbExplorer.Interfaces; 39 36 using HeuristicLab.Persistence.Default.Xml; 37 using HeuristicLab.PluginInfrastructure; 38 using HeuristicLab.Problems.DataAnalysis; 40 39 41 40 namespace HeuristicLab.DataImporter.DataProcessor { … … 357 356 this.SaveAs(); 358 357 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) { 363 362 try { 364 363 this.Cursor = Cursors.WaitCursor; 365 XmlGenerator.Serialize( this.dataProcessor, filename,9);364 XmlGenerator.Serialize(serialize, filename, 9); 366 365 this.Cursor = Cursors.Default; 367 366 this.Text = "Data Importer - " + lastSavedFile; … … 377 376 saveFileDialog.AddExtension = true; 378 377 saveFileDialog.RestoreDirectory = true; 378 saveFileDialog.Filter = "Regression Problem file (*.hl)|*.hl|Classification Problem file (*.hl)|*.hl|DataImporter file (*.dhl)|*.dhl|All files (*.*)|*.*"; 379 379 saveFileDialog.DefaultExt = "dhl"; 380 saveFileDialog.Filter = "DataImporter file (*.dhl)|*.dhl|All files (*.*)|*.*";380 saveFileDialog.FilterIndex = 3; 381 381 382 382 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 383 383 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); 386 424 } 387 425 … … 425 463 try { 426 464 this.Cursor = Cursors.WaitCursor; 427 XmlGenerator.Serialize(this.dataProcessor.CommandChain, saveFileDialog.FileName, 9);465 XmlGenerator.Serialize(this.dataProcessor.CommandChain, saveFileDialog.FileName, 9); 428 466 } 429 467 finally { -
branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DataProcessor/HeuristicLab.DataImporter.DataProcessor.csproj
r7632 r7868 94 94 </PropertyGroup> 95 95 <ItemGroup> 96 <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 96 97 <Reference Include="HeuristicLab.Common.Resources-3.3"> 97 98 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath> 98 99 <Private>False</Private> 99 100 </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" /> 100 103 <Reference Include="HeuristicLab.Persistence-3.3"> 101 104 <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath> … … 106 109 <Private>False</Private> 107 110 </Reference> 111 <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL" /> 108 112 <Reference Include="System" /> 109 113 <Reference Include="System.Core">
Note: See TracChangeset
for help on using the changeset viewer.