graphshaper 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/graphshaper +6 -4
- data/lib/graphshaper.rb +1 -0
- data/lib/graphshaper/adapters/avocadodb_adapter.rb +44 -0
- data/lib/graphshaper/version.rb +1 -1
- metadata +10 -9
data/bin/graphshaper
CHANGED
@@ -14,8 +14,10 @@ else
|
|
14
14
|
edge_output_file = File.new "edges.csv", "w"
|
15
15
|
logger = Graphshaper::LoggingAdapter.new vertex_output_file, edge_output_file
|
16
16
|
|
17
|
+
avocado_db = Graphshaper::AvocadoDbAdapter.new "vertices", "edges"
|
18
|
+
|
17
19
|
start_time = Time.now
|
18
|
-
graph = Graphshaper::UndirectedGraph.without_orphans_with_order_of inner_vertices, adapters: [logger]
|
20
|
+
graph = Graphshaper::UndirectedGraph.without_orphans_with_order_of inner_vertices, adapters: [logger, avocado_db]
|
19
21
|
(number_of_vertices - inner_vertices).times do
|
20
22
|
graph.add_vertex do |preferential_attachment|
|
21
23
|
preferential_attachment > rand
|
@@ -29,10 +31,10 @@ else
|
|
29
31
|
puts "#{graph.size} edges (saved to edges.csv)"
|
30
32
|
|
31
33
|
if ellapsed_time < 2
|
32
|
-
puts "Generated in about one second"
|
34
|
+
puts "Generated and saved in about one second"
|
33
35
|
elsif ellapsed_time < 60
|
34
|
-
puts "Generated in about #{ellapsed_time.round} seconds"
|
36
|
+
puts "Generated and saved in about #{ellapsed_time.round} seconds"
|
35
37
|
else
|
36
|
-
puts "Generated in about #{ellapsed_time.round / 60} minutes and #{ellapsed_time.round % 60} seconds"
|
38
|
+
puts "Generated and saved in about #{ellapsed_time.round / 60} minutes and #{ellapsed_time.round % 60} seconds"
|
37
39
|
end
|
38
40
|
end
|
data/lib/graphshaper.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module Graphshaper
|
4
|
+
class AvocadoDbAdapter
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
base_uri 'localhost:8529'
|
8
|
+
format :json
|
9
|
+
|
10
|
+
def initialize(vertex_collection_name, edge_collection_name)
|
11
|
+
@vertex_collection_name = vertex_collection_name
|
12
|
+
@edge_collection_name = edge_collection_name
|
13
|
+
@vertex_matching = []
|
14
|
+
@edge_matching = []
|
15
|
+
|
16
|
+
[@vertex_collection_name, @edge_collection_name].each { |collection| drop_and_create_collection collection}
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String] id in the database
|
20
|
+
def add_vertex(id)
|
21
|
+
cmd = "/document?collection=#{@vertex_collection_name}"
|
22
|
+
body = "{ \"id\" : \"#{id}\" }"
|
23
|
+
response = self.class.post(cmd, :body => body)
|
24
|
+
@vertex_matching[id] = response.parsed_response["_id"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_edge(edge_id, from, to)
|
28
|
+
database_id_for_first_node = @vertex_matching[from]
|
29
|
+
database_id_for_second_node = @vertex_matching[to]
|
30
|
+
|
31
|
+
cmd = "/edge?collection=#{@edge_collection_name}&from=#{database_id_for_first_node}&to=#{database_id_for_second_node}"
|
32
|
+
body = "{ \"id\" : \"#{edge_id}\" }"
|
33
|
+
response = self.class.post(cmd, :body => body)
|
34
|
+
@edge_matching[edge_id] = response.parsed_response["_id"]
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def drop_and_create_collection(name)
|
40
|
+
self.class.delete "/_api/collection/#{name}"
|
41
|
+
self.class.post "/_api/collection", body: "{ \"name\" : \"#{name}\"}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/graphshaper/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphshaper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-04 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70277557670180 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.8.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70277557670180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70277557669680 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.2.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70277557669680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70277557669220 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.9.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70277557669220
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: yard
|
49
|
-
requirement: &
|
49
|
+
requirement: &70277557668760 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 0.7.5
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70277557668760
|
58
58
|
description: Generate realistic graphs
|
59
59
|
email:
|
60
60
|
- me@moonglum.net
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- bin/graphshaper
|
73
73
|
- graphshaper.gemspec
|
74
74
|
- lib/graphshaper.rb
|
75
|
+
- lib/graphshaper/adapters/avocadodb_adapter.rb
|
75
76
|
- lib/graphshaper/adapters/logging_adapter.rb
|
76
77
|
- lib/graphshaper/undirected_graph.rb
|
77
78
|
- lib/graphshaper/version.rb
|