-
Notifications
You must be signed in to change notification settings - Fork 5
/
stats.py
75 lines (65 loc) · 2.29 KB
/
stats.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
import os
import re
import argparse
import numpy as np
def args():
parser = argparse.ArgumentParser(description='Check runs status')
parser.add_argument('--pattern', type=str)
parser.add_argument('--show', action='store_true')
parser.add_argument('--num', type=int, default=10)
parser.add_argument('--runs', action='store_true')
return parser.parse_args()
def print_logs(outputs, opt):
sorted_index = np.argsort(outputs['number'])
if opt.show:
for index in sorted_index:
if opt.runs:
print('===========', outputs['number'][index],
outputs['date'][index], outputs['run_names'][index])
continue
else:
print('===========', outputs['number'][index],
outputs['date'][index])
if len(outputs['logs'][index]) > 0:
print(outputs['logs'][index])
else:
print('No log exist')
else:
for index in sorted_index:
print(outputs['number'][index], outputs['date'][index])
if __name__ == '__main__':
opt = args()
logdir = 'runs'
pattern = opt.pattern
num = opt.num
run_names = []
for root, subdirs, files in os.walk(logdir, followlinks=True):
if re.match(pattern, root):
run_names += [root]
outputs = {
'number': [],
'date': [],
'logs': [],
'run_names': []
}
for run_name in run_names:
number = run_name.split('/')[-1].split('_')[1]
outputs['number'].append(number)
f = open(run_name + '/log.txt', 'r')
lines = f.read().splitlines()
lines.reverse()
f.close()
for last_line in lines:
if len(last_line.split(' ')) > 1 and last_line.split(' ')[0].startswith('2020'):
last_line = last_line.split(' ')
break
if len(last_line) > 1:
outputs['date'].append(' '.join([last_line[0], last_line[1]]))
else:
outputs['date'].append('No Date')
f = open(run_name + '/log', 'r')
lines = f.read().splitlines()
outputs['logs'].append('\n'.join(lines[-num:]))
outputs['run_names'].append(run_name)
f.close()
print_logs(outputs, opt)