-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_pandas.py
executable file
·152 lines (130 loc) · 4.61 KB
/
parse_pandas.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
#!/usr/bin/env python
import pandas
import re
import sys
import os
import signal
def sigint_handler(signum, frame):
"""CTRL+C handling"""
print('Pressing the CTRL+C!')
exit()
signal.signal(signal.SIGINT, sigint_handler)
mfile = sys.argv[1]
"""Header for CSV."""
header = ['Counter', 'Operation', 'Node', 'Topic', 'Node_Id', 'Count_all', 'Count_last']
"""Reading CSV."""
data_df = pandas.read_csv(mfile, names = header)
"""Dropping unused columns."""
data_df.drop(['Node_Id', 'Counter', 'Count_all', 'Node'], axis=1, inplace=True)
"""Replacing unwanted strings."""
data_df.replace({'NetworkAccessGroup.*smppClient\.': '(NEP) '}, regex=True, inplace=True)
data_df.replace({'ApplicationAccessGroup.*\.': '(AEP) '}, regex=True, inplace=True)
data_df.replace({';$': ''}, regex=True, inplace=True)
"""Indexing phase."""
indexed_by_Topic = data_df.set_index(['Topic'])
indexed_by_Operation = data_df.set_index(['Operation'])
"""Changing data types in columns"""
indexed_by_Operation[['Count_last']] = indexed_by_Operation[['Count_last']].astype('int')
indexed_by_Topic[['Count_last']] = indexed_by_Topic[['Count_last']].astype('int')
def find_metric(metric_type):
print('Search based on metric_type - {}'.format(metric_type))
print('----------------------------------------------------')
indexed_by_Operation.sort_values(['Count_last'], inplace=True)
tailed = indexed_by_Operation.loc[metric_type]
print(tailed.tail(20))
print('\n Press ENTER for more queries')
void = input()
main()
def find_esme(esmename):
print('Search based on ESME - {}'.format(esmename))
print('----------------------------------------------------')
indexed_by_Topic.sort_values(['Operation'], inplace=True)
tailed = indexed_by_Topic.loc[esmename]
print(tailed.tail(20))
print('\n Press ENTER for more queries')
void = input()
main()
def match_topic_pattern():
"""Creates a list of Topics based on regexp given"""
topic_input = input('Provide Regex for Search (SPC for all): ')
df_list = data_df['Topic'].tolist()
u_df_list = set(df_list)
esme_list = []
for x in u_df_list:
for match in re.findall(r'(.*{}.*)'.format(topic_input), x, re.IGNORECASE):
esme_list.append(match)
if len(esme_list) == 0:
print('No Match..')
main()
return esme_list
def match_operation_pattern():
"""Creates a list of Operation based on regexp given"""
operation_input = input('Provide Regex for Search ("_" for all): ')
df_list = data_df['Operation'].tolist()
u_df_list = set(df_list)
metric_list = []
for x in u_df_list:
for match in re.findall(r'(.*{}.*)'.format(operation_input), x, re.IGNORECASE):
metric_list.append(match)
if len(metric_list) == 0:
print('No Match..')
main()
return metric_list
def const_esmemenu(esme_list):
"""Constructing Esme SubMenu"""
count = -1
for f in esme_list:
count += 1
menu = '[{}] {}'.format(count, f)
print(menu)
while True:
ans_ch = int(input("Select option: "))
if ans_ch > count:
print('Wrong selection.')
continue
path = esme_list[ans_ch]
#print("Selection performed: [{}] {} ".format(ans_ch, path))
find_esme(path)
def const_metricmenu(metric_list):
"""Constructing Metric SubMenu"""
count = -1
for f in metric_list:
count += 1
menu = '[{}] {}'.format(count, f)
print(menu)
while True:
ans_ch = int(input("Select option: "))
if ans_ch > count:
print('Wrong selection.')
continue
path = metric_list[ans_ch]
#print("Selection performed: [{}] {} ".format(ans_ch, path))
find_metric(path)
def main():
os.system('clear')
"""MAIN MENU / START"""
print("""
Menu for interaction with Metrics
---------------------------------
[0] Main screen
[1] List all available metrics for AEP or NEP (Usually ESME name)
[2] List all available endpoints which are writing to a specific metric
""")
while True:
ans_b = int(input('Select option (CTRL-C for exit): '))
if ans_b == 1:
print("Selection performed: [{}]\n".format(ans_b))
res = match_topic_pattern()
const_esmemenu(res)
break
elif ans_b == 2:
print("Selection performed: [{}]\n".format(ans_b))
res = match_operation_pattern()
const_metricmenu(res)
break
elif ans_b == 0:
os.execv(__file__, sys.argv)
else:
print('Wrong selection.')
break
main()