Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.cs @ 10256

Last change on this file since 10256 was 10256, checked in by rstoll, 11 years ago

Fixed View error

File size: 3.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Windows.Forms;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Core.Views;
8using HeuristicLab.Data;
9using HeuristicLab.MainForm;
10using HeuristicLab.Optimization;
11using HeuristicLab.Problems.DataAnalysis;
12
13namespace HeuristicLab.DataPreprocessing {
14  [View("DataPreprocessing View")]
15  [Content(typeof(PreprocessingContext), true)]
16  public partial class DataPreprocessingView : ItemView {
17
18    private DataGridContent dataGridContent;
19    private Dictionary<ListViewItem, IItem> listViewItemItemMapping;
20
21
22    public DataPreprocessingView() {
23      InitializeComponent();
24
25      InitializeContents();
26
27    }
28
29
30    private ListViewItem CreateListViewItem(IItem item) {
31      ListViewItem listViewItem = new ListViewItem();
32
33      listViewItem.Text = item.ToString();
34      //listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
35      //itemsListView.SmallImageList.Images.Add(content.);
36      //listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
37      //listViewItem.Tag = item;
38      return listViewItem;
39    }
40
41    private void InitializeContents() {
42      IPreprocessingData data = Content != null ? this.Content.Data : null;
43      ISearchLogic searchLogic = new SearchLogic(data);
44      dataGridContent = new DataGridContent(new DataGridLogic(data), new PreprocessingDataManipulation(data, searchLogic, new StatisticsLogic(data, searchLogic)));
45
46      listViewItemItemMapping = new Dictionary<ListViewItem, IItem>();
47      ListViewItem contentListViewItem = CreateListViewItem(dataGridContent);
48      listViewItemItemMapping[contentListViewItem] = dataGridContent;
49
50      contentListView.Items.Add(contentListViewItem);
51    }
52
53    public new PreprocessingContext Content {
54      get { return (PreprocessingContext)base.Content; }
55      set { base.Content = value; }
56    }
57
58    private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
59
60      if (contentListView.SelectedItems.Count > 0) {
61        ListViewItem listViewItem = (ListViewItem)contentListView.SelectedItems[0];
62        this.viewHost.Content = listViewItemItemMapping[listViewItem];
63      }
64    }
65
66    private void listView1_DoubleClick(object sender, EventArgs e) {
67      ListViewItem listViewItem = (ListViewItem)contentListView.SelectedItems[0];
68      MainFormManager.MainForm.ShowContent(listViewItemItemMapping[listViewItem]);
69    }
70
71    private void tryOutAlgorithmButton_Click(object sender, EventArgs e) {
72      IPreprocessingData Data = Content.Data;
73
74      foreach (string variable in Data.VariableNames) {
75        for (int j = 0; j < Data.Rows; j++) {
76          // assume: all double
77          Data.SetCell(variable, j, 1.0);
78        }
79      }
80
81      MessageBox.Show("Success, now cloning... ");
82
83      Dataset dataset = Data.ExportToDataset();
84      var variables = new CheckedItemList<StringValue>(Data.VariableNames.Select(s => new StringValue(s))).AsReadOnly();
85
86      var cloner = new Cloner();
87
88      cloner.RegisterClonedObject(Content.DataAnalysisProblemData.Dataset, dataset);
89      cloner.RegisterClonedObject(Content.DataAnalysisProblemData.TrainingPartition, Data.TrainingPartition);
90      cloner.RegisterClonedObject(Content.DataAnalysisProblemData.TestPartition, Data.TestPartition);
91      cloner.RegisterClonedObject(Content.DataAnalysisProblemData.InputVariables, variables);
92      if (Content.Algorithm != null) {
93        cloner.RegisterClonedObject(Content.Algorithm.Runs, new RunCollection { OptimizerName = Content.Algorithm.Name });
94      }
95
96      var item = cloner.Clone(Content.ParentItem);
97
98      MainFormManager.MainForm.ShowContent(item);
99    }
100  }
101}
102
Note: See TracBrowser for help on using the repository browser.