[rhmessaging-commits] rhmessaging commits: r3838 - in mgmt/trunk/cumin: python/cumin/grid and 2 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Wed Feb 3 13:37:21 EST 2010


Author: eallen
Date: 2010-02-03 13:37:21 -0500 (Wed, 03 Feb 2010)
New Revision: 3838

Modified:
   mgmt/trunk/cumin/python/cumin/OpenFlashChart.py
   mgmt/trunk/cumin/python/cumin/grid/pool.strings
   mgmt/trunk/cumin/python/cumin/grid/slot.py
   mgmt/trunk/cumin/python/cumin/grid/slot.strings
   mgmt/trunk/cumin/python/cumin/inventory/system.strings
   mgmt/trunk/cumin/resources/slots.swf
Log:
Updates to flash slot vis to:
 - handle no cjson or jjson module installed
 - collapse systems and allow drill down when slots > 500

Modified: mgmt/trunk/cumin/python/cumin/OpenFlashChart.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/OpenFlashChart.py	2010-02-03 14:30:51 UTC (rev 3837)
+++ mgmt/trunk/cumin/python/cumin/OpenFlashChart.py	2010-02-03 18:37:21 UTC (rev 3838)
@@ -14,76 +14,76 @@
 CJSON = False
 JJSON = False
 try:
-	import cjson
-	CJSON = True
+    import cjson
+    CJSON = True
 except ImportError:
-	try:
-		import json
-		JJSON = True
-	except ImportError:
-		pass
-import	copy	
+    try:
+        import json
+        JJSON = True
+    except ImportError:
+        pass
+import    copy    
 
 class Chart(dict):
-	# Dictionary for replacing attribute names
-	replaceKeyDictionary =	{
-		"on_show": "on-show",			"on_click": "on-click", "on_click_text": "on-click-text",
-		"start_angle": "start-angle",
-		
-		"threeD": "3d",					"tick_height": "tick-height",
-		"grid_colour": "grid-colour",	"tick_length": "tick-length",
-	
-		"dot_style": "dot-style",		"dot_size": "dot-size",
-		"halo_size": "halo-size",
-			
-		"line_style": "line-style",		"outline_colour": "outline-colour",
-		"fill_alpha": "fill-alpha",		"gradient_fill": "gradient-fill",
-		"visible_steps": "visible-steps",
-	}
+    # Dictionary for replacing attribute names
+    replaceKeyDictionary =    {
+        "on_show": "on-show",            "on_click": "on-click", "on_click_text": "on-click-text",
+        "start_angle": "start-angle",
+        
+        "threeD": "3d",                    "tick_height": "tick-height",
+        "grid_colour": "grid-colour",    "tick_length": "tick-length",
+    
+        "dot_style": "dot-style",        "dot_size": "dot-size",
+        "halo_size": "halo-size",
+            
+        "line_style": "line-style",        "outline_colour": "outline-colour",
+        "fill_alpha": "fill-alpha",        "gradient_fill": "gradient-fill",
+        "visible_steps": "visible-steps",
+    }
 
-	# Redefine to allow for nested attributes.
-	# E.g. when calling the leaf attribute, text, in chart.title.text
-	#      without previously defining the branch attribute, title.
-	def __getattribute__(self, key):
-		try:
-			return dict.__getattribute__(self, key)
-		except AttributeError:
-			self.__dict__[key] = Chart()
-			return dict.__getattribute__(self, key)
+    # Redefine to allow for nested attributes.
+    # E.g. when calling the leaf attribute, text, in chart.title.text
+    #      without previously defining the branch attribute, title.
+    def __getattribute__(self, key):
+        try:
+            return dict.__getattribute__(self, key)
+        except AttributeError:
+            self.__dict__[key] = Chart()
+            return dict.__getattribute__(self, key)
 
