Author: justi9
Date: 2008-01-06 00:02:43 -0500 (Sun, 06 Jan 2008)
New Revision: 1537
Modified:
mgmt/cumin/python/cumin/charts.py
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/stat.py
mgmt/cumin/python/cumin/stat.strings
mgmt/notes/justin-todo.txt
Log:
Working toward better charts.
Adds reference values in the y dimension. Adds neatly divisible
rounding.
Makes the drawing logic resilient to varying x max values, so we can
introduce variable time ranges in charts.
Modified: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py 2008-01-04 21:25:32 UTC (rev 1536)
+++ mgmt/cumin/python/cumin/charts.py 2008-01-06 05:02:43 UTC (rev 1537)
@@ -10,21 +10,22 @@
self.width = width
self.height = height
self.surface = ImageSurface(FORMAT_ARGB32, width + 60, height + 20)
- self.max_value = 1
- self.value_interval = 5
+ self.surface.set_device_offset(0.5, 8.5)
+ self.x_max = 1
+ self.y_max = 1
- def set_max_value(self, value):
- self.max_value = value
+ def set_x_max(self, value):
+ self.x_max = value
- def set_value_interval(self, interval):
- self.value_interval = interval
+ def set_y_max(self, value):
+ self.y_max = value
def plot_values(self, samples, color=(0, 0, 0)):
cr = Context(self.surface)
cr.set_line_width(2)
cr.set_source_rgb(*color)
- tzero = time()
+ tnow = time()
for dt, value in samples:
if value is None:
@@ -32,49 +33,63 @@
value = 0
t = secs(dt)
- x = self.width + (t - tzero)
- y = self.height - (value / float(self.max_value)) * self.height
+
+ x = self.width - ((tnow - t) / float(self.x_max)) * self.width
+ y = self.height - (value / float(self.y_max)) * self.height
cr.line_to(x, y)
- cr.stroke()
+ self.stroke(cr)
def plot_frame(self, color=(0.8, 0.8, 0.8)):
cr = Context(self.surface)
cr.set_line_width(1)
cr.set_source_rgb(*color)
-
- cr.rectangle(0.5, 0.5, self.width, self.height)
- cr.stroke()
+ cr.move_to(self.width, 0)
+ cr.line_to(self.width, self.height)
+ cr.line_to(0, self.height)
- def plot_x_axis(self, interval=60):
+ self.stroke(cr)
+
+ def plot_x_axis(self, interval):
cr = Context(self.surface)
cr.set_line_width(0.2)
- cr.set_source_rgb(0.8, 0.8, 0.8)
+ cr.set_source_rgb(0.6, 0.6, 0.6)
- xs = range(self.width, 0 - interval, -interval)
+ i = 0
- for x, i in zip(xs, range(0, 120)):
+ for x in range(self.width, 0 - interval, -interval):
cr.move_to(x, 0)
cr.line_to(x, self.height + 10)
if i % 2 == 0:
- value = self.width - x
+ value = self.x_max - (self.x_max * x / float(self.width))
cr.show_text(fmt_duration_brief(value))
- cr.stroke()
+ i += 1
- def plot_y_axis(self):
+ self.stroke(cr)
+
+ def plot_y_axis(self, interval):
cr = Context(self.surface)
+ cr.set_line_width(0.2)
+ cr.set_source_rgb(0.6, 0.6, 0.6)
- x = self.width + 2
+ i = 0
- cr.move_to(x, 9)
- cr.show_text(str(self.max_value))
+ for y in range(self.height, 0 - interval, -interval):
+ cr.move_to(0, y)
+ cr.line_to(self.width + 2, y)
- cr.move_to(x, self.height)
- cr.show_text("0")
+ if i % 2 == 0:
+ value = self.y_max - (self.y_max * y / float(self.height))
+ cr.show_text(str(value))
+ i += 1
+
+ self.stroke(cr)
+
+ def stroke(self, cr):
cr.stroke()
def write(self, writer):
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2008-01-04 21:25:32 UTC (rev 1536)
+++ mgmt/cumin/python/cumin/model.py 2008-01-06 05:02:43 UTC (rev 1537)
@@ -89,12 +89,12 @@
self.cumin_class.add_stat(self)
- def samples(self, object, secs=600):
+ def samples(self, object, secs):
stats = object.stats
col = self.cumin_class.mint_stats_class.q.recTime
dt = datetime.now() - timedelta(seconds=secs)
- stats = stats.filter(col > dt)
+ stats = stats.filter(col >= dt)
stats = stats.orderBy("-recTime")
Modified: mgmt/cumin/python/cumin/stat.py
===================================================================
--- mgmt/cumin/python/cumin/stat.py 2008-01-04 21:25:32 UTC (rev 1536)
+++ mgmt/cumin/python/cumin/stat.py 2008-01-06 05:02:43 UTC (rev 1537)
@@ -1,6 +1,7 @@
from wooly import *
from wooly.widgets import *
from mint import *
+from math import sqrt
from widgets import *
from parameters import *
@@ -113,7 +114,7 @@
return "image/png"
def do_render(self, session, object):
- chart = LineChart(600, 120)
+ chart = LineChart(480, 120)
cls = self.class_.get(session)
stats = [cls.get_stat(x) for x in self.stats.get(session)]
@@ -123,7 +124,7 @@
values = dict()
for stat in stats:
- samples[stat] = stat.samples(object)
+ samples[stat] = stat.samples(object, 600)
values[stat] = [x[1] for x in samples[stat]]
max_value = 0
@@ -133,13 +134,25 @@
if vals:
max_value = max(max(vals), max_value)
- max_value = max_value * 1.1
- max_value = max_value + (10 - max_value % 10)
- chart.set_max_value(int(max_value))
+ max_value = int(max_value * 1.1)
- chart.plot_x_axis()
- chart.plot_y_axis()
+ if max_value < 10:
+ round = 6
+ elif max_value < 100:
+ round = 60
+ elif max_value < 10000:
+ round = 600
+ else:
+ round = 6000
+ max_value = max_value + (round - max_value % round)
+
+ chart.set_x_max(600)
+ chart.set_y_max(max_value)
+
+ chart.plot_x_axis(48)
+ chart.plot_y_axis(20)
+
colors = ((1,0,0), (0,0,1), (0,1,0))
for stat, color in zip(stats, colors):
Modified: mgmt/cumin/python/cumin/stat.strings
===================================================================
--- mgmt/cumin/python/cumin/stat.strings 2008-01-04 21:25:32 UTC (rev 1536)
+++ mgmt/cumin/python/cumin/stat.strings 2008-01-06 05:02:43 UTC (rev 1537)
@@ -80,7 +80,7 @@
}
[StatValueChart.html]
-<img id="{id}" src="{href}" height="140"
width="660"/>
+<img id="{id}" src="{href}" height="140"
width="540"/>
<script>
cumin.listeners["{id}"] = updateChartImage
</script>
Modified: mgmt/notes/justin-todo.txt
===================================================================
--- mgmt/notes/justin-todo.txt 2008-01-04 21:25:32 UTC (rev 1536)
+++ mgmt/notes/justin-todo.txt 2008-01-06 05:02:43 UTC (rev 1537)
@@ -6,8 +6,6 @@
- "purge messages from queues"
- - "unregister brokers"
-
* Improve charts
- Add legends to charts
@@ -36,6 +34,9 @@
Deferred
+ * Prevent browsers from caching the chart pngs and then running out
+ of memory
+
* Only perform js updates if there's new data
* Avoid dirtying js namespace with updateFoo methods
@@ -97,8 +98,6 @@
* Ask tross to take some prints out of ManagedBroker.start
- * Get rid of CuminClass.mint_stats_class
-
* Add a do_get_item_count, and cache result for use by get_item_count
* Add a ~3 second (or use broker update interval, if we can get that)