Skip to content

Instantly share code, notes, and snippets.

View plotti's full-sized avatar

Thomas Ebermann plotti

View GitHub Profile
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()
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()
@plotti
plotti / gist:2895565
Created June 8, 2012 13:17
List collection function
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"]
@plotti
plotti / gist:2895615
Created June 8, 2012 13:29
Collect list members
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
@plotti
plotti / gist:2895661
Created June 8, 2012 13:40
Create Sorted lists
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
@plotti
plotti / gist:2895707
Created June 8, 2012 13:50
Sorted List output
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
@plotti
plotti / gist:2910941
Created June 11, 2012 16:12
List collected for the keyword hollywood
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
@plotti
plotti / gist:2910991
Created June 11, 2012 16:22
Smart interest groups matching
#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"]
@plotti
plotti / gist:2911079
Created June 11, 2012 16:29
Merged Categories
airlines_aviation
army_military_veteran
astronomy_physics
beauty_fashion_shopping
career_employment
charity_philanthropy
etsy_handmade
exercise_fitness
finance_economics
healthcare_medicine
@plotti
plotti / gist:2916063
Created June 12, 2012 08:02
Comparing the rankings of the members
#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