summaryrefslogtreecommitdiff
path: root/lib/utils.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-05-08 16:30:47 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-05-08 16:30:47 +0200
commit62919d668c475a9191ff9cc8c4016a3baee1667c (patch)
treed9f6926dc76b5926ae523beb494356e1b6a045f9 /lib/utils.py
parentc75a3e2034aa73277c5c499423941259cf6fda49 (diff)
add cpu cycles -> cpu energy and packet size -> tx energy for protocolmodeling
Diffstat (limited to 'lib/utils.py')
-rw-r--r--lib/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py
index 64f1780..02c1d26 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -31,6 +31,21 @@ def float_or_nan(n):
except ValueError:
return np.nan
+def soft_cast_int(n):
+ """
+ Convert to int, if possible.
+
+ If it is empty, returns None.
+ If it is not numeric, it is left unchanged.
+ """
+ if n == None or n == '':
+ return None
+ try:
+ return int(n)
+ except ValueError:
+ return n
+
+
def flatten(somelist):
"""
Flatten a list.
@@ -39,6 +54,13 @@ def flatten(somelist):
"""
return [item for sublist in somelist for item in sublist]
+def parse_conf_str(conf_str):
+ conf_dict = dict()
+ for option in conf_str.split(','):
+ key, value = option.split(':')
+ conf_dict[key] = soft_cast_int(value)
+ return conf_dict
+
def param_slice_eq(a, b, index):
"""
Check if by_param keys a and b are identical, ignoring the parameter at index.