forked from plasma-umass/DataDebug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerformanceExperiments.cs
More file actions
233 lines (191 loc) · 11.1 KB
/
PerformanceExperiments.cs
File metadata and controls
233 lines (191 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using DataDebugMethods;
namespace DataDebug
{
public partial class PerformanceExperiments : Form
{
string folderPath;
public PerformanceExperiments()
{
InitializeComponent();
}
private void selectFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog selectFolderDialog = new FolderBrowserDialog();
selectFolderDialog.ShowDialog();
if (selectFolderDialog.SelectedPath == "")
{
return;
}
//a folder was chosen
folderPath = @selectFolderDialog.SelectedPath;
//textBox1.Text += Environment.NewLine + "Folder was selected: " + folderPath;
textBox1.AppendText(Environment.NewLine + "Folder was selected: " + folderPath);
//textBox1.Text += Environment.NewLine + "Checking for necessary files";
textBox1.AppendText(Environment.NewLine + "Checking for files");
//Look for xls or xlsx
string[] xlsFilePaths = Directory.GetFiles(folderPath, "*.xls");
//sstring[] xlsxFilePaths = Directory.GetFiles(folderPath, "*.xlsx");
if (xlsFilePaths.Length == 0)
{
//textBox1.Text += Environment.NewLine + "ERROR: XLS/XLSX file not found";
textBox1.AppendText(Environment.NewLine + "ERROR: No *.xls or *.xlsx files found.");
return;
}
} //end selectFolder_Click
private void runExperiments_Click(object sender, EventArgs e)
{
string[] xlsFilePaths = Directory.GetFiles(folderPath, "*.xls");
string results = "Workbook name" + "\tBootstraps" + "\tTotal Time" + "\tTree Building Time" + "\tBootstrap Time" +
"\tColoring Time" + Environment.NewLine;
foreach (string xlsFilePath in xlsFilePaths)
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
TimeSpan tree_building_timespan;
TimeSpan bootstrap_timespan;
TimeSpan coloring_timespan;
TimeSpan total_timespan;
textBox1.AppendText(Environment.NewLine + "Opening Excel file: " + xlsFilePath + Environment.NewLine);
// Get current app
Excel.Application app = Globals.ThisAddIn.Application;
Excel.Workbook originalWB = app.Workbooks.Open(xlsFilePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
textBox1.AppendText(Environment.NewLine + "Running bootstrap analysis." + Environment.NewLine);
//Disable screen updating during perturbation and analysis to speed things up
Globals.ThisAddIn.Application.ScreenUpdating = false;
// Make a new analysisData object
AnalysisData data = new AnalysisData(app, app.ActiveWorkbook, false);
data.worksheets = app.Worksheets;
// Construct a new tree every time the tool is run
data.Reset();
stopwatch.Start();
// Build dependency graph (modifies data)
ConstructTree.constructTree(data, app.ActiveWorkbook, app);
tree_building_timespan = stopwatch.Elapsed;
string tree_building_time = tree_building_timespan.TotalSeconds + "";
if (data.TerminalInputNodes().Length == 0)
{
System.Windows.Forms.MessageBox.Show("This spreadsheet has no input ranges. Sorry, dude.");
data.pb.Close();
Globals.ThisAddIn.Application.ScreenUpdating = true;
return;
}
// e * bootstrapMultiplier
int bootstrapMultiplier = (int)numericUpDown1.Value;
var NBOOTS = (int)(Math.Ceiling(bootstrapMultiplier * Math.Exp(1.0)));
// Get bootstraps
var scores = Analysis.Bootstrap(NBOOTS, data, app, true);
bootstrap_timespan = stopwatch.Elapsed;
string bootstrap_time = (bootstrap_timespan.TotalSeconds - tree_building_timespan.TotalSeconds) + "";
// Color outputs
Analysis.ColorOutliers(scores);
stopwatch.Stop();
total_timespan = stopwatch.Elapsed;
string total_time = total_timespan.TotalSeconds + "";
coloring_timespan = stopwatch.Elapsed;
string coloring_time = (coloring_timespan.TotalSeconds - bootstrap_timespan.TotalSeconds) + "";
// Enable screen updating when we're done
Globals.ThisAddIn.Application.ScreenUpdating = true;
textBox1.AppendText("Done." + Environment.NewLine);
textBox1.AppendText("Total time:" + total_time +
Environment.NewLine + "Tree construction: " + tree_building_time +
Environment.NewLine + "Perturbation: " + bootstrap_time +
Environment.NewLine + "Coloring: " + coloring_time + Environment.NewLine + Environment.NewLine);
results += originalWB.Name + "\t" + NBOOTS + "\t" + total_time + "\t" + tree_building_time + "\t" + bootstrap_time +
"\t" + coloring_time + Environment.NewLine;
originalWB.Close(false);
}
System.IO.File.WriteAllText(@folderPath + @"\ExperimentalResults.xls", results);
} //END runExperiments_Click
private void runSingle_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.ShowDialog();
if (openFileDialog.FileName == "")
{
System.Windows.Forms.MessageBox.Show("No file selected.");
}
else if (!openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf(".")).Contains(".xls"))
{
System.Windows.Forms.MessageBox.Show("Please select .xls or .xlsx file.");
}
else
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
TimeSpan tree_building_timespan;
TimeSpan bootstrap_timespan;
TimeSpan coloring_timespan;
TimeSpan total_timespan;
textBox1.AppendText(Environment.NewLine + "Opening Excel file: " + openFileDialog.FileName + Environment.NewLine);
// Get current app
Excel.Application app = Globals.ThisAddIn.Application;
Excel.Workbook originalWB = app.Workbooks.Open(openFileDialog.FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
textBox1.AppendText(Environment.NewLine + "Running bootstrap analysis." + Environment.NewLine);
//Disable screen updating during perturbation and analysis to speed things up
Globals.ThisAddIn.Application.ScreenUpdating = false;
// Make a new analysisData object
AnalysisData data = new AnalysisData(app, app.ActiveWorkbook, false);
data.worksheets = app.Worksheets;
// Construct a new tree every time the tool is run
data.Reset();
stopwatch.Start();
// Build dependency graph (modifies data)
ConstructTree.constructTree(data, app.ActiveWorkbook, app);
tree_building_timespan = stopwatch.Elapsed;
string tree_building_time = tree_building_timespan.TotalSeconds + "";
if (data.TerminalInputNodes().Length == 0)
{
System.Windows.Forms.MessageBox.Show("This spreadsheet has no input ranges. Sorry, dude.");
data.pb.Close();
Globals.ThisAddIn.Application.ScreenUpdating = true;
return;
}
// e * bootstrapMultiplier
int bootstrapMultiplier = (int)numericUpDown1.Value;
var NBOOTS = (int)(Math.Ceiling(bootstrapMultiplier * Math.Exp(1.0)));
// Get bootstraps
var scores = Analysis.Bootstrap(NBOOTS, data, app, true);
bootstrap_timespan = stopwatch.Elapsed;
string bootstrap_time = (bootstrap_timespan.TotalSeconds - tree_building_timespan.TotalSeconds) + "";
// Color outputs
Analysis.ColorOutliers(scores);
stopwatch.Stop();
total_timespan = stopwatch.Elapsed;
string total_time = total_timespan.TotalSeconds + "";
coloring_timespan = stopwatch.Elapsed;
string coloring_time = (coloring_timespan.TotalSeconds - bootstrap_timespan.TotalSeconds) + "";
// Enable screen updating when we're done
Globals.ThisAddIn.Application.ScreenUpdating = true;
textBox1.AppendText("Done." + Environment.NewLine);
textBox1.AppendText("Total time:" + total_time +
Environment.NewLine + "Tree construction: " + tree_building_time +
Environment.NewLine + "Perturbation: " + bootstrap_time +
Environment.NewLine + "Coloring: " + coloring_time + Environment.NewLine + Environment.NewLine);
string results = originalWB.Name + "\t" + NBOOTS + "\t" + total_time + "\t" + tree_building_time + "\t" + bootstrap_time +
"\t" + coloring_time + Environment.NewLine;
originalWB.Close(false);
try
{
string originalFileText = System.IO.File.ReadAllText(openFileDialog.FileName.Substring(0,openFileDialog.FileName.LastIndexOf(@"\")+1) + @"\ExperimentalResults.xls");
results = originalFileText + results;
}
catch
{
results = "Workbook name" + "\tBootstraps" + "\tTotal Time" + "\tTree Building Time" + "\tBootstrap Time" +
"\tColoring Time" + Environment.NewLine + results;
}
System.IO.File.WriteAllText(openFileDialog.FileName.Substring(0, openFileDialog.FileName.LastIndexOf(@"\")) + @"\ExperimentalResults.xls", results);
textBox1.AppendText("Wrote file: " + openFileDialog.FileName.Substring(0, openFileDialog.FileName.LastIndexOf(@"\")) + @"\ExperimentalResults.xls");
}
}
}
}