...
Or even to use one of these nice libraries for fancy rendering (d3 as Treemap or SunBurst):
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
SIZE = { "aborted": 50, "queued": 10, "complete": 10, "unknown": 10, "submitted": 30, "active": 50, "running": 10, "shutdown": 30, "halted": 50, } STATUS = { "aborted": 5, "queued": 3, "complete": 2, "unknown": 10, "submitted": 4, "active": 6, "running": 10, "shutdown": 7, "suspended": 1, "halted": 8, } class ObserverD3(Observer): """ simple ecflow watchdog class + html output """ def __init__(self, defs, node, port, path, fname="ecflow.html"): super(ObserverD3, self).__init__(defs, node, port, path) self.fname = fname self.status_mask = ("queued", "complete", "unknown") self.d3body = """ <!DOCTYPE html> <meta charset="utf-8"> <style> body { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; margin: auto; position: relative; width: 960px; } form { position: absolute; right: 10px; top: 10px; } .node { border: solid 1px white; font: 10px sans-serif; line-height: 12px; overflow: hidden; position: absolute; text-indent: 2px; } </style> <form> <label><input type="radio" name="mode" value="size" checked>Size</label> <label><input type="radio" name="mode" value="count"> Count</label> </form> <script src="http://d3js.org/d3.v3.min.js"></script> <script> var margin = {top: 40, right: 10, bottom: 10, left: 10}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var color = d3.scale.category20c(); var treemap = d3.layout.treemap() .size([width, height]) .sticky(true) .value(function(d) { return d.size; }); var div = d3.select("body").append("div") .style("position", "relative") .style("width", (width + margin.left + margin.right) + "px") .style("height", (height + margin.top + margin.bottom) + "px") .style("left", margin.left + "px") .style("top", margin.top + "px"); d3.json("ecflow.json", function(error, root) { var node = div.datum(root).selectAll(".node") .data(treemap.nodes) .enter().append("div") .attr("class", "node") .call(position) .style("background", function(d) { return d.children ? color(d.name) : null; }) .text(function(d) { return d.childrenkids ? null : d.name; }); d3.selectAll("input").on("change", function change() { var value = this.value === "count" ? function() { return 1; } : function(d) { return d.size; }; node .data(treemap.value(value).nodes) .transition() .duration(1500) .call(position); }); }); function position() { this.style("left", function(d) { return d.x + "px"; }) .style("top", function(d) { return d.y + "px"; }) .style("width", function(d) { return Math.max(0, d.dx - 1) + "px"; }) .style("height", function(d) { return Math.max(0, d.dy - 1) + "px"; }); } </script> """ def process_node(self, node, fp): if node is None: return elif isinstance(node, ec.Alias): return elif isinstance(node, ec.Defs): status = "%s" % node.get_server_state() status = status.lower() name = "%s@%s" % (self.node, self.port) else: status = "%s" % node.get_state() name = node.name() if status in self.status_mask: return print >>fp, "<ul>" print >>fp, "<li class='%s fold'>%s" % (status, name) if isinstance(node, ec.Defs): for kid in node.suites: self.process_node(kid, fp) else: for kid in node.nodes: self.process_node(kid, fp) print >>fp, "</li></ul>" # def, suite, family, task # autocancel, clock, complete, cron, date, day, defstatus, edit # event, inlimit, label, late, limit, meter, repeat, time, today, trigger def get_dict(self, node): if isinstance(node, ec.Alias): return status = "%s" % node.get_state() try: a = SIZE[status], except: print SIZE.keys(), status; raise return { "name": node.name(), "status": STATUS[status], "state": status, "size": SIZE[status], "children": [ self.get_dict(kid) for kid in node.nodes ]} def run(self): client = ec.Client(self.node, self.port) fp = open(self.fname, "w") print >> fp, self.d3body fp.close() while 1: client.sync_local() # get changes, if self.path == "/": node = client.get_defs() else: node = client.get_defs().find_abs_node(self.path) if 0: assert node is not None if isinstance(node, ec.Defs): status = "%s" % node.get_server_state() d = {"name": "%s-%s" % (self.node, self.port), "status": STATUS[status.lower()], "size": SIZE[status.lower()], "state": status, "children": [self.get_dict(kid) for kid in node.suites]} elif isinstance(node, ec.Alias): pass elif (isinstance(node, ec.Suite) or isinstance(node, ec.Family) or isinstance(node, ec.Task)): d = self.get_dict(node) else: d = {}; print type(node) # FIXME import json print d fp = open("ecflow.json", "w") print >>fp, json.dumps(d) fp.close() time.sleep(90) |
...