Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7309


Ignore:
Timestamp:
01/10/12 17:36:58 (13 years ago)
Author:
sforsten
Message:

#1752: -data set is exported exactly in the way it is stored in the Dataset class

Location:
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisProblemView.Designer.cs

    r7290 r7309  
    4747      this.ImportButton = new System.Windows.Forms.Button();
    4848      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    49       this.BenchmarkComboBox = new System.Windows.Forms.ComboBox();
    5049      this.LoadButton = new System.Windows.Forms.Button();
    5150      this.BenchmarkTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
     51      this.ExportButton = new System.Windows.Forms.Button();
     52      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    5253      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5354      this.BenchmarkTableLayoutPanel.SuspendLayout();
     
    5657      // parameterCollectionView
    5758      //
    58       this.parameterCollectionView.Location = new System.Drawing.Point(3, 80);
    59       this.parameterCollectionView.Size = new System.Drawing.Size(490, 254);
     59      this.parameterCollectionView.Location = new System.Drawing.Point(3, 56);
     60      this.parameterCollectionView.Size = new System.Drawing.Size(490, 278);
    6061      this.parameterCollectionView.TabIndex = 4;
    6162      //
     
    7475      this.ImportButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    7576            | System.Windows.Forms.AnchorStyles.Right)));
    76       this.ImportButton.Location = new System.Drawing.Point(3, 24);
     77      this.ImportButton.Location = new System.Drawing.Point(3, 3);
    7778      this.ImportButton.Name = "ImportButton";
    78       this.ImportButton.Size = new System.Drawing.Size(487, 23);
     79      this.ImportButton.Size = new System.Drawing.Size(158, 21);
    7980      this.ImportButton.TabIndex = 3;
    80       this.ImportButton.Text = "Import from CSV file";
     81      this.ImportButton.Text = "Import ProblemData from CSV file";
    8182      this.ImportButton.UseVisualStyleBackColor = true;
    8283      this.ImportButton.Click += new System.EventHandler(this.ImportButton_Click);
     
    8586      //
    8687      this.openFileDialog.Filter = "CSV files|*.csv|Text files|*.txt|All files|*.*";
    87       this.openFileDialog.Title = "Import data...";
    88       //
    89       // BenchmarkComboBox
    90       //
    91       this.BenchmarkComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    92             | System.Windows.Forms.AnchorStyles.Right)));
    93       this.BenchmarkComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    94       this.BenchmarkComboBox.FormattingEnabled = true;
    95       this.BenchmarkComboBox.Location = new System.Drawing.Point(3, 3);
    96       this.BenchmarkComboBox.Name = "BenchmarkComboBox";
    97       this.BenchmarkComboBox.Size = new System.Drawing.Size(240, 21);
    98       this.BenchmarkComboBox.TabIndex = 5;
     88      this.openFileDialog.Title = "Import ProblemData...";
    9989      //
    10090      // LoadButton
     
    10292      this.LoadButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    10393            | System.Windows.Forms.AnchorStyles.Right)));
    104       this.LoadButton.Location = new System.Drawing.Point(249, 2);
     94      this.LoadButton.Location = new System.Drawing.Point(167, 2);
    10595      this.LoadButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 3);
    10696      this.LoadButton.Name = "LoadButton";
    107       this.LoadButton.Size = new System.Drawing.Size(241, 23);
     97      this.LoadButton.Size = new System.Drawing.Size(158, 23);
    10898      this.LoadButton.TabIndex = 6;
    109       this.LoadButton.Text = "Load";
     99      this.LoadButton.Text = "Generate Benchmark ProblemData";
    110100      this.LoadButton.UseVisualStyleBackColor = true;
    111       this.LoadButton.Click += new System.EventHandler(this.loadButton_Click);
     101      this.LoadButton.Click += new System.EventHandler(this.LoadButton_Click);
    112102      //
    113103      // BenchmarkTableLayoutPanel
     
    115105      this.BenchmarkTableLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    116106            | System.Windows.Forms.AnchorStyles.Right)));
    117       this.BenchmarkTableLayoutPanel.ColumnCount = 2;
    118       this.BenchmarkTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    119       this.BenchmarkTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    120       this.BenchmarkTableLayoutPanel.Controls.Add(this.BenchmarkComboBox, 0, 0);
     107      this.BenchmarkTableLayoutPanel.ColumnCount = 3;
     108      this.BenchmarkTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
     109      this.BenchmarkTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
     110      this.BenchmarkTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
    121111      this.BenchmarkTableLayoutPanel.Controls.Add(this.LoadButton, 1, 0);
    122       this.BenchmarkTableLayoutPanel.Location = new System.Drawing.Point(0, 51);
     112      this.BenchmarkTableLayoutPanel.Controls.Add(this.ImportButton, 0, 0);
     113      this.BenchmarkTableLayoutPanel.Controls.Add(this.ExportButton, 2, 0);
     114      this.BenchmarkTableLayoutPanel.Location = new System.Drawing.Point(0, 26);
    123115      this.BenchmarkTableLayoutPanel.Name = "BenchmarkTableLayoutPanel";
    124116      this.BenchmarkTableLayoutPanel.RowCount = 1;
    125       this.BenchmarkTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
     117      this.BenchmarkTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
    126118      this.BenchmarkTableLayoutPanel.Size = new System.Drawing.Size(493, 28);
    127119      this.BenchmarkTableLayoutPanel.TabIndex = 7;
     120      //
     121      // ExportButton
     122      //
     123      this.ExportButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     124            | System.Windows.Forms.AnchorStyles.Right)));
     125      this.ExportButton.Location = new System.Drawing.Point(331, 3);
     126      this.ExportButton.Name = "ExportButton";
     127      this.ExportButton.Size = new System.Drawing.Size(159, 22);
     128      this.ExportButton.TabIndex = 7;
     129      this.ExportButton.Text = "Export ProblemData to CSV file";
     130      this.ExportButton.UseVisualStyleBackColor = true;
     131      this.ExportButton.Click += new System.EventHandler(this.ExportButton_Click);
     132      //
     133      // saveFileDialog
     134      //
     135      this.saveFileDialog.Filter = "CSV files|*.csv|All files|*.*";
     136      this.saveFileDialog.Title = "Save ProblemData...";
    128137      //
    129138      // DataAnalysisProblemView
     
    131140      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    132141      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    133       this.Controls.Add(this.ImportButton);
    134142      this.Controls.Add(this.BenchmarkTableLayoutPanel);
    135143      this.Name = "DataAnalysisProblemView";
    136144      this.Size = new System.Drawing.Size(493, 334);
    137145      this.Controls.SetChildIndex(this.BenchmarkTableLayoutPanel, 0);
    138       this.Controls.SetChildIndex(this.ImportButton, 0);
    139146      this.Controls.SetChildIndex(this.parameterCollectionView, 0);
    140147      this.Controls.SetChildIndex(this.infoLabel, 0);
     
    152159    private System.Windows.Forms.Button ImportButton;
    153160    private System.Windows.Forms.OpenFileDialog openFileDialog;
    154     private System.Windows.Forms.ComboBox BenchmarkComboBox;
    155161    private System.Windows.Forms.Button LoadButton;
    156162    private System.Windows.Forms.TableLayoutPanel BenchmarkTableLayoutPanel;
     163    private System.Windows.Forms.Button ExportButton;
     164    private System.Windows.Forms.SaveFileDialog saveFileDialog;
    157165  }
    158166}
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisProblemView.cs

    r7290 r7309  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
     23using System.IO;
     24using System.Text;
    2525using System.Windows.Forms;
    26 using HeuristicLab.Common;
    2726using HeuristicLab.MainForm;
    2827using HeuristicLab.Optimization.Views;
     
    3332  [Content(typeof(IDataAnalysisProblem), true)]
    3433  public partial class DataAnalysisProblemView : ProblemView {
     34
     35    private BenchmarkGeneratorDialog problemDataSelectorDialog;
     36
    3537    public DataAnalysisProblemView() {
    3638      InitializeComponent();
     
    4648      ImportButton.Enabled = !Locked && !ReadOnly && Content != null;
    4749      LoadButton.Enabled = !Locked && !ReadOnly && Content != null;
    48       BenchmarkComboBox.Enabled = !Locked && !ReadOnly && Content != null;
     50      ExportButton.Enabled = !Locked && !ReadOnly && Content != null;
    4951    }
    5052
     
    6062    }
    6163
    62     private void loadButton_Click(object sender, EventArgs e) {
    63       if (BenchmarkComboBox.SelectedItem != null)
    64         Content.ProblemData = ((IDataAnalysisBenchmarkProblemDataGenerator)BenchmarkComboBox.SelectedItem).GenerateProblemData();
     64    private void LoadButton_Click(object sender, EventArgs e) {
     65      if (problemDataSelectorDialog == null) {
     66        problemDataSelectorDialog = new BenchmarkGeneratorDialog(Content);
     67      }
     68      if (problemDataSelectorDialog.ShowDialog(this) == DialogResult.OK) {
     69        try {
     70          Content.ProblemData = problemDataSelectorDialog.ProblemData;
     71        }
     72        catch (Exception ex) {
     73          ErrorHandling.ShowErrorDialog(this, ex);
     74        }
     75      }
    6576    }
    6677
    67     protected override void OnContentChanged() {
    68       base.OnContentChanged();
    69       BenchmarkComboBox.Items.Clear();
    70       BenchmarkComboBox.Items.AddRange(GetBenchmarkProblemDataGenerators().OrderBy(b => b.Name, new NaturalStringComparer()).ToArray());
    71       if (BenchmarkComboBox.Items.Count > 0)
    72         BenchmarkComboBox.SelectedIndex = 0;
     78    private void ExportButton_Click(object sender, EventArgs e) {
     79      if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
     80        try {
     81          ExportProblemData(Content.ProblemData.Dataset, saveFileDialog.FileName);
     82        }
     83        catch (Exception ex) {
     84          ErrorHandling.ShowErrorDialog(this, ex);
     85        }
     86      }
    7387    }
    7488
    75     protected IEnumerable<IDataAnalysisBenchmarkProblemDataGenerator> GetBenchmarkProblemDataGenerators() {
    76       if (Content is IRegressionProblem)
    77         return ApplicationManager.Manager.GetInstances<IRegressionBenchmarkProblemDataGenerator>();
    78       else if (Content is IClassificationProblem)
    79         return ApplicationManager.Manager.GetInstances<IClassificationBenchmarkProblemDataGenerator>();
    80       else if (Content is IClusteringProblem)
    81         return ApplicationManager.Manager.GetInstances<IClusteringBenchmarkProblemDataGenerator>();
    82       return new List<IDataAnalysisBenchmarkProblemDataGenerator>();
     89    private void ExportProblemData(Dataset dataset, string file) {
     90      StringBuilder strBuilder = new StringBuilder();
     91
     92      foreach (var variable in dataset.VariableNames) {
     93        strBuilder.Append(variable + ";");
     94      }
     95      strBuilder.Remove(strBuilder.Length - 1, 1);
     96      strBuilder.AppendLine();
     97
     98      for (int i = 0; i < dataset.Rows; i++) {
     99        for (int j = 0; j < dataset.Columns; j++) {
     100          strBuilder.Append(dataset.GetValue(i, j) + ";");
     101        }
     102        strBuilder.Remove(strBuilder.Length - 1, 1);
     103        strBuilder.AppendLine();
     104      }
     105
     106      using (StreamWriter writer = new StreamWriter(file)) {
     107        writer.Write(strBuilder);
     108      }
    83109    }
    84110  }
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisProblemView.resx

    r7127 r7309  
    121121    <value>107, 17</value>
    122122  </metadata>
     123  <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     124    <value>107, 17</value>
     125  </metadata>
    123126  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    124127    <value>17, 17</value>
     
    127130    <value>230, 17</value>
    128131  </metadata>
     132  <metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     133    <value>363, 17</value>
     134  </metadata>
    129135</root>
Note: See TracChangeset for help on using the changeset viewer.