comparison service/arduinoNode/dotrender.py @ 166:c0180bd2b33a

only recompile if the C code is new. redo Device class api. single temperature sensor is working Ignore-this: e78106d25dbb2ac8c5e5d8a81d576358
author drewp@bigasterisk.com
date Sat, 11 Apr 2015 01:43:59 -0700
parents
children
comparison
equal deleted inserted replaced
165:af4e9d9f0bd8 166:c0180bd2b33a
1 from rdflib import Literal, URIRef
2
3 def render(configGraph, boards):
4 nodes = {} # uri: (nodeid, nodeline)
5 edges = []
6
7 serial = [0]
8 def addNode(node):
9 if node not in nodes or isinstance(node, Literal):
10 id = 'node%s' % serial[0]
11 if isinstance(node, URIRef):
12 short = configGraph.qname(node)
13 else:
14 short = str(node)
15 nodes[node] = (
16 id,
17 '%s [ label="%s", shape = record, color = blue ];' % (
18 id, short))
19 serial[0] += 1
20 else:
21 id = nodes[node][0]
22 return id
23 def addStmt(stmt):
24 ns = addNode(stmt[0])
25 no = addNode(stmt[2])
26 edges.append('%s -> %s [ label="%s" ];' % (
27 ns, no, configGraph.qname(stmt[1])))
28 for b in boards:
29 for stmt in b.currentGraph():
30 # color these differently from config ones
31 addStmt(stmt)
32 for stmt in configGraph:
33 addStmt(stmt)
34
35 nodes = '\n'.join(line for _, line in nodes.values())
36 edges = '\n'.join(edges)
37 return '''
38 digraph {
39 graph [ranksep=0.4];
40 node [fontsize=8, margin=0];
41 edge[weight=1.2, fontsize=8, fontcolor="gray"];
42 rankdir = LR;
43 charset="utf-8";
44 %(nodes)s
45 %(edges)s
46 }
47 ''' % dict(nodes=nodes, edges=edges)