Ejemplo n.º 1
0
import networkx as nx# sudo pip install networkx
import file_reader
import community
import matplotlib.pyplot as plt

G = nx.DiGraph() # non-directed graph: must be non-directed for com

file_reader.readInDonors(G, 1.0, False)
file_reader.readCommitteeToCommittee(G)


obamaTag = "C00431445";
clintonTag = "C00431569";
edwardsTag = "C00431205";
bidenTag = "C00431916";
doddTag = "C00431379";
gravelTag = "C00423202";
kucinichTag = "C00430975";
richardsonTag = "C00431577";

dems2008 = {obamaTag : "Barack Obama", clintonTag: "Hilary Clinton", edwardsTag: "John Edwards",
    bidenTag: "Joe Biden", doddTag: "Chris Dodd", gravelTag: "Mike Gravel",
    kucinichTag: "Dennis Kucinich", richardsonTag: "Bill Richardson"};

def isPac(id):
	return id[0:2] == 'C0'

# edge (i, j) means that i donated to j.
allPacs = set([])
# first, find all pacs that donated to the candidates of interest. (exists edge )
for node in G.nodes():
Ejemplo n.º 2
0
import networkx as nx# sudo pip install networkx
import file_reader

minDate = "01012008"

G = nx.DiGraph() #directed graph

file_reader.readInDonors(G, 1.0, true, minDate)
file_reader.readCommitteeToCommittee(G)
weightedPR = nx.pagerank(G)
for candidate in dems2008.keys():
	print dems2008[candidate], weightedPR[candidate] 
Ejemplo n.º 3
0
			 nClique['pacNclique'],
			 str(cs[candidate['id']]['community_size']),
			 str(cs[candidate['id']]['pacs_in_community'])])	
		print outstr


print 'year,party,name,id,delegates,percent_of_delegates,popular_vote,weighted_page_rank,pacs_contributing,direct_individual_donors,all_individual_donors,pac_n_clique_overlap,all_n_clique_overlap,community_size,pacs_in_community'
for year in [2004]:
	G = nx.DiGraph() #directed graph
	ndG = nx.Graph() # non-directed graph: must be non-directed for com

	donorFile = "../CS224w_Project/" + str(int(year) - 1) + "_" + str(year) + "/itcont.txt"
	committeeFile = "../CS224w_Project/" + str(int(year) - 1) + "_" + str(year) + "/itoth.txt"
	cnFile = "../CS224w_Project/" + str(int(year) - 1) + "_" + str(year) + "/cn.txt"
	itpasFile = "../CS224w_Project/" + str(int(year) - 1) + "_" + str(year) + "/itpas2.txt"

	minDate = "0101" + str(year)
	file_reader.readInDonors(G, minDate, donorFile)
	file_reader.readCommitteeToCommittee(G, committeeFile, minDate)
	file_reader.readCommitteeToCandidate(G, itpasFile, cnFile, minDate)

	file_reader.readInDonors(ndG, minDate, donorFile)
	file_reader.readCommitteeToCommittee(ndG, committeeFile, minDate)
	file_reader.readCommitteeToCandidate(ndG, itpasFile, cnFile, minDate)
	weightedPR = nx.pagerank(G)

	partition = community.best_partition(ndG)

	print_stats(year, 'd', G, ndG, candidates, partition)
	print_stats(year, 'r', G, ndG, candidates, partition)
Ejemplo n.º 4
0
import networkx as nx# sudo pip install networkx
import file_reader
import community
import matplotlib.pyplot as plt


G = nx.Graph() # non-directed graph: must be non-directed for com
donorFile = "../CS224w_Project/1995_1996/itcont.txt"
committeeFile = "../CS224w_Project/1995_1996/itoth.txt"
cnFile = "../CS224w_Project/1995_1996/cn.txt"
itpasFile = "../CS224w_Project/1995_1996/itpas2.txt"

file_reader.readInDonors(G, "01011996", donorFile)
print 'read donors'
file_reader.readCommitteeToCommittee(G, committeeFile)
file_reader.readCommitteeToCandidate(G, itpasFile, cnFile, '01011996')
print 'read committees'
#first compute the best partition
print 'made partition'

candidates = set(['C00317743','C00361352','C00343772',  'C00452532', 'C00301333',  'C00299917', 
'C00301465','C00302216'])

def community_structure(G, candidates):
    partition = community.best_partition(G)
    to_return = {}
    candidates_found = 0
    for candidate in candidates:
        to_return[candidate] = {}
    candidate_to_pacs_in_community = {}
    candidate_to_community_size = {}