def _encode_ratio(inval, outval):
'''
Calculate the log ratio between inbound and outbound traffic.
Positive when outval > inval, and negative when inval > outval.
Returns a non-infinite floating point value:
- zero when inval and outval are zero,
- a large negative number (< -100) when outval is zero, and
- a large positive number (> 100) when inval is zero, and
- log(base 2)(outval/inval) otherwise.
'''
inval = float(inval)
outval = float(outval)
if inval == 0.0 and outval == 0.0:
return 0.0
elif inval == 0.0:
return sys.float_info.max_exp
elif outval == 0.0:
return sys.float_info.min_exp
else:
return math.log(outval/inval, 2)
评论列表
文章目录