-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocessstatsruns.py
executable file
·49 lines (46 loc) · 1.81 KB
/
processstatsruns.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
#!/usr/bin/python3
import sys, re
lineRe = re.compile(r'^\((\d), \((\d), (\d), (\d)\)\): \[(.*)\]\s*$')
def main(fileName):
f = open(fileName, 'r')
print('<situations>')
for line in f.readlines():
lineMatch = lineRe.match(line)
if lineMatch:
# Starting at one to make compliant with other file
baseSum = 1
if (lineMatch.group(2) == '1'):
baseSum = baseSum + 1
if (lineMatch.group(3) == '1'):
baseSum = baseSum + 2
if (lineMatch.group(4) == '1'):
baseSum = baseSum + 4
stringToPrint = "<situation outs=\"%s\" runners=\"%d\">" % (lineMatch.group(1), baseSum)
runsList = lineMatch.group(5).split(', ')
runsList = [int(x) for x in runsList]
totalRuns = sum(runsList)
stringToPrint += "<total>%d</total>" % totalRuns
curRuns = 0
for numInstances in runsList:
stringToPrint += '<count runs="%d">%d</count>' % (curRuns, numInstances)
curRuns = curRuns + 1
stringToPrint += '</situation>'
#stringToPrint = stringToPrint + "%s,%s,%s,%s,%s,%s" % (lineMatch.group(1), lineMatch.group(3), baseSum, lineMatch.group(7), lineMatch.group(9), lineMatch.group(8))
print(stringToPrint)
else:
print("ERROR - couldn't parse line %s" %line)
print('</situations>')
f.close()
def cmpWithCommaFirst(x, y):
if (cmp(x[:3], y[:3]) != 0):
return cmp(x[:3], y[:3])
xIsComma = (x[5] == ',')
yIsComma = (y[5] == ',')
if (cmp(x,y) == -1 and yIsComma and not xIsComma):
return 1
elif (cmp(x,y) == 1 and xIsComma and not yIsComma):
return -1
else:
return cmp(x,y)
if (__name__ == '__main__'):
main(sys.argv[1])