-
Notifications
You must be signed in to change notification settings - Fork 3
/
main2.js
273 lines (218 loc) · 8.26 KB
/
main2.js
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// const { ipcMain } = require('electron');
// const { spawn } = require('child_process');
// const fs = require('fs');
// const path = require('path');
// const os = require('os');
// ipcMain.on('upload-file', (event, fileName, fileContent) => {
// const tempFilePath = path.join(os.tmpdir(), fileName);
// fs.writeFileSync(tempFilePath, fileContent, 'utf8');
// const pythonProcess = spawn('python', ['path_to_your_script.py', tempFilePath]);
// pythonProcess.stdout.on('data', (data) => {
// console.log(`Output from Python: ${data}`);
// });
// pythonProcess.stderr.on('data', (data) => {
// console.error(`Error from Python: ${data}`);
// });
// pythonProcess.on('exit', () => {
// fs.unlinkSync(tempFilePath); // Delete the temporary file after processing
// });
// });
// ipcMain.on('send-file', (event, csvFilePath) => {
// const pythonProcess = spawn('python', ['flask_ml/app.py', csvFilePath]);
// pythonProcess.stdout.on('data', (data) => {
// console.log(`Output from Python: ${data}`);
// });
// pythonProcess.stderr.on('data', (data) => {
// console.error(`Error from Python: ${data}`);
// });
// });
// ipcMain.on('send-data', (event, jsonString) => {
// const pythonProcess = spawn('python', ['flask_ml/app.py', jsonString]);
// let pythonOutput = '';
// pythonProcess.stdout.on('data', (data) => {
// pythonOutput += data.toString();
// });
// pythonProcess.stderr.on('data', (data) => {
// console.error(`Error from Python: ${data}`);
// });
// pythonProcess.on('close', (code) => {
// if (code === 0) {
// // Send the parsed JSON back to the renderer process
// event.reply('python-result', JSON.parse(pythonOutput));
// } else {
// console.error(`Python process exited with code ${code}`);
// }
// });
// });
// const { app, BrowserWindow, ipcMain } = require('electron');
// const path = require('path');
// const { exec } = require('child_process');
// let mainWindow;
// function createWindow() {
// mainWindow = new BrowserWindow({
// width: 1600,
// height: 1000,
// webPreferences: {
// preload: path.join(__dirname, 'preload.js'),
// contextIsolation: true,
// enableRemoteModule: false,
// nodeIntegration: true,
// }
// });
// mainWindow.on('closed', function () {
// mainWindow = null;
// });
// mainWindow.loadFile('Buildathon/progress1.html');
// }
// app.whenReady().then(() => {
// createWindow();
// app.on('activate', () => {
// if (BrowserWindow.getAllWindows().length === 0) {
// createWindow();
// }
// });
// });
// app.on('window-all-closed', () => {
// if (process.platform !== 'darwin') {
// app.quit();
// }
// });
// ipcMain.on('ingest-data', (event, data) => {
// const { path, filename } = data;
// // Add logic to handle file ingestion if needed
// event.sender.send('confirmation-message', 'Data ingested successfully.');
// });
// ipcMain.on('show-data-dimensions', (event, data) => {
// const script = 'flask_ml/app.py'; // Adjust the path to your Python script
// const dataFilePath = data; // Adjust the path to your data file
// exec(`python ${script} show-data-dimensions ${dataFilePath}`, (error, stdout, stderr) => {
// if (error) {
// console.error(`exec error: ${error}`);
// return;
// }
// const dimensions = JSON.parse(stdout);
// event.sender.send('data-dimensions', dimensions);
// });
// });
// ipcMain.on('remove-features', (event, data) => {
// const { removeFeatures } = data;
// const script = 'flask_ml/app.py'; // Adjust the path to your Python script
// exec(`python ${script} remove-features ${removeFeatures}`, (error, stdout, stderr) => {
// if (error) {
// console.error(`exec error: ${error}`);
// return;
// }
// event.sender.send('confirmation-message', 'Features removed successfully.');
// });
// });
// ipcMain.on('convert-numbers', (event, data) => {
// const { convertNumbers } = data;
// const script = 'flask_ml/app.py'; // Adjust the path to your Python script
// exec(`python ${script} convert-numbers ${convertNumbers}`, (error, stdout, stderr) => {
// if (error) {
// console.error(`exec error: ${error}`);
// return;
// }
// event.sender.send('confirmation-message', 'Features converted successfully.');
// });
// });
// ipcMain.on('train-test-split', (event, data) => {
// const { trainData, testData } = data;
// const script = 'flask_ml/app.py'; // Adjust the path to your Python script
// exec(`python ${script} train-test-split ${trainData} ${testData}`, (error, stdout, stderr) => {
// if (error) {
// console.error(`exec error: ${error}`);
// return;
// }
// event.sender.send('confirmation-message', 'Train-test split completed.');
// });
// });
// ipcMain.on('train-random-forest', (event, data) => {
// const { criterion, maxDepth, nEstimators } = data;
// const script = 'flask_ml/app.py'; // Adjust the path to your Python script
// exec(`python ${script} train-random-forest ${criterion} ${maxDepth} ${nEstimators}`, (error, stdout, stderr) => {
// if (error) {
// console.error(`exec error: ${error}`);
// return;
// }
// event.sender.send('confirmation-message', 'Random Forest trained successfully.');
// });
// });
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const { exec } = require('child_process');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1600,
height: 1000,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: false,
enableRemoteModule: false,
nodeIntegration: true,
}
});
mainWindow.on('closed', function () {
mainWindow = null;
});
mainWindow.loadFile('Buildathon/progress1.html');
}
app.whenReady().then(() => {
createWindow();
ipcMain.on('file-upload', (event, { filename, content }) => {
const buffer = Buffer.from(new Uint8Array(content));
fs.writeFile(path.join(__dirname, 'uploads', filename), buffer, (err) => {
if (err) {
console.error('Error saving file:', err);
} else {
console.log('File saved successfully');
}
});
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
ipcMain.on('ingest-data', (event, data) => {
const { path, filename } = data;
event.sender.send('confirmation-message', `File ${filename} from path ${path} ingested successfully.`);
});
ipcMain.on('show-data-dimensions', (event) => {
const script = 'flask_ml/app.py';
exec(`python ${script} show-data-dimensions`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
const dimensions = JSON.parse(stdout);
event.sender.send('data-dimensions', dimensions);
});
});
ipcMain.on('remove-features', (event, data) => {
const { removeFeatures } = data;
event.sender.send('confirmation-message', `Features ${removeFeatures} removed successfully.`);
});
ipcMain.on('convert-numbers', (event, data) => {
const { convertNumbers } = data;
event.sender.send('confirmation-message', `Features ${convertNumbers} converted to numbers successfully.`);
});
ipcMain.on('train-test-split', (event, data) => {
const { trainData, testData } = data;
event.sender.send('confirmation-message', `Train test split: ${trainData}% training data, ${testData}% testing data.`);
});
ipcMain.on('train-random-forest', (event, data) => {
const { criterion, maxDepth, nEstimators } = data;
event.sender.send('confirmation-message', `Random Forest trained with criterion ${criterion}, max depth ${maxDepth}, and ${nEstimators} estimators.`);
});
ipcMain.on('export-model', (event, data) => {
const { modelType, path } = data;
event.sender.send('confirmation-message', `${modelType} model exported to ${path} successfully.`);
});