@@ -0,0 +1,1932 @@
+import graph_tool.all as gt%0Aimport pandas as pd%0Aimport os%0Aimport pickle%0A%0A(amends, parties_votings, congressmen_votings, congressmen) =  pd.read_pickle('data.pck')%0A%0A# merge add cabecas column%0A%0Adf = pd.merge(pd.read_csv('cabecas.csv', sep=';').reset_index(), congressmen_votings.transpose().reset_index(), %0A               left_on='TSE' ,right_on='index', how='right')%0A%0A# build network%0A%0Ag = gt.Graph()%0A%0Aname_to_vertex = %7B%7D%0Avertex_to_name = %7B%7D%0Adiap = %5B%5D%0Aedges = %7B%7D%0A%0A# add vertices%0A%0Adata = df3.values.tolist()%0A%0Afor line in data:%0A    name = line%5B4%5D%0A    diap.append(line%5B3%5D)%0A    name_to_vertex%5Bname%5D = g.add_vertex()%0A    vertex_to_name%5Bname_to_vertex%5Bname%5D%5D = name%0A      %0A# add edges%0A%0Aweight_map = g.new_edge_property('double')%0A%0Afor idx1 in range(len(data)):%0A    for idx2 in range(idx1+1, len(data)):%0A        dep1, dep2 = data%5Bidx1%5D, data%5Bidx2%5D%0A        e = g.add_edge(name_to_vertex%5Bdep1%5B4%5D%5D, name_to_vertex%5Bdep2%5B4%5D%5D)%0A%0A        # calculates similarity%0A        try:%0A            common_votes = sum(%5B dep1%5Bidx%5D == dep2%5Bidx%5D for idx in range(5, len(data%5B1%5D)) %5D)%0A%0A            weight_map%5Be%5D = 1. * common_votes / len(dep1%5B5:%5D)%0A            edges%5B(dep1%5B4%5D,dep2%5B4%5D)%5D = %5Bweight_map%5Be%5D, dep1, dep2%5D # adds for debuging%0A%0A        except Exception, e:%0A            print str(e)%0A%0A%0A# conventional centrality analysis%0A%0A# degree %0Adegree = g.degree_property_map('total', weight = weight_map)%0A%0A# vertice betweeness%0Abetweeness = gt.betweenness(g, weight = weight_map)%0A%0A# closeness%0Acloseness = gt.closeness(g, weight = weight_map)%0A%0A# Katz%0Akatz = gt.katz(g, weight = weight_map)%0A%0A# Pagerank%0Apagerank = gt.pagerank(g, weight = weight_map)%0A%0A%0Ametrics = %5B'name', 'diap', 'betweenness', 'closeness', 'degree', 'katz', 'pagerank'%5D%0Adf = pd.DataFrame(zip(vertex_to_name.values(), diap, degree.a.tolist(), betweeness%5B0%5D.a.tolist(), closeness.a.tolist(), katz.a.tolist(), %0A                      pagerank.a.tolist()), columns = metrics)%0A%0Adf.sort('Page', ascending=True)%5B:30%5D%0A

Create conventional_centrality_analysis.py