mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-25 17:59:25 +01:00
test-runner: move BarChart into utils.py
This commit is contained in:
parent
bc9dfee7cd
commit
f199e3f40d
@ -22,7 +22,7 @@ import dbus.mainloop.glib
|
|||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
from runner import Runner
|
from runner import Runner
|
||||||
from utils import Process, Namespace
|
from utils import Process, Namespace, BarChart
|
||||||
|
|
||||||
config = None
|
config = None
|
||||||
intf_id = 0
|
intf_id = 0
|
||||||
@ -291,47 +291,6 @@ class Hostapd:
|
|||||||
for f in glob("/tmp/eap_sim_db*"):
|
for f in glob("/tmp/eap_sim_db*"):
|
||||||
os.remove(f)
|
os.remove(f)
|
||||||
|
|
||||||
class BarChart():
|
|
||||||
def __init__(self, height=10, max_width=80):
|
|
||||||
self._height = height
|
|
||||||
self._max_width = max_width
|
|
||||||
self._values = []
|
|
||||||
self._max_value = 0
|
|
||||||
self._min_value = 0
|
|
||||||
|
|
||||||
def add_value(self, value):
|
|
||||||
if len(self._values) == 0:
|
|
||||||
self._max_value = int(1.01 * value)
|
|
||||||
self._min_value = int(0.99 * value)
|
|
||||||
elif value > self._max_value:
|
|
||||||
self._max_value = int(1.01 * value)
|
|
||||||
elif value < self._min_value:
|
|
||||||
self._min_value = int(0.99 * value)
|
|
||||||
|
|
||||||
self._values.append(value)
|
|
||||||
|
|
||||||
def _value_to_stars(self, value):
|
|
||||||
# Need to scale value (range of min_value -> max_value) to
|
|
||||||
# a range of 0 -> height
|
|
||||||
#
|
|
||||||
# Scaled = ((value - min_value) / ( max_value - min_value)) * (Height - 0) + 0
|
|
||||||
|
|
||||||
return int(((value - self._min_value) /
|
|
||||||
(self._max_value - self._min_value)) * self._height)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
# Need to map value from range 0 - self._height
|
|
||||||
ret = ''
|
|
||||||
|
|
||||||
for i, value in enumerate(self._values):
|
|
||||||
stars = self._value_to_stars(value)
|
|
||||||
ret += '[%3u] ' % i + '%-10s' % ('*' * stars) + '\t\t\t%d\n' % value
|
|
||||||
|
|
||||||
ret += '\n'
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
class TestContext(Namespace):
|
class TestContext(Namespace):
|
||||||
'''
|
'''
|
||||||
Contains all information for a given set of tests being run
|
Contains all information for a given set of tests being run
|
||||||
|
@ -453,3 +453,43 @@ class Namespace:
|
|||||||
ret += '===================================================\n\n'
|
ret += '===================================================\n\n'
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
class BarChart():
|
||||||
|
def __init__(self, height=10, max_width=80):
|
||||||
|
self._height = height
|
||||||
|
self._max_width = max_width
|
||||||
|
self._values = []
|
||||||
|
self._max_value = 0
|
||||||
|
self._min_value = 0
|
||||||
|
|
||||||
|
def add_value(self, value):
|
||||||
|
if len(self._values) == 0:
|
||||||
|
self._max_value = int(1.01 * value)
|
||||||
|
self._min_value = int(0.99 * value)
|
||||||
|
elif value > self._max_value:
|
||||||
|
self._max_value = int(1.01 * value)
|
||||||
|
elif value < self._min_value:
|
||||||
|
self._min_value = int(0.99 * value)
|
||||||
|
|
||||||
|
self._values.append(value)
|
||||||
|
|
||||||
|
def _value_to_stars(self, value):
|
||||||
|
# Need to scale value (range of min_value -> max_value) to
|
||||||
|
# a range of 0 -> height
|
||||||
|
#
|
||||||
|
# Scaled = ((value - min_value) / ( max_value - min_value)) * (Height - 0) + 0
|
||||||
|
|
||||||
|
return int(((value - self._min_value) /
|
||||||
|
(self._max_value - self._min_value)) * self._height)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
# Need to map value from range 0 - self._height
|
||||||
|
ret = ''
|
||||||
|
|
||||||
|
for i, value in enumerate(self._values):
|
||||||
|
stars = self._value_to_stars(value)
|
||||||
|
ret += '[%3u] ' % i + '%-10s' % ('*' * stars) + '\t\t\t%d\n' % value
|
||||||
|
|
||||||
|
ret += '\n'
|
||||||
|
|
||||||
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user