-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSDN_utils.py
34 lines (28 loc) · 926 Bytes
/
SDN_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
30
31
32
33
34
#!/usr/bin/python
"""
Documentation: Pending . . .
"""
# Global Imports
import os, socket, struct;
# Make Directories Save (Create if not exists)
def makedirs_s(s):
if os.path.exists(s) is False:
os.makedirs(s);
# IP-INT conversion methods
IP2INT = lambda ipstr: struct.unpack('!I', socket.inet_aton(ipstr))[0]; # IP Address to Integer
INT2IP = lambda n: socket.inet_ntoa(struct.pack('!I', n)); # Integer to IP Address
# Find Mean
def get_mean(_list):
if not _list:
return 0.0;
_list = map(lambda x: x if x >= 0 else 0, _list); # Force -ve Values to Zero (Error Codes)
return sum(_list) / len(_list);
# Find Median
def get_median(_list):
if not _list:
return 0.0;
_list = sorted(map(lambda x: x if x >= 0 else 0, _list)); # Force -ve Values to Zero (Error Codes) and Sort the list
_len = len(_list);
if (_len % 2) == 1:
return _list[_len / 2];
return (_list[(_len / 2) - 1] + _list[_len / 2]) / 2;