-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathresult_transform.py
More file actions
55 lines (42 loc) · 1.48 KB
/
result_transform.py
File metadata and controls
55 lines (42 loc) · 1.48 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
import os
from openpyxl import load_workbook
import openpyxl
import argparse
def parce_folder():
# Parse input params
parser = argparse.ArgumentParser()
parser.add_argument('--folder', type=str, help="Folder (path to results)")
args, unknown = parser.parse_known_args()
folder = getattr(args, 'folder')
return folder
### Start
print('Use example: result_transform.py --folder="D:\Dropbox\Exchange\! ML new test results\btc"')
folder = parce_folder()
#cwd = os.getcwd()
column = 1
# Create the file
filepath = "{}/results_processed.xlsx".format(folder)
wb = openpyxl.Workbook()
wb.save(filepath)
wb = load_workbook(filepath)
ws = wb.get_active_sheet()
for filename in os.listdir(folder):
if filename.endswith(".log") and filename.find('summary') > 0:
print (filename)
with open('%s\\%s' % (folder, filename), 'r+') as file:
row = 1
line_original = file.readline()
ws.cell(row = row, column = column).value = line_original
row += 1
while line_original !="":
line_original = file.readline()
# Write converted where possible
line = line_original.replace('\n', '').replace('\r', '')
try:
line = float(line)
except:
pass
line = ws.cell(row = row, column = column).value = line
row += 1
column += 1
wb.save(filepath)