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