]> gitweb.pimeys.fr Git - chopes.git/commitdiff
ce qui permet de faire des graphes (noms seuls et liens, pas d'infos supplémentaires). master
authorGaétan Lerisson <lerisson@crans.org>
Tue, 14 Aug 2012 01:09:28 +0000 (03:09 +0200)
committerGaétan Lerisson <lerisson@crans.org>
Tue, 14 Aug 2012 01:09:28 +0000 (03:09 +0200)
.gitignore
graphe.py [new file with mode: 0755]

index a57fd2e1371d220e6a03263011d32a51bebfb738..62633f6b3c13c630a9ba2c47e328c13e3d002125 100644 (file)
@@ -1,6 +1,7 @@
 # Custom #
 ###################
 *~
 # Custom #
 ###################
 *~
+*.png
 
 # Compiled source #
 ###################
 
 # Compiled source #
 ###################
diff --git a/graphe.py b/graphe.py
new file mode 100755 (executable)
index 0000000..499abb2
--- /dev/null
+++ b/graphe.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+# -*- encoding: utf-8 -*-
+
+
+# Import graphviz
+import gv
+
+import psycopg2
+import psycopg2.extras
+
+def getcursor():
+    con = psycopg2.connect(database = "chopes")
+    cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
+    return con, cur
+
+# Import pygraph
+from pygraph.classes.graph import graph
+from pygraph.classes.digraph import digraph
+from pygraph.algorithms.searching import breadth_first_search
+from pygraph.readwrite.dot import write
+
+
+def getgraph():
+    con, cur = getcursor()
+    cur.execute("SELECT * FROM gens;")
+    l = cur.fetchall()
+    gens = {n: nom.decode("utf8") for n,nom in l}
+    cur.execute("SELECT id1, id2 FROM chopes;")
+    chopes = cur.fetchall()
+    return gens, chopes
+
+
+if __name__ == "__main__":
+    gens, chopes = getgraph()
+    #gr = graph()
+    textgraph = u"graph chope {\n"
+    for noeud in gens.values():
+        textgraph += u'"%s";\n' % noeud
+    #gr.add_nodes(gens.values())
+    
+    for chopeur, victime in chopes:
+        textgraph += u'"%s" -- "%s";\n' % (gens[chopeur], gens[victime])
+        #gr.add_edge((gens[chopeur], gens[victime]))
+    textgraph += "}\n"
+    print textgraph
+    # Draw as PNG
+    #dot = write(gr)
+    dot = textgraph.encode("utf8")
+    gvv = gv.readstring(dot)
+    gv.layout(gvv, 'dot')
+    gv.render(gvv, 'png', 'chopes.png')