Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import csv, sys
- import networkx as nx
- import numpy as np
- import pylab as P
- import MySQLdb as mdb
- conn = mdb.connect('10.251.1.137', 'jayron','MySQLight', 'SEN_Grafo')
- dbcursor = conn.cursor()
- Q = dbcursor.execute("select origid, destid, weight from gr_ministro_lei where weight > 90")
- #resp = Q.fetchall()
- print Q
- def ministro_lei(nedges=0):
- """
- Cria multigrafo de Ministros e leis
- """
- # stf = csv.reader(open('resultado.csv', 'rb'), delimiter=',', quotechar='|')
- if not nedges:
- resp = Q.fetchall()
- nedges = len(resp)
- print " passou aqui !", resp, nedges
- else:
- resp = Q.fetchmany()
- eds = [(i[0],i[1],i[2]) for i in resp]
- G = nx.DiGraph(nome='ministro_lei')
- G.add_weighted_edges_from(eds)
- lista = []
- for i in G.degree():
- try:
- if int(i):
- lista.append(int(i))
- except:
- lista.sort() # print "=>", i
- P.hist(lista, bins=60, facecolor='green')
- P.savefig('degree_>_2.png')
- P.title('Nodes degrees')
- P.grid(True)
- P.show()
- return G, eds
- g, e = ministro_lei()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement