This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def total_edge_weight(D): | |
total = 0 | |
for edge in D.edges(data=True): | |
total += edge[2]["weight"] | |
return total | |
def average_tie_strength(D): | |
return float(total_edge_weight(D))/len(D.edges()) | |
D = nx.DiGraph() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reciprocity(D): | |
G=D.to_undirected() # copy | |
for (u,v) in D.edges(): | |
if not D.has_edge(v,u): | |
G.remove_edge(u,v) | |
return float(len(G.edges()))/len(D.to_undirected().edges()) | |
# A simple test: | |
G = nx.DiGraph() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.collect_list_memberships(username, project_id = "") | |
page_size = LIST_PAGE_SIZE | |
attempts = 0 | |
while Project.get_remaining_hits == "timeout" | |
puts "collect_list_memberships waiting..." | |
sleep(60) | |
end | |
begin | |
result = @@twitter.memberships(username, {:cursor => -1, :count => page_size}) | |
lists = result["lists"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.collect_list_members(username, list_id,project_id) | |
while Project.get_remaining_hits == "timeout" | |
puts "collect_list_members waiting..." | |
sleep(60) | |
end | |
result = @@twitter.list_members(username, list_id, {:cursor => -1}) | |
members = result["users"] | |
next_cursor = result["next_cursor"] | |
old_next_cursor = 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_most_listed_members | |
seen_lists = [] | |
seen_membersets = [] | |
@tmp_persons = [] | |
self.persons.each do |person| | |
#puts person.username | |
@tmp_persons << {:username => person.username, :list_count => 1, | |
:uri => "http://www.twitter.com/#{person.username}", :followers => person.followers_count, | |
:friends => person.friends_count} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Username,Followers,List Count,URI | |
aplusk,10137792,343,http://www.twitter.com/aplusk | |
JimCarrey,7159113,297,http://www.twitter.com/JimCarrey | |
tomhanks,3773553,288,http://www.twitter.com/tomhanks | |
ActuallyNPH,3061975,283,http://www.twitter.com/ActuallyNPH | |
NathanFillion,1222189,232,http://www.twitter.com/NathanFillion | |
RedHourBen,2655373,230,http://www.twitter.com/RedHourBen | |
peterfacinelli,1937513,215,http://www.twitter.com/peterfacinelli | |
Alyssa_Milano,2016472,214,http://www.twitter.com/Alyssa_Milano | |
KevinSpacey,2259294,210,http://www.twitter.com/KevinSpacey |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Username,Followers,List Count,URI | |
aplusk,9777167,83,http://www.twitter.com/aplusk | |
katyperry,16107303,80,http://www.twitter.com/katyperry | |
ladygaga,20799180,79,http://www.twitter.com/ladygaga | |
TheEllenShow,9922576,75,http://www.twitter.com/TheEllenShow | |
RyanSeacrest,6176522,73,http://www.twitter.com/RyanSeacrest | |
tomhanks,3587554,73,http://www.twitter.com/tomhanks | |
ActuallyNPH,2908961,68,http://www.twitter.com/ActuallyNPH | |
ConanOBrien,5213126,63,http://www.twitter.com/ConanOBrien | |
Oprah,10431484,62,http://www.twitter.com/Oprah |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Define how many list places should be considered | |
MAX = 200 | |
#Threshold: The threshold until which the categories should be merged (e.g. 0.2 = 20 % of members are shared) | |
THRESHOLD = 0.2 | |
outfile = CSV.open("data/partitions#{MAX}_#{THRESHOLD}.csv", "wb") | |
final_partition = CSV.open("data/final_partitions#{MAX}_#{THRESHOLD}.csv", "wb") | |
outfile << ["Name","Original Category", "Original Category Place", "Assigned Category", "Assigned Category Place", "Competing Categories", "Details"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
airlines_aviation | |
army_military_veteran | |
astronomy_physics | |
beauty_fashion_shopping | |
career_employment | |
charity_philanthropy | |
etsy_handmade | |
exercise_fitness | |
finance_economics | |
healthcare_medicine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Second step is to output the final partitions according to the ranking of the persons in their groups | |
seen_persons = [] | |
final_candidates = {} | |
seen_projects = [] | |
@@communities.each do |community| | |
project = Project.find(community) | |
if merged[project.name] == nil | |
project_members = members[project.name] | |
project_name = project.name | |
else |
OlderNewer