-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.rb
99 lines (85 loc) · 2.32 KB
/
graph.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'rubygems'
require 'net/http'
require 'yaml'
require 'cgi'
require 'bossman'
include Java
include BOSSMan
jars = Dir['./lib/*.jar']
jars.each do |jar|
require jar
end
java_import Java::edu.uci.ics.jung.graph.DirectedSparseGraph
java_import Java::edu.uci.ics.jung.algorithms.importance.BetweennessCentrality
java_import Java::edu.uci.ics.jung.graph.util.EdgeType
$stdout.sync = true
BOSSMan.application_id = YAML.load_file("config.yml")['yahookey']
urls = []
location = ARGV[0]
if location == 'New York'
aggregated_locations = ['Brooklyn', 'New York', 'Queens']
else
aggregated_locations = [location]
end
aggregated_locations.each do |individual_location|
puts "Finding developers in #{individual_location}"
puts "---"
offset = 0
done = false
while !done
results = BOSSMan::Search.web('site:github.com location "' + individual_location + '" "profile - github"', :start => offset)
offset += results.count.to_i
if offset > results.totalhits.to_i
done = true
end
urls += results.results.map { |r| r.url }
end
end
puts "Getting social graph"
network = {}
Net::HTTP.start('github.com') { |http|
for line in urls
sleep 1
line.match(/github.com\/([a-zA-Z0-9-]+)/)
me = $1
if me.match(/^(.*)\/$/)
me = $1
end
url = "/api/v2/yaml/user/show/#{me}/followers"
puts url
req = Net::HTTP::Get.new(url)
response = http.request(req)
case response
when Net::HTTPSuccess
network[me] = []
for link in YAML.load(response.body)["users"]
network[me] << link
end
else
puts "non-200: #{me}"
end
end
}
puts 'Ranking results'
network_graph = DirectedSparseGraph.new
count = 0
network.each do |node|
user = node[0]
follows = node[1]
follows.each do |followed_user|
network_graph.addEdge(count, user, followed_user, EdgeType::DIRECTED)
count = count + 1
end
end
ranker = BetweennessCentrality.new(network_graph)
result = Hash.new
ranker.setRemoveRankScoresOnFinalize(false)
ranker.evaluate
network_graph.getVertices.each do |vertice|
result[vertice] = ranker.getVertexRankScore(vertice)
end
ranker = Java::Ranker.new
p ranker
for user in result.sort_by { |user,score| score }
puts "#{user[0]} = #{user[1]}"
end