-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstructs.py
More file actions
67 lines (54 loc) · 1.67 KB
/
Copy pathstructs.py
File metadata and controls
67 lines (54 loc) · 1.67 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
class IPTracking:
def __init__(self, ip, seq, ts):
self.timestamp = ts
self.ip = ip
self.seq = seq
self.timeout = False
self.ping = 0.0
self.error_code = 0
self.error_msg = ""
def set_delay(self, delay):
self.ping = delay
def set_error(self, error_code, error_msg):
self.error_code = error_code
self.error_msg = error_msg
def set_timeout(self):
self.timeout = True
class SummaryData:
def __init__(self):
self.curr_delay = 0.0
self.total_delay = 0.0
self.amount_updates = 0
self.total_errors = 0
self.total_timeouts = 0
self.highest_delay = 0
def update(self, iptracking):
if isinstance(iptracking, IPTracking):
if iptracking.error_code > 0:
self.total_errors += 1
elif iptracking.timeout:
self.total_timeouts += 1
else:
self.curr_delay = iptracking.ping
self.total_delay += iptracking.ping
self.amount_updates += 1
if self.highest_delay < self.curr_delay:
self.highest_delay = self.curr_delay
def calc_avg_delay(self):
if self.amount_updates > 0:
return round(self.total_delay / self.amount_updates, 4)
else:
return 0.0
class MessageQueue:
def __init__(self):
self.queue = []
def push(self, message):
self.queue.append(message)
def pop(self):
ret = None
if self.len > 0:
ret = self.queue.pop(0)
return ret
@property
def len(self):
return len(self.queue)