-	# This copy function is called when we want to get all the attributes of the 
-	# chart instance so we can pass it off to cjson to create the JSON string.
-	# Recursive trick to get leaf attributes.  Have to be careful of list types.
-	# Also, replace certain underscored keys.
-	# E.g. getting the leaf attribute, text, from the parent Chart instance where a  
-	#      previous assignment was to chart.title.text
-	def __copy__(self):
-		attributes = dict()
-		for key, value in self.__dict__.items():
-			if isinstance(value, list):
-				attributes[self.replaceKey(key)] = [copy.copy(item) for item in value]
-			else:
-				attributes[self.replaceKey(key)] = copy.copy(value)
-		return attributes
+    # This copy function is called when we want to get all the attributes of the 
+    # chart instance so we can pass it off to cjson to create the JSON string.
+    # Recursive trick to get leaf attributes.  Have to be careful of list types.
+    # Also, replace certain underscored keys.
+    # E.g. getting the leaf attribute, text, from the parent Chart instance where a  
+    #      previous assignment was to chart.title.text
+    def __copy__(self):
+        attributes = dict()
+        for key, value in self.__dict__.items():
+            if isinstance(value, list):
+                attributes[self.replaceKey(key)] = [copy.copy(item) for item in value]
+            else:
+                attributes[self.replaceKey(key)] = copy.copy(value)
+        return attributes
 
-	# If key has an underscore, replace with a dash.
-	# Python does not allow dash in object names.
-	def replaceKey(self, key):
-		if (key in self.replaceKeyDictionary):
-			return self.replaceKeyDictionary[key]
-		else:
-			return key
+    # If key has an underscore, replace with a dash.
+    # Python does not allow dash in object names.
+    def replaceKey(self, key):
+        if (key in self.replaceKeyDictionary):
+            return self.replaceKeyDictionary[key]
+        else:
+            return key
 
-	# Encode the chart attributes as JSON
-	def create(self):
-		attributes = copy.copy(self)
-		if CJSON:
-			return cjson.encode(attributes)
-		elif JJSON:
-			return json.dumps(attributes)
-		else:
-			return str(attributes)
+    # Encode the chart attributes as JSON
+    def create(self):
+        attributes = copy.copy(self)
+        if CJSON:
+            return cjson.encode(attributes)
+        elif JJSON:
+            return json.dumps(attributes)
+        else:
+            return str(attributes).replace("': u'", "': '")
 
 
 class Element(Chart):
-	pass
\ No newline at end of file
+    pass
\ No newline at end of file

Modified: mgmt/trunk/cumin/python/cumin/grid/pool.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/pool.strings	2010-02-03 14:30:51 UTC (rev 3837)
+++ mgmt/trunk/cumin/python/cumin/grid/pool.strings	2010-02-03 18:37:21 UTC (rev 3838)
@@ -69,15 +69,10 @@
     function updatePoolSlotVis(id, loadType) {
         var chart = cumin.getFlashChart(id);
         if ((chart != null)  && (typeof chart.src != "undefined")) {
-            if (typeof loadType != "undefined") {
-                if (typeof chart.reload != "undefined")
-                    chart.reload(chart.src, false);
-            } else {
-                if (typeof chart.load != "undefined")
-                    chart.load(chart.src, false);
-                else
-                    wooly.log("load not definded for " + id);
-            }
+            if (typeof chart.load != "undefined")
+                chart.load(chart.src, false);
+            else
+                wooly.log("load not definded for " + id);
         }
     }
     function vis_loaded(data) {
@@ -96,6 +91,14 @@
             updatePoolSlotVis('{id}ctrl');
         }
     }
