-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview_result.py
67 lines (56 loc) · 2.24 KB
/
view_result.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
from __future__ import division
import re
import sys
class result:
def __init__(self, success, correct, wrong, unanaswered, total, text):
self.success = success
self.correct = correct
self.wrong = wrong
self.unanswered = unanswered
self.total = total
self.text = text
self.score = (3*self.correct - self.wrong)*self.total/100
def print_details(self):
##self.bogus = ''
print self.text
print "Score: ", self.score
print
if __name__ == '__main__':
if len(sys.argv) != 3:
print 'Usage: python view_result.py option filename'
option = sys.argv[1]
result_text = open(sys.argv[2]).read()
results = []
header = re.search(r"(?s)(.*)>>>", result_text).group(1)
##print header
matches = re.findall(r"(.*\n.*?(\d+\.\d+) % success, (\d+\.\d+) % correct, (\d+\.\d+) % wrong, (\d+\.\d+) % unanswered, (\d+) total\.)", result_text)
for match in matches:
success = float(match[1])
##print 'success=', success
correct = float(match[2])
wrong = float(match[3])
unanswered = float(match[4])
total = int(match[5])
text = match[0]
results.append(result(success, correct, wrong, unanswered, total, text))
#print the header
print header
#now print the remaining file sorted according to the option
if option == '--success':
for res in sorted(results, key = lambda r: r.success, reverse=True):
res.print_details()
elif option == '--correct':
for res in sorted(results, key = lambda r: r.correct, reverse=True):
res.print_details()
elif option == '--wrong':
for res in sorted(results, key = lambda r: r.wrong, reverse=True):
res.print_details()
elif option == '--unanswered':
for res in sorted(results, key = lambda r: r.unanswered, reverse=True):
res.print_details()
elif option == '--total':
for res in sorted(results, key = lambda r: r.total, reverse=True):
res.print_details()
elif option == '--score':
for res in sorted(results, key = lambda r: r.score, reverse=True):
res.print_details()