From ce129cf1ede82971588df5e41ac2231f84a3e7b6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 6 Mar 2014 14:08:51 +0100 Subject: add KB/s to network speed in moderate example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/moderate | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'examples/moderate') diff --git a/examples/moderate b/examples/moderate index 1ab25e6..f424aa0 100644 --- a/examples/moderate +++ b/examples/moderate @@ -121,8 +121,17 @@ def network(): value = 0 value /= 128 * net_tdiff return colourise(value) - net = [(dev, kbps(dev, 'rx'), kbps(dev, 'tx')) for dev in net_] - net = ['%s: %skbps↓ %skbps↑' % (dev, down, up) for dev, down, up in net] + def KBps(device, direction): + direction += '_bytes' + value = net_[device][direction] + if device in net_last: + value -= net_last[device][direction] + else: + value = 0 + value /= 1024 * net_tdiff + return value + net = [(dev, kbps(dev, 'rx'), KBps(dev, 'rx'), kbps(dev, 'tx'), KBps(dev, 'tx')) for dev in net_] + net = ['%s: %skbps(%.0fKB/s)↓ %skbps(%.0fKB/s)↑' % x for x in net] net = '%s' % ' '.join(net) net_last = net_ return net -- cgit v1.2.3-70-g09d2