Advertisement
jayronsoares

Error

Nov 28th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import csv, sys
  5. import networkx as nx
  6. import numpy as np
  7. import pylab as P
  8. import MySQLdb as mdb
  9.  
  10. conn = mdb.connect('10.251.1.137', 'jayron','MySQLight', 'SEN_Grafo')
  11. dbcursor = conn.cursor()
  12. Q = dbcursor.execute("select origid, destid, weight from gr_ministro_lei where weight > 90")
  13. #resp = Q.fetchall()
  14. print Q
  15.        
  16. def ministro_lei(nedges=0):
  17.  
  18.     """
  19.    Cria multigrafo de Ministros e leis
  20.  
  21.    """
  22.     # stf = csv.reader(open('resultado.csv', 'rb'), delimiter=',', quotechar='|')
  23.     if not nedges:
  24.         resp = Q.fetchall()
  25.         nedges = len(resp)
  26.         print " passou aqui !", resp, nedges
  27.        
  28.     else:
  29.         resp = Q.fetchmany()
  30.    
  31.     eds = [(i[0],i[1],i[2]) for i in resp]
  32.     G = nx.DiGraph(nome='ministro_lei')
  33.     G.add_weighted_edges_from(eds)
  34.     lista = []
  35.     for i in G.degree():
  36.         try:
  37.             if int(i):
  38.                 lista.append(int(i))
  39.         except:
  40.             lista.sort() # print "=>", i
  41.     P.hist(lista, bins=60, facecolor='green')
  42.     P.savefig('degree_>_2.png')
  43.     P.title('Nodes degrees')
  44.     P.grid(True)
  45.     P.show()
  46.    
  47.     return G, eds
  48.  
  49. g, e = ministro_lei()
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement