dbd 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.txt +6 -0
- data/bin/test_7.rb +27 -0
- data/lib/dbd/graph.rb +30 -1
- data/lib/dbd/version.rb +1 -1
- data/spec/lib/dbd/graph/from_csv_spec.rb +36 -0
- data/spec/lib/dbd/time_stamp/methods_spec.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b2bc30c49af7b08d577c827026747f15cbd445
|
4
|
+
data.tar.gz: 4cefc94a588e2f53b2b8a42d259eee98f10567f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17ccb9cc70e2e7f17b2b5d5ed944ab68ab88d7350bcbc9aad17205a37f120bee1c344aa499661b5481cf6b7e31451fb6d5a38e22e96a330e271f787a6b36e6be
|
7
|
+
data.tar.gz: c9dcd9ac5be891a80101230f09ba9ce250d61db2bdba25883a7648efb2034ea14285489f4272d312bcd2a8382d2b1f89f2a38bf6b733f6ca266adb06ebc27e9a
|
data/HISTORY.txt
CHANGED
data/bin/test_7.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This implementation streams from disk
|
4
|
+
#
|
5
|
+
# See test_5.rb for usage and basic performance test
|
6
|
+
|
7
|
+
filename = ARGV[0]
|
8
|
+
unless filename
|
9
|
+
puts "Give a 'filename' as argument."
|
10
|
+
exit(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'dbd'
|
14
|
+
|
15
|
+
start = Time.now
|
16
|
+
|
17
|
+
graph = Dbd::Graph.new.from_unsorted_CSV_file(filename)
|
18
|
+
|
19
|
+
puts "Graph is ready (took #{Time.now - start}s)."
|
20
|
+
|
21
|
+
puts "graph.size is #{graph.size}"
|
22
|
+
|
23
|
+
puts "first fact is:"
|
24
|
+
puts graph.first.string_values
|
25
|
+
|
26
|
+
puts "last fact is:"
|
27
|
+
puts graph.last.string_values
|
data/lib/dbd/graph.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'csv'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module Dbd
|
4
5
|
|
@@ -54,7 +55,9 @@ module Dbd
|
|
54
55
|
end
|
55
56
|
|
56
57
|
##
|
57
|
-
# Import a graph from a CSV IO stream
|
58
|
+
# Import a graph from a sorted CSV IO stream
|
59
|
+
#
|
60
|
+
# time_stamps need to be strictly monotonic increasing
|
58
61
|
#
|
59
62
|
# Tokens "backslash n" in the CSV fields will be unescaped to newlines.
|
60
63
|
# Tokens "double backslash" in the CSV fields will be unescaped to single backslash
|
@@ -68,6 +71,20 @@ module Dbd
|
|
68
71
|
self
|
69
72
|
end
|
70
73
|
|
74
|
+
##
|
75
|
+
# Import a graph from an unsorted CSV file (by filename)
|
76
|
+
#
|
77
|
+
# time_stamps need to be unique (but can be random order)
|
78
|
+
#
|
79
|
+
# Tokens "backslash n" in the CSV fields will be unescaped to newlines.
|
80
|
+
# Tokens "double backslash" in the CSV fields will be unescaped to single backslash
|
81
|
+
#
|
82
|
+
# @param [String] filename the filename of the unsorted CSV file
|
83
|
+
# @return [Graph] the imported graph
|
84
|
+
def from_unsorted_CSV_file(filename)
|
85
|
+
on_sorted_file(filename) { |sorted_file| from_CSV(sorted_file) }
|
86
|
+
end
|
87
|
+
|
71
88
|
private
|
72
89
|
|
73
90
|
##
|
@@ -89,5 +106,17 @@ module Dbd
|
|
89
106
|
end
|
90
107
|
end
|
91
108
|
|
109
|
+
def on_sorted_file(filename)
|
110
|
+
Tempfile.open('foo', 'data/') do |sorted_file|
|
111
|
+
create_sorted_file(filename, sorted_file)
|
112
|
+
yield(sorted_file)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def create_sorted_file(filename, sorted_file)
|
117
|
+
temp_name = sorted_file.path
|
118
|
+
`sort #{filename} > #{temp_name}`
|
119
|
+
end
|
120
|
+
|
92
121
|
end
|
93
122
|
end
|
data/lib/dbd/version.rb
CHANGED
@@ -96,7 +96,43 @@ module Dbd
|
|
96
96
|
csv = 'foo, bar'
|
97
97
|
lambda { described_class.new.from_CSV(csv) }.should raise_error IndexError
|
98
98
|
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#from_unsorted_CSV_file' do
|
102
|
+
|
103
|
+
let(:graph_context) { TestFactories::Graph.only_context }
|
104
|
+
let(:graph_facts) { TestFactories::Graph.only_facts(graph_context.first.subject) }
|
105
|
+
let(:graph_facts_csv) { graph_facts.to_CSV }
|
106
|
+
let(:inverted_graph_facts_csv) do
|
107
|
+
graph_facts_csv.split("\n").reverse.join("\n")
|
108
|
+
end
|
99
109
|
|
110
|
+
it "inverted_graph_facts_csv is really inverted" do
|
111
|
+
first_line = inverted_graph_facts_csv.split("\n").first
|
112
|
+
last_line = inverted_graph_facts_csv.split("\n").last
|
113
|
+
first_line.should > last_line
|
114
|
+
end
|
115
|
+
|
116
|
+
it "reads the inverted_graph" do
|
117
|
+
filename = 'data/reverse.csv'
|
118
|
+
File.open(filename, 'w') do |f|
|
119
|
+
f << inverted_graph_facts_csv
|
120
|
+
end
|
121
|
+
|
122
|
+
graph = Graph.new
|
123
|
+
graph.from_unsorted_CSV_file(filename)
|
124
|
+
graph.first.time_stamp.should < graph.last.time_stamp
|
125
|
+
end
|
126
|
+
|
127
|
+
it "returns a graph" do
|
128
|
+
filename = 'data/reverse.csv'
|
129
|
+
File.open(filename, 'w') do |f|
|
130
|
+
f << inverted_graph_facts_csv
|
131
|
+
end
|
132
|
+
|
133
|
+
graph = Graph.new
|
134
|
+
graph.from_unsorted_CSV_file(filename).should be_a(described_class)
|
135
|
+
end
|
100
136
|
end
|
101
137
|
end
|
102
138
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Vandenabeele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,6 +145,7 @@ executables:
|
|
145
145
|
- test_4.rb
|
146
146
|
- test_5.rb
|
147
147
|
- test_6.rb
|
148
|
+
- test_7.rb
|
148
149
|
extensions: []
|
149
150
|
extra_rdoc_files: []
|
150
151
|
files:
|
@@ -163,6 +164,7 @@ files:
|
|
163
164
|
- bin/test_4.rb
|
164
165
|
- bin/test_5.rb
|
165
166
|
- bin/test_6.rb
|
167
|
+
- bin/test_7.rb
|
166
168
|
- data/.gitkeep
|
167
169
|
- dbd.gemspec
|
168
170
|
- docs/rationale.md
|