-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocessstats.py
executable file
·51 lines (48 loc) · 1.62 KB
/
processstats.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
#!/usr/bin/python3
import sys, re, functools
lineRe = re.compile(r'^\((\d+), (\d+), (\d+), \((\d+), (\d+), (\d+)\), (-?\d+)\): \((\d+), (\d+)\)')
def main(fileName):
f = open(fileName, 'r')
linesToWrite = []
for line in f.readlines():
lineMatch = lineRe.match(line)
if lineMatch:
if (lineMatch.group(2) == '1'):
stringToPrint = '"H",'
else:
stringToPrint = '"V",'
# Starting at one to make compliant with other file
baseSum = 1
if (lineMatch.group(4) == '1'):
baseSum = baseSum + 1
if (lineMatch.group(5) == '1'):
baseSum = baseSum + 2
if (lineMatch.group(6) == '1'):
baseSum = baseSum + 4
stringToPrint = stringToPrint + "%s,%s,%s,%s,%s,%s" % (lineMatch.group(1), lineMatch.group(3), baseSum, lineMatch.group(7), lineMatch.group(9), lineMatch.group(8))
linesToWrite.append(stringToPrint)
else:
print("ERROR - couldn't parse line %s" %line)
linesToWrite.sort(key=functools.cmp_to_key(cmpWithCommaFirst))
for line in linesToWrite:
print(line)
f.close()
def cmpWithCommaFirst(x, y):
if x[:3] < y[:3]:
return -1
if x[:3] > y[:3]:
return 1
xIsComma = (x[5] == ',')
yIsComma = (y[5] == ',')
if (x < y and yIsComma and not xIsComma):
return 1
elif (x > y and xIsComma and not yIsComma):
return -1
else:
if x < y:
return -1
if x > y:
return 1
return 0
if (__name__ == '__main__'):
main(sys.argv[1])