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