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)
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 = {}