-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
29 lines (23 loc) · 839 Bytes
/
utils.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
import pandas as pd
def center_string(text: str, length: int) -> str:
if len(str(text)) >= length:
return str(text)[:length - 3] + "..."
else:
return str(text).center(length)
def generate_table_line(line: pd.Series, cols_dim: dict) -> str:
values = [line["number"], line["time"], line["mac_src"], line["mac_dst"], line["protocol"], line["length"]]
length = list(cols_dim.values())
line_str = "|".join(center_string(values[i], length[i]) for i in range(len(values)))
return line_str
def select_line_color(line: pd.Series) -> int:
protocol = line["protocol"]
match protocol:
case "TCP":
proto_color = 3
case "UDP":
proto_color = 4
case "ICMP":
proto_color = 5
case _:
proto_color = 0
return proto_color