Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/17/08 14:29:53 (15 years ago)
Author:
gkronber
Message:

worked on CEDMA console and problem importer. #419 (Refactor CEDMA plugins)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ProblemView.cs

    r992 r1003  
    2929using System.Windows.Forms;
    3030using HeuristicLab.Core;
     31using HeuristicLab.DataAnalysis;
    3132
    3233namespace HeuristicLab.CEDMA.Core {
     
    3839      InitializeComponent();
    3940    }
     41
     42    protected override void UpdateControls() {
     43      base.UpdateControls();
     44      // TASK update text-boxes and datasetview
     45    }
     46
     47    private void importButton_Click(object sender, EventArgs e) {
     48      if(openFileDialog.ShowDialog(this) == DialogResult.OK) {
     49        DatasetParser parser = new DatasetParser();
     50        bool success = false;
     51        try {
     52          try {
     53            parser.Import(openFileDialog.FileName, true);
     54            success = true;
     55          } catch(DataFormatException ex) {
     56            ShowWarningMessageBox(ex);
     57            // not possible to parse strictly => clear and try to parse non-strict
     58            parser.Reset();
     59            parser.Import(openFileDialog.FileName, false);
     60            success = true;
     61          }
     62        } catch(DataFormatException ex) {
     63          // if the non-strict parsing also failed then show the exception
     64          ShowErrorMessageBox(ex);
     65        }
     66        if(success) {
     67          Dataset dataset = (Dataset)problem.DataSet;
     68          dataset.Rows = parser.Rows;
     69          dataset.Columns = parser.Columns;
     70          dataset.VariableNames = parser.VariableNames;
     71          dataset.Name = parser.ProblemName;
     72          dataset.Samples = new double[dataset.Rows * dataset.Columns];
     73          Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
     74          problem.TrainingSamplesStart = parser.TrainingSamplesStart;
     75          problem.ValidationSamplesEnd = parser.TrainingSamplesStart;
     76          problem.TrainingSamplesEnd = parser.TrainingSamplesEnd;
     77          problem.ValidationSamplesStart = parser.ValidationSamplesStart;
     78          problem.ValidationSamplesEnd = parser.ValidationSamplesEnd;
     79          problem.TestSamplesStart = parser.TestSamplesStart;
     80          problem.TestSamplesEnd = parser.TestSamplesEnd;
     81          problem.AllowedTargetVariables.Add(parser.TargetVariable);
     82
     83          List<int> nonInputVariables = parser.NonInputVariables;
     84          for(int i = 0; i < dataset.Columns; i++) {
     85            if(!nonInputVariables.Contains(i)) problem.AllowedInputVariables.Add(i);
     86          }
     87          Refresh();
     88        }
     89      }
     90
     91    }
     92    private void ShowWarningMessageBox(Exception ex) {
     93      MessageBox.Show(ex.Message,
     94                      "Warning - " + ex.GetType().Name,
     95                      MessageBoxButtons.OK,
     96                      MessageBoxIcon.Warning);
     97    }
     98    private void ShowErrorMessageBox(Exception ex) {
     99      MessageBox.Show(BuildErrorMessage(ex),
     100                      "Error - " + ex.GetType().Name,
     101                      MessageBoxButtons.OK,
     102                      MessageBoxIcon.Error);
     103    }
     104    private string BuildErrorMessage(Exception ex) {
     105      StringBuilder sb = new StringBuilder();
     106      sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     107
     108      while(ex.InnerException != null) {
     109        ex = ex.InnerException;
     110        sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     111      }
     112      return sb.ToString();
     113    }
    40114  }
    41115}
Note: See TracChangeset for help on using the changeset viewer.