-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
76 lines (65 loc) · 2.1 KB
/
Copy pathanalysis.py
File metadata and controls
76 lines (65 loc) · 2.1 KB
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
'''
数据分析
'''
from calendar import c
from cmath import log
import utils
# 分析训练集测试集事件出现的次数
def analysis_event_count(dataset):
qa_train = utils.read_json('logs/{}/qa_train.json'.format(dataset))
qa_test = utils.read_json('logs/{}/qa_test.json'.format(dataset))
train_counter = {}
test_counter = {}
for qa in qa_train:
event = qa['Events'][0]
if event in train_counter.keys():
train_counter[event] += 1
else:
train_counter[event] = 1
for qa in qa_test:
event = qa['Events'][0]
if event in test_counter.keys():
test_counter[event] += 1
else:
test_counter[event] = 1
print('训练集事件出现的次数:')
print(train_counter)
print('测试集事件出现的次数:')
print(test_counter)
print('测试集中的事件在训练集中没有出现:')
for event in test_counter.keys():
if event not in train_counter.keys():
print(event)
# 问题类型的分析
def count_word4question(dataset):
qa_data = utils.read_json('logs/{}/qa.json'.format(dataset))
counter = {}
total = 0
for qa in qa_data:
question = qa['Question']
q_token = question.replace('?', '').split()[0]
if q_token not in counter.keys():
counter[q_token] = 1
else:
counter[q_token] += 1
total += 1
print(counter)
for k, v in counter.items():
print(k, v/total * 100)
# 分析回答问题所需日志的数量
def analysis_log_count(dataset):
qa_data = utils.read_json('logs/{}/qa.json'.format(dataset))
total = 0
log_count = 0
for qa in qa_data:
ans_type = qa['Answer_type']
if not ans_type == 'Span':
log_count += len(qa['Logs'])
total += 1
print('{}回答问题(不包含span类型)平均所需日志的数量:'.format(dataset))
print(log_count/total)
if __name__ == "__main__":
dataset = 'OpenSSH'
# analysis_event_count(dataset)
# count_word4question(dataset)
analysis_log_count(dataset)