[tor-commits] [nyx/master] Drop _draw_bandwidth_stats()

atagar at torproject.org atagar at torproject.org
Sun Jun 26 00:48:01 UTC 2016


commit 973da9b991803cac0640982c2b9a31f14d11a103
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun May 29 10:24:29 2016 -0700

    Drop _draw_bandwidth_stats()
    
    I can see why we had this but... it's confusing. On small screen resolutions we
    replaced our y-axis with the average and total bandwidth usage. This only
    applied when rendering bandwidths and it's debatable if this is more valuable
    than the y-axis.
    
    On my netbook (which is just 100 colums wide) we still show the averages (just
    dropping the total) which imho works just fine. We might try something else if
    this makes anyone sad.
---
 nyx/panel/graph.py  | 27 +++------------------------
 test/panel/graph.py | 13 +------------
 2 files changed, 4 insertions(+), 36 deletions(-)

diff --git a/nyx/panel/graph.py b/nyx/panel/graph.py
index c35df13..d3ed768 100644
--- a/nyx/panel/graph.py
+++ b/nyx/panel/graph.py
@@ -51,7 +51,6 @@ PRIMARY_COLOR, SECONDARY_COLOR = GREEN, CYAN
 ACCOUNTING_RATE = 5
 DEFAULT_CONTENT_HEIGHT = 4  # space needed for labeling above and below the graph
 WIDE_LABELING_GRAPH_COL = 50  # minimum graph columns to use wide spacing for x-axis labels
-COLLAPSE_WIDTH = 135  # width at which to move optional stats from the title to x-axis label
 
 
 def conf_handler(key, value):
@@ -228,7 +227,7 @@ class GraphCategory(object):
       header = CONFIG['attr.graph.header.secondary'].get(self.stat_type(), '')
       header_stats = self._secondary_header_stats
 
-    header_stats = join(header_stats, '', width - len(header) - 4)
+    header_stats = join(header_stats, '', width - len(header) - 4).rstrip()
     return '%s (%s):' % (header, header_stats) if header_stats else '%s:' % header
 
   def _y_axis_label(self, value, is_primary):
@@ -560,12 +559,8 @@ class GraphPanel(nyx.panel.Panel):
     self._draw_subgraph(subwindow, attr, attr.stat.primary, 0, PRIMARY_COLOR)
     self._draw_subgraph(subwindow, attr, attr.stat.secondary, attr.subgraph_width, SECONDARY_COLOR)
 
-    if attr.stat.stat_type() == GraphStat.BANDWIDTH:
-      if subwindow.width <= COLLAPSE_WIDTH:
-        _draw_bandwidth_stats(subwindow, DEFAULT_CONTENT_HEIGHT + attr.subgraph_height - 4, attr.stat, attr.subgraph_width)
-
-      if accounting_stats:
-        _draw_accounting_stats(subwindow, DEFAULT_CONTENT_HEIGHT + attr.subgraph_height - 2, accounting_stats)
+    if attr.stat.stat_type() == GraphStat.BANDWIDTH and accounting_stats:
+      _draw_accounting_stats(subwindow, DEFAULT_CONTENT_HEIGHT + attr.subgraph_height - 2, accounting_stats)
 
   def _draw_subgraph(self, subwindow, attr, data, x, color):
     # Concering our subgraph colums, the y-axis label can be at most six
@@ -709,22 +704,6 @@ class GraphPanel(nyx.panel.Panel):
         self.redraw(True)
 
 
-def _draw_bandwidth_stats(subwindow, y, stat, subgraph_width):
-  """
-  Replaces the x-axis labeling with bandwidth stats. This is done on small
-  screens since this information otherwise wouldn't fit.
-  """
-
-  subwindow.addstr(0, y, ' ' * 500)  # clear line
-
-  runtime = time.time() - stat.start_time
-  primary_footer = 'total: %s, avg: %s/sec' % (_size_label(stat.primary.total), _size_label(stat.primary.total / runtime))
-  secondary_footer = 'total: %s, avg: %s/sec' % (_size_label(stat.secondary.total), _size_label(stat.secondary.total / runtime))
-
-  subwindow.addstr(1, y, primary_footer, PRIMARY_COLOR)
-  subwindow.addstr(subgraph_width + 1, y, secondary_footer, SECONDARY_COLOR)
-
-
 def _draw_accounting_stats(subwindow, y, accounting):
   if tor_controller().is_alive():
     hibernate_color = CONFIG['attr.hibernate_color'].get(accounting.status, RED)
diff --git a/test/panel/graph.py b/test/panel/graph.py
index 40c07fb..f2eca4b 100644
--- a/test/panel/graph.py
+++ b/test/panel/graph.py
@@ -11,7 +11,7 @@ import nyx.panel.graph
 import test
 
 from test import require_curses
-from mock import patch, Mock
+from mock import patch
 
 EXPECTED_ACCOUNTING = """
 Accounting (awake)                 Time to reset: 01:02
@@ -21,17 +21,6 @@ Accounting (awake)                 Time to reset: 01:02
 
 class TestGraph(unittest.TestCase):
   @require_curses
-  @patch('time.time', Mock(return_value = 460.0))
-  def test_draw_bandwidth_stats(self):
-    stat = Mock()
-    stat.start_time = 215.0
-    stat.primary.total = 2306867.2
-    stat.secondary.total = 1782579.2
-
-    rendered = test.render(nyx.panel.graph._draw_bandwidth_stats, 0, stat, 40)
-    self.assertEqual(' total: 17.6 Mb, avg: 73.5 Kb/sec        total: 13.5 Mb, avg: 56.8 Kb/sec', rendered.content)
-
-  @require_curses
   @patch('nyx.panel.graph.tor_controller')
   def test_draw_accounting_stats(self, tor_controller_mock):
     tor_controller_mock().is_alive.return_value = True





More information about the tor-commits mailing list