Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/14 15:08:11 (11 years ago)
Author:
mkommend
Message:

#1758: Reimplemented functionality to load new problem data to data analysis solution and redesigned the according views.

  • Added setter for the target variable of regression and classification problem data.
  • Added functionality to check the compatibility of problem data.
  • Added functionality to adjust the properties of a problem data.
  • Added flowLayoutPanel with according buttons for loading a new problem data, simplifying and exporting data analysis solutions.
  • TradingProblemData currently throws a NotSupportedException when the properties should be adjusted.
Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClassificationSolutionView.cs

    r10175 r10540  
    2020#endregion
    2121
    22 using System;
    2322using System.Windows.Forms;
    24 using HeuristicLab.Common;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.MainForm;
    27 using HeuristicLab.PluginInfrastructure;
    2825
    2926namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    5451    }
    5552    #endregion
    56 
    57     protected override bool CheckCompatibilityOfProblemData(IDataAnalysisProblemData problemData) {
    58       IClassificationProblemData classificationProblemData = problemData as IClassificationProblemData;
    59       if (classificationProblemData == null) {
    60         ErrorHandling.ShowErrorDialog(this, new ArgumentException("The problem data is no classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided."));
    61         return false;
    62       }
    63 
    64       if (!classificationProblemData.TargetVariable.Equals(Content.ProblemData.TargetVariable)) {
    65         string message = "The target variables are not matching. Old target variable: '"
    66                          + Content.ProblemData.TargetVariable
    67                          + "'. New targetvariable: '" + classificationProblemData.TargetVariable + "'";
    68         ErrorHandling.ShowErrorDialog(this, new InvalidOperationException(message));
    69         return false;
    70       }
    71 
    72       return base.CheckCompatibilityOfProblemData(problemData);
    73     }
    7453  }
    7554}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.Designer.cs

    r10175 r10540  
    1919 */
    2020#endregion
    21 
    2221
    2322namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    4645    /// </summary>
    4746    private void InitializeComponent() {
    48       this.exportButton = new System.Windows.Forms.Button();
    49       this.exportFileDialog = new System.Windows.Forms.SaveFileDialog();
     47      this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
    5048      this.loadProblemDataButton = new System.Windows.Forms.Button();
    5149      this.loadProblemDataFileDialog = new System.Windows.Forms.OpenFileDialog();
     
    5755      this.detailsGroupBox.SuspendLayout();
    5856      this.SuspendLayout();
     57      //
     58      // itemslistView
     59      //
     60      this.itemsListView.Location = new System.Drawing.Point(this.itemsListView.Location.X, this.itemsListView.Location.Y + 3);
     61      //
     62      // detailsGroupBox
     63      //
     64      this.detailsGroupBox.Location = new System.Drawing.Point(this.detailsGroupBox.Location.X, this.detailsGroupBox.Location.Y + 3);
     65      //
    5966      //
    6067      // splitContainer
     
    6370      // splitContainer.Panel2
    6471      //
    65       this.splitContainer.Panel2.Controls.Add(this.loadProblemDataButton);
    66       this.splitContainer.Panel2.Controls.Add(this.exportButton);
     72      this.splitContainer.Panel2.Controls.Add(this.flowLayoutPanel);
    6773      //
    6874      // itemsGroupBox
    6975      //
    7076      this.itemsGroupBox.Text = "Data Analysis Solution";
    71       //
    72       // addButton
    73       //
    74       this.toolTip.SetToolTip(this.addButton, "Add");
    75       //
    76       // removeButton
    77       //
    78       this.toolTip.SetToolTip(this.removeButton, "Remove");
    79       //
    80       // exportButton
    81       //
    82       this.exportButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    83       this.exportButton.Location = new System.Drawing.Point(194, 3);
    84       this.exportButton.Name = "exportButton";
    85       this.exportButton.Size = new System.Drawing.Size(75, 24);
    86       this.exportButton.TabIndex = 6;
    87       this.exportButton.Text = "Export";
    88       this.exportButton.UseVisualStyleBackColor = true;
    89       this.exportButton.Click += new System.EventHandler(this.exportButton_Click);
     77      //
     78      // flowLayoutPanel
     79      //
     80      this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
     81      this.flowLayoutPanel.FlowDirection = System.Windows.Forms.FlowDirection.LeftToRight;
     82      this.flowLayoutPanel.Location = new System.Drawing.Point(0, 0);
     83      this.flowLayoutPanel.Padding = new System.Windows.Forms.Padding(3, 0, 3, 0);
     84      this.flowLayoutPanel.Size = new System.Drawing.Size(266, 30);
     85      this.flowLayoutPanel.Controls.Add(this.loadProblemDataButton);
    9086      //
    9187      // loadProblemDataButton
    9288      //
    93       this.loadProblemDataButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)));
    94       this.loadProblemDataButton.Location = new System.Drawing.Point(3, 3);
     89      this.loadProblemDataButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
     90      this.loadProblemDataButton.AutoSize = true;
     91      this.loadProblemDataButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Open;
     92      this.loadProblemDataButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
    9593      this.loadProblemDataButton.Name = "loadProblemDataButton";
    96       this.loadProblemDataButton.Size = new System.Drawing.Size(75, 24);
    97       this.loadProblemDataButton.TabIndex = 7;
    98       this.loadProblemDataButton.Text = "Load Data";
     94      this.loadProblemDataButton.Size = new System.Drawing.Size(105, 24);
     95      this.loadProblemDataButton.TabIndex = 6;
     96      this.loadProblemDataButton.Text = "Load new Data";
     97      this.loadProblemDataButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
    9998      this.loadProblemDataButton.UseVisualStyleBackColor = true;
    10099      this.loadProblemDataButton.Click += new System.EventHandler(this.loadProblemDataButton_Click);
     
    122121    #endregion
    123122
    124     private System.Windows.Forms.SaveFileDialog exportFileDialog;
    125     protected System.Windows.Forms.Button exportButton;
    126123    protected System.Windows.Forms.Button loadProblemDataButton;
    127124    protected System.Windows.Forms.OpenFileDialog loadProblemDataFileDialog;
     125    protected System.Windows.Forms.FlowLayoutPanel flowLayoutPanel;
    128126
    129127  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs

    r10175 r10540  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.ComponentModel;
    2524using System.Drawing;
    2625using System.Linq;
    27 using System.Text;
    2826using System.Windows.Forms;
    2927using HeuristicLab.Core;
     
    5452      addButton.Enabled = false;
    5553      removeButton.Enabled = false;
    56       if (Content == null) {
    57         exportButton.Enabled = false;
    58         loadProblemDataButton.Enabled = false;
    59       } else {
    60         exportButton.Enabled = !Locked;
    61         loadProblemDataButton.Enabled = !Locked;
    62       }
     54      loadProblemDataButton.Enabled = Content != null && !Locked;
    6355    }
    6456
     
    133125    protected virtual void loadProblemDataButton_Click(object sender, EventArgs e) {
    134126      if (loadProblemDataFileDialog.ShowDialog(this) != DialogResult.OK) return;
    135       object hlFile = XmlParser.Deserialize(loadProblemDataFileDialog.FileName);
    136 
    137       IDataAnalysisProblemData problemData = null;
    138       if (hlFile is IDataAnalysisProblemData) {
    139         problemData = (IDataAnalysisProblemData)hlFile;
    140       } else if (hlFile is IDataAnalysisProblem) {
    141         problemData = ((IDataAnalysisProblem)hlFile).ProblemData;
    142       } else if (hlFile is IDataAnalysisSolution) {
    143         problemData = ((IDataAnalysisSolution)hlFile).ProblemData;
    144       }
    145 
    146       if (problemData == null) {
    147         ErrorHandling.ShowErrorDialog(this, new NullReferenceException("The problem data is null." + Environment.NewLine
    148                                       + "The .hl-file contains no DataAnalysisProblemData or DataAnylsisProblem."));
    149         return;
    150       }
    151 
    152       if (CheckCompatibilityOfProblemData(problemData)) {
     127      try {
     128        object hlFile = XmlParser.Deserialize(loadProblemDataFileDialog.FileName);
     129
     130        IDataAnalysisProblemData problemData = null;
     131        if (hlFile is IDataAnalysisProblemData) {
     132          problemData = (IDataAnalysisProblemData)hlFile;
     133        } else if (hlFile is IDataAnalysisProblem) {
     134          problemData = ((IDataAnalysisProblem)hlFile).ProblemData;
     135        } else if (hlFile is IDataAnalysisSolution) {
     136          problemData = ((IDataAnalysisSolution)hlFile).ProblemData;
     137        }
     138
     139        if (problemData == null)
     140          throw new InvalidOperationException("The chosen HeuristicLab file does not contain a ProblemData, Problem, or DataAnalysisSolution.");
     141
    153142        var solution = (IDataAnalysisSolution)Content.Clone();
     143        problemData.AdjustProblemDataProperties(solution.ProblemData);
    154144        solution.ProblemData = problemData;
    155         solution.Name += " with loaded problem data (" + loadProblemDataFileDialog + ")";
     145        if (!solution.Name.EndsWith(" with loaded problemData"))
     146          solution.Name += " with loaded problemData";
    156147        MainFormManager.MainForm.ShowContent(solution);
    157148      }
    158     }
    159 
    160     private void exportButton_Click(object sender, EventArgs e) {
    161       var exporters = ApplicationManager.Manager.GetInstances<IDataAnalysisSolutionExporter>()
    162         .Where(exporter => exporter.Supports(Content)).ToArray();
    163       exportFileDialog.Filter = exporters.Skip(1)
    164         .Aggregate(exporters.First().FileTypeFilter, (s, exporter) => s + "|" + exporter.FileTypeFilter);
    165       var result = exportFileDialog.ShowDialog();
    166       if (result == DialogResult.OK) {
    167 
    168         var name = exportFileDialog.FileName;
    169         var selectedExporter = exporters.Single(exporter => exporter.FileTypeFilter == exportFileDialog.Filter);
    170 
    171         using (BackgroundWorker bg = new BackgroundWorker()) {
    172           MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Exportion solution to " + name + ".");
    173           bg.DoWork += (_, __) => selectedExporter.Export(Content, name);
    174           bg.RunWorkerCompleted += (_, __) => MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    175           bg.RunWorkerAsync();
    176         }
     149      catch (InvalidOperationException invalidOperationException) {
     150        ErrorHandling.ShowErrorDialog(this, invalidOperationException);
     151      }
     152      catch (ArgumentException argumentException) {
     153        ErrorHandling.ShowErrorDialog(this, argumentException);
    177154      }
    178155    }
     
    224201      validDragOperation = false;
    225202      if (ReadOnly) return;
     203      if (e.Effect != DragDropEffects.Copy) return;
    226204
    227205      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    228       if (dropData is DataAnalysisProblemData) validDragOperation = true;
     206      if (dropData is IDataAnalysisProblemData) validDragOperation = true;
    229207      else if (dropData is IDataAnalysisProblem) validDragOperation = true;
    230208      else if (dropData is IValueParameter) {
     
    248226      }
    249227      if (problemData == null) return;
    250       CheckCompatibilityOfProblemData(problemData);
    251       Content.ProblemData = (IDataAnalysisProblemData)problemData.Clone();
     228
     229      try {
     230        problemData.AdjustProblemDataProperties(Content.ProblemData);
     231        Content.ProblemData = problemData;
     232
     233        if (!Content.Name.EndsWith(" with changed problemData"))
     234          Content.Name += " with changed problemData";
     235      }
     236      catch (InvalidOperationException invalidOperationException) {
     237        ErrorHandling.ShowErrorDialog(this, invalidOperationException);
     238      }
     239      catch (ArgumentException argumentException) {
     240        ErrorHandling.ShowErrorDialog(this, argumentException);
     241      }
    252242    }
    253243    #endregion
    254244
    255     #region load problem data
    256     protected virtual bool CheckCompatibilityOfProblemData(IDataAnalysisProblemData problemData) {
    257       StringBuilder message = new StringBuilder();
    258       List<string> variables = problemData.InputVariables.Select(x => x.Value).ToList();
    259       foreach (var item in Content.ProblemData.InputVariables.CheckedItems) {
    260         if (!variables.Contains(item.Value.Value))
    261           message.AppendLine("Input variable '" + item.Value.Value + "' is not in the new problem data.");
    262       }
    263 
    264       if (message.Length != 0) {
    265         ErrorHandling.ShowErrorDialog(this, new InvalidOperationException(message.ToString()));
    266         return false;
    267       }
    268       return true;
    269     }
    270     #endregion
    271245  }
    272246}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs

    r10175 r10540  
    2020#endregion
    2121
    22 using System;
    2322using System.Windows.Forms;
    24 using HeuristicLab.Common;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.MainForm;
    27 using HeuristicLab.PluginInfrastructure;
    2825
    2926namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    5451    }
    5552    #endregion
    56 
    57     protected override bool CheckCompatibilityOfProblemData(IDataAnalysisProblemData problemData) {
    58       IRegressionProblemData regressionProblemData = problemData as IRegressionProblemData;
    59       if (regressionProblemData == null) {
    60         ErrorHandling.ShowErrorDialog(this, new ArgumentException("The problem data is no regression problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided."));
    61         return false;
    62       }
    63 
    64       if (!regressionProblemData.TargetVariable.Equals(Content.ProblemData.TargetVariable)) {
    65         string message = "The target variables are not matching. Old target variable: '"
    66                          + Content.ProblemData.TargetVariable
    67                          + "'. New targetvariable: '" + regressionProblemData.TargetVariable + "'";
    68         ErrorHandling.ShowErrorDialog(this, new InvalidOperationException(message));
    69         return false;
    70       }
    71 
    72       return base.CheckCompatibilityOfProblemData(problemData);
    73     }
    7453  }
    7554}
Note: See TracChangeset for help on using the changeset viewer.