Author: justi9
Date: 2007-11-21 16:08:58 -0500 (Wed, 21 Nov 2007)
New Revision: 1353
Modified:
mgmt/cumin/python/cumin/charts.py
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/widgets.py
Log:
In preparation for labeled axes in charts, adds a samples method to CuminStat.
Modified: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py 2007-11-21 17:32:03 UTC (rev 1352)
+++ mgmt/cumin/python/cumin/charts.py 2007-11-21 21:08:58 UTC (rev 1353)
@@ -7,16 +7,20 @@
self.height = height
self.surface = ImageSurface(FORMAT_ARGB32, width + 60, height + 20)
self.max_value = 1
+ self.value_interval = 5
def set_max_value(self, value):
self.max_value = value
- def plot_values(self, values, interval=5, color=(0, 0, 0)):
+ def set_value_interval(self, interval):
+ self.value_interval = interval
+
+ def plot_values(self, values, color=(0, 0, 0)):
cr = Context(self.surface)
cr.set_line_width(2)
cr.set_source_rgb(*color)
- xs = range(self.width, 0 - interval, -interval)
+ xs = range(self.width, 0 - self.value_interval, -self.value_interval)
for x, value in zip(xs, values):
y = self.height - (value / float(self.max_value)) * self.height
@@ -33,17 +37,27 @@
cr.stroke()
- def plot_x_intervals(self, interval=40):
- cr = Context(self.surface)
- cr.set_line_width(0.2)
- cr.set_source_rgb(0.8, 0.8, 0.8)
+ def plot_x_axis(self, values, interval=40):
+ if values:
+ cr = Context(self.surface)
+ cr.set_line_width(0.2)
+ cr.set_source_rgb(0.8, 0.8, 0.8)
- for x in range(0, self.width, interval):
- cr.move_to(x, 0)
- cr.line_to(x, self.height)
+ zero = values[0]
+ xs = range(self.width, 0 - interval, -interval)
- cr.stroke()
+ for x in xs:
+ cr.move_to(x, 0)
+ cr.line_to(x, self.height + 10)
+ # XXX
+ #index = 120 - x // self.value_interval
+ #value = values[index] - zero
+ #print x, index, value
+ #cr.show_text(value.strftime("%S"))
+
+ cr.stroke()
+
def plot_y_axis(self):
cr = Context(self.surface)
@@ -55,5 +69,7 @@
cr.move_to(x, self.height)
cr.show_text("0")
+ cr.stroke()
+
def write(self, writer):
self.surface.write_to_png(writer)
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2007-11-21 17:32:03 UTC (rev 1352)
+++ mgmt/cumin/python/cumin/model.py 2007-11-21 21:08:58 UTC (rev 1353)
@@ -61,16 +61,17 @@
def value(self, object):
return nvl(getattr(object.stats, self.name), -1)
- def values(self, object, limit=None):
+ def samples(self, object, limit=None):
cls = self.cumin_class.mint_stats_class
stats = cls.select(orderBy="-id")[:limit]
- values = list()
+ samples = list()
for stat in stats:
+ time = getattr(stat, "recTime")
value = getattr(stat, self.name)
- values.append(value)
+ samples.append((time, value))
- return values
+ return samples
def rate(self, object):
if object.stats:
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2007-11-21 17:32:03 UTC (rev 1352)
+++ mgmt/cumin/python/cumin/widgets.py 2007-11-21 21:08:58 UTC (rev 1353)
@@ -176,9 +176,12 @@
cls = self.app.cmodel.get_class(object)
stats = [cls.get_stat(x) for x in self.stats.get(session)]
+ samples = stats[0].samples(object, 121)
+ times = [x[0] for x in samples]
+
values = dict()
for stat in stats:
- values[stat] = stat.values(object, 121)
+ values[stat] = [x[1] for x in stat.samples(object, 121)]
max_value = 0
for stat in stats:
@@ -187,7 +190,7 @@
max_value = max_value + (100 - max_value % 100)
chart.set_max_value(int(max_value))
- chart.plot_x_intervals()
+ chart.plot_x_axis(times)
chart.plot_y_axis()
colors = ((1,0,0), (0,0,1), (0,1,0))