-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate_edges.rb
104 lines (91 loc) · 3.32 KB
/
create_edges.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
100
101
102
103
104
require 'mongo'
require 'ruby-debug'
$db = Mongo::Connection.new("localhost", 27017)["crunch_profile"]
def get_person_edges(p)
return nil if !p["relationships"]
edges = p["relationships"].collect do |company|
next if !company["firm"] || !(permalink = company["firm"]["permalink"])
company = $db["companies"].find("permalink" => permalink).first
next if !company || !company["relationships"]
people = company["relationships"].collect do |person|
company_info = {"company" => {:image => company["image"], :name => company["name"], :homepage_url => company["homepage_url"], :permalink => company["permalink"]}}
if person["person"]["permalink"] != p["permalink"]
person["person"].merge(company_info)
else
nil
end
end.compact
end.flatten.compact
end
def graph_people
$db["people"].find().each do |p|
edges = get_person_edges(p)
p["edges"] = edges if edges
$db["people"].save(p)
=begin
next unless p["relationships"]
p["relationships"].each do |company|
if company["firm"] && (permalink = company["firm"]["permalink"])
company = $db["companies"].find("permalink" => permalink).first
if company && company["relationships"]
edges = company["relationships"].collect do |person|
company_info = {"company" => {:image => company["image"], :name => company["name"], :homepage_url => company["homepage_url"], :permalink => company["permalink"]}}
if person["permalink"] != permalink
person.merge(company_info)
else
nil
end
end
p["edges"] = edges
$db["people"].save(p)
end
end
end
=end
end
end
def get_company_edges(c)
return nil if !c["relationships"]
edges = c["relationships"].collect do |person|
next if !person["person"] || !(permalink = person["person"]["permalink"])
person = $db["people"].find({"permalink" => permalink}).first
next if !person || !person["relationships"]
edges = person["relationships"].collect do |company|
person_info = {"person" => {"image" => person["image"], "first_name" => person["first_name"], "last_name" => person["last_name"], "permalink" => person["permalink"]}}
if company["firm"]["permalink"] != c["permalink"]
company["firm"].merge(person_info)
else
nil
end
end.compact
end.flatten.compact
end
def graph_companies
$db["companies"].find().each do |c|
edges = get_company_edges(c)
c["edges"] = edges if edges
$db["companies"].save(c)
end
=begin
next unless c["relationships"]
c["relationships"].each do |person|
if person["person"] && (permalink = person["person"]["permalink"])
person = $db["people"].find("permalink" => permalink).first
if person && person["relationships"]
edges = person["relationships"].collect do |company|
person_info = {"person" => {:image => person["image"], :first_name => person["first_name"], :last_name => person["last_name"], :permalink => person["permalink"]}}
if company["permalink"] != permalink
company.merge(person_info)
else
nil
end
end
c["edges"] = edges
$db["companies"].save(c)
end
end
end
=end
end
#graph_people
graph_companies