+    function vis_expand(parent) {
+        var chart = cumin.getFlashChart("{id}");
+        var src = chart.src;
+        var branch = wooly.session.branch(src);
+        branch['expanded'] = parent;
+        chart.src = branch.marshal();
+        updatePoolSlotVis("{id}", "reload");
+    }
     function vis_treemap_over(type, value) {
         var chart = cumin.getFlashChart("{id}");
         if (chart) {

Modified: mgmt/trunk/cumin/python/cumin/grid/slot.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/slot.py	2010-02-03 14:30:51 UTC (rev 3837)
+++ mgmt/trunk/cumin/python/cumin/grid/slot.py	2010-02-03 18:37:21 UTC (rev 3838)
@@ -155,6 +155,7 @@
     shapes = ["rectangle", "circle", "circle"]
     max_width = 400
     max_png_age = 30
+    max_visible_slots = 500 # start drill-down mode after this number
     def __init__(self, app, name, param, desc):
         super(SlotMapPage, self).__init__(app, name)
 
@@ -171,6 +172,10 @@
         self.json = Parameter(app, "json")
         self.add_parameter(self.json)
 
+        self.expanded = Parameter(app, "expanded")
+        self.expanded.default = "all"
+        self.add_parameter(self.expanded)
+
         group = Parameter(app, "agroup")
         self.groups = ListParameter(app, "group", group)
         self.add_parameter(self.groups)
@@ -241,6 +246,18 @@
             d[atr].append(i)
         return d
 
+    def get_activityStates(self, records, plist):
+        """ for each unique combination of activity:state, return a dictionary entry
+            that counts the number of records with that combo """
+
+        d = dict()
+        for i in plist:
+            activityState = "%s:%s" % (records[i]["activity"], records[i]["state"])
+            if not activityState in d:
+                d[activityState] = 0
+            d[activityState] += 1
+        return d
+
     def render_json(self, session):
         cursor = self.slots.execute(session)
         records = cursor_to_rows(cursor)
@@ -257,15 +274,15 @@
         root.slots = slot_count
         root.vis = self.json.get(session)
         root.activity_colors = self.interiors
+        expanded = self.expanded.get(session)
+        json = self.json.get(session)
         leaves = True
-        if self.json.get(session) == "slots":
-            if slot_count > 1000:
-                leaves = False
+        root.tree = self.treeify(records, range(slot_count), groups, 0, 
+                                 expanded, leaves, slot_count, json)
 
-        root.tree = self.treeify(records, range(slot_count), groups, 0, leaves)
         return "[%s]" % root.create()
 
-    def treeify(self, records, plist, groups, level, leaves):
+    def treeify(self, records, plist, groups, level, expanded, leaves, slot_count, json):
         level_list = list()
         # leaf
         if level == len(groups):
@@ -282,11 +299,21 @@
                     el.name = "slot"
                     el.slot_id = records[i]["id"]
                     level_list.append(el)
+            else:
+                # display summary info for all the slots under this grouping
+                activityStates = self.get_activityStates(records, plist)
+                for activityState in activityStates:
+                    el = Element()
+                    el.name = "slot_info"
+                    el.value = activityState
+                    el.count = activityStates[activityState]
+                    level_list.append(el)
             return level_list
 
         # not a leaf
         group = groups[level]
         level_dict = self.get_info_array(records, plist, group)
+        first = True
         for key in sorted(level_dict):
             el = Element()
             el.name = group
@@ -294,7 +321,23 @@
             el.slots = len(level_dict[key])
             el.level = level
             if level < len(groups):
-                el.tree = self.treeify(records, level_dict[key], groups, level + 1, leaves)
+                if json == "slots":
+                    if expanded == self.expanded.default:
+                        # expand the 1st group if there are too many slots
+                        if slot_count >= self.max_visible_slots:
+                            if first:
+                                leaves = True
+                                first = False
+                            else: 
+                                leaves = False
+                        else:
+                            leaves = True
+                    elif expanded == key:
+                        leaves = True
+                    else:
+                        leaves = False
+                el.tree = self.treeify(records, level_dict[key], groups, level + 1, 
+                                       expanded, leaves, slot_count, json)
             level_list.append(el)
 
         return level_list

Modified: mgmt/trunk/cumin/python/cumin/grid/slot.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/slot.strings	2010-02-03 14:30:51 UTC (rev 3837)
+++ mgmt/trunk/cumin/python/cumin/grid/slot.strings	2010-02-03 18:37:21 UTC (rev 3838)
@@ -793,7 +793,6 @@
 function vis_clicked(slot) {
     go_to_slot(slot);
 }
-
 /* generic get value from cookie */
 function get_cookie(name) {
     return get_value(document.cookie, name, ";");

Modified: mgmt/trunk/cumin/python/cumin/inventory/system.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/inventory/system.strings	2010-02-03 14:30:51 UTC (rev 3837)
+++ mgmt/trunk/cumin/python/cumin/inventory/system.strings	2010-02-03 18:37:21 UTC (rev 3838)
@@ -96,15 +96,10 @@
     function updateSystemSlotVis(id, loadType) {
         var chart = cumin.getFlashChart(id);
         if ((chart != null)  && (typeof chart.src != "undefined")) {
-            if (typeof loadType != "undefined") {
-                if (typeof chart.reload != "undefined")
-                    chart.reload(chart.src, false);
-            } else {
-                if (typeof chart.load != "undefined")
-                    chart.load(chart.src, false);
-                else
-                    wooly.log("load not definded for " + id);
-            }
+            if (typeof chart.load != "undefined")
+                chart.load(chart.src, false);
+            else
+                wooly.log("load not definded for " + id);
         }
     }
     function vis_loaded(data) {

Modified: mgmt/trunk/cumin/resources/slots.swf
===================================================================
(Binary files differ)



More information about the rhmessaging-commits mailing list