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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a631ac1b673b24327126207b5898c6132a08f41f
4
- data.tar.gz: 2abdda7d7da624dace39c486381130a813c28e92
3
+ metadata.gz: 75b2bc30c49af7b08d577c827026747f15cbd445
4
+ data.tar.gz: 4cefc94a588e2f53b2b8a42d259eee98f10567f8
5
5
  SHA512:
6
- metadata.gz: 03eac42ce2d9216371065f46a2ab8ab0dc19a88b9270f59cdcd50496d771dc4852fd30f471514028b00da6ed1de71787c8767388c697158e21b73e0e625b636a
7
- data.tar.gz: 4baa8c0d598d1982442ee8c31a1e612939b5ae39c0167eb32eab25ebfa919c3a37523bb3a249a35f504d4bd67a08cdd65bdc76a2d9010846420ba7a3ab1fc265
6
+ metadata.gz: 17ccb9cc70e2e7f17b2b5d5ed944ab68ab88d7350bcbc9aad17205a37f120bee1c344aa499661b5481cf6b7e31451fb6d5a38e22e96a330e271f787a6b36e6be
7
+ data.tar.gz: c9dcd9ac5be891a80101230f09ba9ce250d61db2bdba25883a7648efb2034ea14285489f4272d312bcd2a8382d2b1f89f2a38bf6b733f6ca266adb06ebc27e9a
@@ -96,3 +96,9 @@
96
96
  ======
97
97
 
98
98
  * better exception message for an OutOfOrder exception
99
+
100
+ 0.0.16 (26 Aug 2013)
101
+ ======
102
+
103
+ * add Graph#from_unsorted_CSV_file (sorts in temp file)
104
+ * adds minimal delay (test_7 on 100K facts from 18.2 to 18.8 s)
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dbd
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -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
@@ -42,5 +42,7 @@ module Dbd
42
42
  lambda{ described_class.new(time: time_CET) }.should raise_error ArgumentError
43
43
  end
44
44
  end
45
+
46
+ #NOTE: for '+' and '-' see the comparisons_spec.rb
45
47
  end
46
48
  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.15
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-25 00:00:00.000000000 Z
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