-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog-rank.py
162 lines (128 loc) · 4.96 KB
/
log-rank.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# This source code is a part of Project Violet.
# Copyright (C) 2021. violet-team. Licensed under the Apache-2.0 License.
import sys
import os
import math
from os import listdir
import os.path
from os.path import isfile, join
import re
import json
contains = {}
similar = {}
def process(filename):
f = open(filename, 'r', encoding="UTF-8")
lines = f.readlines()
f.close()
for line in lines:
if line.startswith('('):
data = line.split(')', 1)[1].strip().rsplit('|', 1)[0].strip()
sc = data.split(':')[0].strip()
msg = data.split(':',1)[1].strip()
if sc == 'contains':
if not msg in contains:
contains[msg] = 0
contains[msg] += 1
elif sc == 'similar':
if not msg in similar:
similar[msg] = 0
similar[msg] += 1
else:
print('error')
elif line.split(':')[0] == 'contains' or line.split(':')[0] == 'similar':
sc = line.split(':')[0].strip()
msg = line.split(':',1)[1].strip()
if sc == 'contains':
if not msg in contains:
contains[msg] = 0
contains[msg] += 1
elif sc == 'similar':
if not msg in similar:
similar[msg] = 0
similar[msg] += 1
else:
print('error')
process('nohup-legacy9.out')
process('nohup-legacy8.out')
process('nohup-legacy7.out')
process('nohup-legacy6.out')
process('nohup-legacy5.out')
process('nohup-legacy4.out')
process('nohup-legacy3.out')
process('nohup-legacy.out')
process('nohup.out')
process('a.log')
def apply_blacklist():
f = open('blacklist.txt', 'r', encoding="UTF-8")
lines = f.readlines()
f.close()
for line in lines:
# del contains[line.strip()]
# del similar[line.strip()]
contains.pop(line.strip(), None)
similar.pop(line.strip(), None)
apply_blacklist()
def save(name, what):
what = dict(sorted(what.items(), key=lambda item: -item[1]))
with open(name, 'w', encoding='UTF-8') as file:
file.write(json.dumps(what, ensure_ascii=False, indent=4))
# print(json.dumps(what, ensure_ascii=False, indent=4))
save('contains.json', contains)
save('similar.json', similar)
def save_sorted_with_alphabet():
with open('SORT.md', 'w', encoding='UTF-8') as file:
c = dict(sorted(contains.items(), key=lambda item: item[0]))
s = dict(sorted(similar.items(), key=lambda item: item[0]))
file.write('# Log Rank (Sort)\n[Contains](#Contains)\n[Similar](#Similar)\n## Contains\n```\n')
file.write(json.dumps(c, ensure_ascii=False, indent=4))
file.write('\n```\n## Similar\n```\n')
file.write(json.dumps(s, ensure_ascii=False, indent=4))
file.write('\n```')
save_sorted_with_alphabet()
def create_readme():
with open('README.md', 'w', encoding='UTF-8') as file:
c = dict(sorted(contains.items(), key=lambda item: -item[1]))
s = dict(sorted(similar.items(), key=lambda item: -item[1]))
file.write('# Log Rank\n[Contains](#Contains)\n[Similar](#Similar)\n## Contains\n```\n')
file.write(json.dumps(c, ensure_ascii=False, indent=4))
file.write('\n```\n## Similar\n```\n')
file.write(json.dumps(s, ensure_ascii=False, indent=4))
file.write('\n```')
# create_readme()
def save_sorted_with_alphabet_combine():
with open('SORT-COMBINE.md', 'w', encoding='UTF-8') as file:
combine = contains.copy()
for k,v in similar.items():
if k in combine:
combine[k] += v
else:
combine[k] = v
c = dict(sorted(combine.items(), key=lambda item: item[0]))
file.write('# Log Rank (Sort-Combine)\n## Combine\n```\n')
file.write(json.dumps(c, ensure_ascii=False, indent=4))
file.write('\n```')
def save_sorted_with_alphabet_combine_json():
with open('SORT-COMBINE.json', 'w', encoding='UTF-8') as file:
combine = contains.copy()
for k,v in similar.items():
if k in combine:
combine[k] += v
else:
combine[k] = v
c = dict(sorted(combine.items(), key=lambda item: item[0]))
file.write(json.dumps(c, ensure_ascii=False))
save_sorted_with_alphabet_combine()
save_sorted_with_alphabet_combine_json()
def save_sorted_with_length_combine():
with open('SORT-LEN-COMBINE.md', 'w', encoding='UTF-8') as file:
combine = contains.copy()
for k,v in similar.items():
if k in combine:
combine[k] += v
else:
combine[k] = v
c = dict(sorted(combine.items(), key=lambda item: -len(item[0])))
file.write('# Log Rank (Sort Length)\n## Combine\n```\n')
file.write(json.dumps(c, ensure_ascii=False, indent=4))
file.write('\n```')
save_sorted_with_length_combine()