[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/master] Dropping graph stats' get_color() method
commit 715a2db2e72f40c513d625ec292c0a39c5cdcde2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Sep 21 12:08:12 2014 -0700
Dropping graph stats' get_color() method
Wonder why we had this. Graph panel had default colors, then the only place we
overwrote it was the bandwidth stats with the exact same thing. Maybe it was to
allow customization once upon a time.
Anyway, dropping the unnecessary method.
---
arm/graphing/bandwidth_stats.py | 13 ++++---------
arm/graphing/graph_panel.py | 36 +++++++++++++-----------------------
2 files changed, 17 insertions(+), 32 deletions(-)
diff --git a/arm/graphing/bandwidth_stats.py b/arm/graphing/bandwidth_stats.py
index 0dffde2..8eb637d 100644
--- a/arm/graphing/bandwidth_stats.py
+++ b/arm/graphing/bandwidth_stats.py
@@ -28,8 +28,6 @@ CONFIG = conf.config_dict('arm', {
'tor.chroot': '',
}, conf_handler)
-DL_COLOR, UL_COLOR = 'green', 'cyan'
-
# width at which panel abandons placing optional stats (avg and total) with
# header in favor of replacing the x-axis label
@@ -185,8 +183,8 @@ class BandwidthStats(graph_panel.GraphStats):
secondary_average = 'avg: %s/sec' % _size_label(self.primary_total / (time.time() - self.start_time) * 1024)
secondary_footer = '%s, %s' % (secondary_average, secondary_total)
- panel.addstr(labeling_line, 1, primary_footer, self.get_color(True))
- panel.addstr(labeling_line, graph_column + 6, secondary_footer, self.get_color(False))
+ panel.addstr(labeling_line, 1, primary_footer, graph_panel.PRIMARY_COLOR)
+ panel.addstr(labeling_line, graph_column + 6, secondary_footer, graph_panel.SECONDARY_COLOR)
# provides accounting stats if enabled
@@ -201,8 +199,8 @@ class BandwidthStats(graph_panel.GraphStats):
panel.addstr(y, 35, 'Time to reset: %s' % str_tools.short_time_label(self._accounting_stats.time_until_reset))
- panel.addstr(y + 1, 2, '%s / %s' % (self._accounting_stats.read_bytes, self._accounting_stats.read_limit), self.get_color(True))
- panel.addstr(y + 1, 37, '%s / %s' % (self._accounting_stats.written_bytes, self._accounting_stats.write_limit), self.get_color(True))
+ panel.addstr(y + 1, 2, '%s / %s' % (self._accounting_stats.read_bytes, self._accounting_stats.read_limit), graph_panel.PRIMARY_COLOR)
+ panel.addstr(y + 1, 37, '%s / %s' % (self._accounting_stats.written_bytes, self._accounting_stats.write_limit), graph_panel.SECONDARY_COLOR)
else:
panel.addstr(labeling_line + 2, 0, 'Accounting:', curses.A_BOLD)
panel.addstr(labeling_line + 2, 12, 'Connection Closed...')
@@ -249,9 +247,6 @@ class BandwidthStats(graph_panel.GraphStats):
else:
return 'Upload:'
- def get_color(self, is_primary):
- return DL_COLOR if is_primary else UL_COLOR
-
def get_content_height(self):
base_height = graph_panel.GraphStats.get_content_height(self)
return base_height + 3 if self._accounting_stats else base_height
diff --git a/arm/graphing/graph_panel.py b/arm/graphing/graph_panel.py
index 818699f..c45bd69 100644
--- a/arm/graphing/graph_panel.py
+++ b/arm/graphing/graph_panel.py
@@ -42,7 +42,7 @@ UPDATE_INTERVALS = [
]
DEFAULT_CONTENT_HEIGHT = 4 # space needed for labeling above and below the graph
-DEFAULT_COLOR_PRIMARY, DEFAULT_COLOR_SECONDARY = 'green', 'cyan'
+PRIMARY_COLOR, SECONDARY_COLOR = 'green', 'cyan'
MIN_GRAPH_HEIGHT = 1
# enums for graph bounds:
@@ -180,13 +180,6 @@ class GraphStats:
def secondary_header(self, width):
return ''
- def get_color(self, is_primary):
- """
- Provides the color to be used for the graph and stats.
- """
-
- return DEFAULT_COLOR_PRIMARY if is_primary else DEFAULT_COLOR_SECONDARY
-
def get_content_height(self):
"""
Provides the height content should take up (not including the graph).
@@ -426,9 +419,6 @@ class GraphPanel(panel.Panel):
param = self.get_attr('stats')[self.current_display]
graph_column = min((width - 10) / 2, param.max_column)
- primary_color = param.get_color(True)
- secondary_color = param.get_color(False)
-
if self.is_title_visible():
self.addstr(0, 0, param.get_title(width), curses.A_STANDOUT)
@@ -437,10 +427,10 @@ class GraphPanel(panel.Panel):
left, right = param.primary_header(width / 2), param.secondary_header(width / 2)
if left:
- self.addstr(1, 0, left, curses.A_BOLD, primary_color)
+ self.addstr(1, 0, left, curses.A_BOLD, PRIMARY_COLOR)
if right:
- self.addstr(1, graph_column + 5, right, curses.A_BOLD, secondary_color)
+ self.addstr(1, graph_column + 5, right, curses.A_BOLD, SECONDARY_COLOR)
# determines max/min value on the graph
@@ -473,11 +463,11 @@ class GraphPanel(panel.Panel):
# displays upper and lower bounds
- self.addstr(2, 0, '%4i' % primary_max_bound, primary_color)
- self.addstr(self.graph_height + 1, 0, '%4i' % primary_min_bound, primary_color)
+ self.addstr(2, 0, '%4i' % primary_max_bound, PRIMARY_COLOR)
+ self.addstr(self.graph_height + 1, 0, '%4i' % primary_min_bound, PRIMARY_COLOR)
- self.addstr(2, graph_column + 5, '%4i' % secondary_max_bound, secondary_color)
- self.addstr(self.graph_height + 1, graph_column + 5, '%4i' % secondary_min_bound, secondary_color)
+ self.addstr(2, graph_column + 5, '%4i' % secondary_max_bound, SECONDARY_COLOR)
+ self.addstr(self.graph_height + 1, graph_column + 5, '%4i' % secondary_min_bound, SECONDARY_COLOR)
# displays intermediate bounds on every other row
@@ -494,13 +484,13 @@ class GraphPanel(panel.Panel):
primary_val = (primary_max_bound - primary_min_bound) * (self.graph_height - row - 1) / (self.graph_height - 1)
if primary_val not in (primary_min_bound, primary_max_bound):
- self.addstr(row + 2, 0, '%4i' % primary_val, primary_color)
+ self.addstr(row + 2, 0, '%4i' % primary_val, PRIMARY_COLOR)
if secondary_min_bound != secondary_max_bound:
secondary_val = (secondary_max_bound - secondary_min_bound) * (self.graph_height - row - 1) / (self.graph_height - 1)
if secondary_val not in (secondary_min_bound, secondary_max_bound):
- self.addstr(row + 2, graph_column + 5, '%4i' % secondary_val, secondary_color)
+ self.addstr(row + 2, graph_column + 5, '%4i' % secondary_val, SECONDARY_COLOR)
# creates bar graph (both primary and secondary)
@@ -509,13 +499,13 @@ class GraphPanel(panel.Panel):
column_height = min(self.graph_height, self.graph_height * column_count / (max(1, primary_max_bound) - primary_min_bound))
for row in range(column_height):
- self.addstr(self.graph_height + 1 - row, col + 5, ' ', curses.A_STANDOUT, primary_color)
+ self.addstr(self.graph_height + 1 - row, col + 5, ' ', curses.A_STANDOUT, PRIMARY_COLOR)
column_count = int(param.secondary_counts[self.update_interval][col + 1]) - secondary_min_bound
column_height = min(self.graph_height, self.graph_height * column_count / (max(1, secondary_max_bound) - secondary_min_bound))
for row in range(column_height):
- self.addstr(self.graph_height + 1 - row, col + graph_column + 10, ' ', curses.A_STANDOUT, secondary_color)
+ self.addstr(self.graph_height + 1 - row, col + graph_column + 10, ' ', curses.A_STANDOUT, SECONDARY_COLOR)
# bottom labeling of x-axis
@@ -542,8 +532,8 @@ class GraphPanel(panel.Panel):
# if constrained on space then strips labeling since already provided
time_label = time_label[:-1]
- self.addstr(self.graph_height + 2, 4 + loc, time_label, primary_color)
- self.addstr(self.graph_height + 2, graph_column + 10 + loc, time_label, secondary_color)
+ self.addstr(self.graph_height + 2, 4 + loc, time_label, PRIMARY_COLOR)
+ self.addstr(self.graph_height + 2, graph_column + 10 + loc, time_label, SECONDARY_COLOR)
param.draw(self, width, height) # allows current stats to modify the display
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits