-
Notifications
You must be signed in to change notification settings - Fork 31
/
genspreadsheet.py
88 lines (79 loc) · 2.63 KB
/
genspreadsheet.py
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
#!/usr/bin/python3
import xlsxwriter
from datetime import datetime
import sys
import re
if len(sys.argv)<2:
print("Usage: genspreadsheet.py <results.txt>\n")
sys.exit(0)
regexre = re.compile('Regex:\s*(.*)')
resultre = re.compile('\[\s*(\S+)\]\s*time:\s*([\d\.]+).*matches:\s*(\d+)')
infilename = sys.argv[1]
current_regex = None
results = {}
stats = None
scanners = set()
with open( infilename, "r" ) as filein:
headers = filein.readline().split(';')
headmap = {}
for index,name in enumerate(headers):
match = re.match('(.*\s)*\[ms\]',name)
if match:
regexname = match.groups(1)[0].strip()
headmap[regexname] = index
scanners.add(regexname)
for line in filein:
values = line.strip().split(';')
regex = values[0].strip()
results[regex] = dict( [ (name,float(values[index])) for (name,index) in headmap.items() ] )
nowstr = datetime.now().strftime( "%Y%m%d-%H%M%S" )
outfilename = "regex-results-%s.xlsx" % (nowstr,)
# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook(outfilename)
worksheet = workbook.add_worksheet()
worksheet.hide_gridlines(2)
worksheet.set_column(0,0,30)
worksheet.set_column(1,len(scanners),10)
worksheet.set_row(0,20)
# Add a bold format to use to highlight cells.
bold = workbook.add_format({'bold': True})
boldrot = workbook.add_format({'bold': True})
boldrot.set_rotation(0)
highfmt = workbook.add_format({'bold': True})
highfmt.set_bg_color( 'orange' )
highfmt.set_font_color( 'white' )
lowfmt = workbook.add_format({'bold': True})
lowfmt.set_bg_color( 'blue' )
lowfmt.set_font_color( 'white' )
warnfmt = workbook.add_format({'bold':False})
warnfmt.set_bg_color( 'yellow' )
warnfmt.set_font_color( 'black' )
warnfmt.set_align('center')
# Write some data headers.
scanners = list(scanners)
row = 0
for col,scanner in enumerate(scanners):
worksheet.write( row, col+1, scanner, boldrot )
worksheet.write( row, 0, "Regex", bold)
for regex,stats in results.items():
values = sorted([ ms for ms in stats.values() ])
lowcut = values[1]
highcut = values[-2]
row += 1
worksheet.write( row, 0, regex, bold )
for col,scanner in enumerate(scanners):
if scanner not in stats:
worksheet.write( row, col+1, "n/a", warnfmt )
continue
ms = stats[scanner]
if ms>=999999 or ms<=0:
worksheet.write( row, col+1, "n/a", warnfmt )
continue
fmt = None
if ms <= lowcut:
fmt = lowfmt
if ms >= highcut:
fmt = highfmt
worksheet.write( row, col+1, ms, fmt)
workbook.close()
print("Wrote spreadsheet",outfilename)