data_store 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/.travis.yml +27 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +30 -0
- data/Guardfile +10 -0
- data/LICENSE +1 -1
- data/README.md +91 -2
- data/REMINDERS +8 -0
- data/Rakefile +13 -1
- data/config/database.yml +16 -0
- data/data_store.gemspec +1 -4
- data/db/data_store.db +0 -0
- data/lib/data_store/average_calculator.rb +93 -0
- data/lib/data_store/base.rb +108 -0
- data/lib/data_store/configuration.rb +66 -0
- data/lib/data_store/connector.rb +85 -0
- data/lib/data_store/definitions.rb +42 -0
- data/lib/data_store/table.rb +119 -0
- data/lib/data_store/version.rb +1 -1
- data/lib/data_store.rb +75 -1
- data/test/average_calculator_test.rb +196 -0
- data/test/configuration_test.rb +48 -0
- data/test/connector_test.rb +32 -0
- data/test/data_store_test.rb +117 -0
- data/test/integration_test.rb +66 -0
- data/test/table_test.rb +181 -0
- data/test/test_helper.rb +32 -0
- metadata +56 -66
data/test/table_test.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
require File.expand_path '../test_helper', __FILE__
|
2
|
+
|
3
|
+
class TableTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context 'DataStore::table general' do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
DataStore::Connector.new.reset!
|
9
|
+
@record = DataStore::Base.create(identifier: 1,
|
10
|
+
type: 'gauge',
|
11
|
+
name: 'Electra',
|
12
|
+
description: 'Actual usage of electra in the home',
|
13
|
+
compression_schema: [5,6,10])
|
14
|
+
@table = DataStore::Table.new(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'return the value of the identifier' do
|
18
|
+
assert_equal 1, @table.identifier
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'return the corresponding parent record' do
|
22
|
+
assert_equal true, @table.parent.is_a?(DataStore::Base)
|
23
|
+
assert_equal 1, @table.parent.identifier
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'adding datapoints' do
|
27
|
+
|
28
|
+
setup do
|
29
|
+
@table.stubs(:calculate_average_values)
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'add a datapoint to the table' do
|
33
|
+
@table.add(120.34)
|
34
|
+
assert_equal 1, @table.count
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'be able to add a datapoint to the table asynchronously' do
|
38
|
+
@table.add!(120.34)
|
39
|
+
assert_equal 1, @table.count
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'return the last datapoint' do
|
43
|
+
@table.add(120.34)
|
44
|
+
@table.add(120.38)
|
45
|
+
assert_equal 120.38, @table.last.value
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'return corresponding model' do
|
49
|
+
@table.add(123.45)
|
50
|
+
assert_equal 123.45, @table.model.find(value: 123.45).value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
should 'Trigger the average calculator after adding a value' do
|
55
|
+
calculator = mock
|
56
|
+
#Need to use any_parameters instead of @table because of Celluloid
|
57
|
+
DataStore::AverageCalculator.expects(:new).with(any_parameters).returns(calculator)
|
58
|
+
calculator.expects(:perform)
|
59
|
+
@table.add(120.34)
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'be able to import datapoints' do
|
63
|
+
@table.import([[100, 10], [120, 20], [130, 20]])
|
64
|
+
assert_equal 3, @table.model.db[:ds_1].count
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'fetch' do
|
68
|
+
setup do
|
69
|
+
@from = Time.now.utc.to_f - 3600
|
70
|
+
@till = Time.now.utc.to_f
|
71
|
+
|
72
|
+
@table.model.insert(value: 10, created: @from)
|
73
|
+
@table.model.insert(value: 11, created: @from + 10)
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'return the datapoints in a given time frame' do
|
77
|
+
assert_equal [10.0, 11.0], @table.fetch(:from => @from, :till => @till).map{|datapoint| datapoint[0]}
|
78
|
+
assert_equal [@from.round, (@from + 10).round], @table.fetch(:from => @from, :till => @till).map{|datapoint| datapoint[1].round}
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'return the datapoints from the corresponding time frame' do
|
82
|
+
time = Time.now.utc.to_f
|
83
|
+
|
84
|
+
#Extensive mocking, should we introduce Timeslot object for a more clean and simple test?
|
85
|
+
fourth_query = mock
|
86
|
+
fourth_query.stubs(:all).returns([])
|
87
|
+
third_query = mock
|
88
|
+
third_query.stubs(:order).returns(fourth_query)
|
89
|
+
second_query = mock
|
90
|
+
second_query.stubs(:where).returns(third_query)
|
91
|
+
first_query = mock
|
92
|
+
first_query.stubs(:where).returns(second_query)
|
93
|
+
|
94
|
+
@table.parent.db.expects('[]').with(:ds_1_5).returns(first_query)
|
95
|
+
@table.fetch(:from => time, :till => time + 8001)
|
96
|
+
|
97
|
+
@table.parent.db.expects('[]').with(:ds_1_30).returns(first_query)
|
98
|
+
@table.fetch(:from => time, :till => time + 40001)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'DataStore::table general' do
|
104
|
+
|
105
|
+
setup do
|
106
|
+
DataStore::Connector.new.reset!
|
107
|
+
@record = DataStore::Base.create(identifier: 1,
|
108
|
+
type: 'gauge',
|
109
|
+
name: 'Electra',
|
110
|
+
description: 'Actual usage of electra in the home',
|
111
|
+
compression_schema: [5,6,10])
|
112
|
+
|
113
|
+
@table = DataStore::Table.new(1, 1)
|
114
|
+
@table.stubs(:calculate_average_values)
|
115
|
+
end
|
116
|
+
|
117
|
+
should 'store a value in the compressed table' do
|
118
|
+
@table.add(12345.67)
|
119
|
+
assert_equal 12345.67, DataStore::Base.db[:ds_1_5].first[:value]
|
120
|
+
end
|
121
|
+
|
122
|
+
should 'store a value in the compressed table with the corresponding index' do
|
123
|
+
@table.add(765.432, table_index: 3)
|
124
|
+
assert_equal 765.432, DataStore::Base.db[:ds_1_300].first[:value]
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'with a counter type' do
|
130
|
+
|
131
|
+
setup do
|
132
|
+
@record = DataStore::Base.create(identifier: 2,
|
133
|
+
type: 'counter',
|
134
|
+
name: 'Gas',
|
135
|
+
description: 'Actual usage of natural gas',
|
136
|
+
compression_schema: [])
|
137
|
+
@table = DataStore::Table.new(2)
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'adding datapoints' do
|
141
|
+
|
142
|
+
setup do
|
143
|
+
@table.stubs(:calculate_average_values)
|
144
|
+
end
|
145
|
+
|
146
|
+
should 'add the original value as the first datapoint to the table' do
|
147
|
+
@table.add(120123)
|
148
|
+
assert_equal 120123, @table.last.value
|
149
|
+
end
|
150
|
+
|
151
|
+
should 'storing the difference between current and last value' do
|
152
|
+
@table.add(120125)
|
153
|
+
@table.add(120127)
|
154
|
+
@table.add(120129)
|
155
|
+
assert_equal 2, @table.last.value
|
156
|
+
end
|
157
|
+
|
158
|
+
should 'remove the very first record after more datapoints' do
|
159
|
+
#first record => [#< @values={:id=>1, :value=>120125.0, :original_value=>120125.0, :created=>1358023611.75022}>]
|
160
|
+
#So this will be removed in order to maintain a dataset with only 'difference' values
|
161
|
+
@table.add(120125)
|
162
|
+
|
163
|
+
@table.add(120127)
|
164
|
+
@table.add(120129)
|
165
|
+
|
166
|
+
assert_equal 2, @table.count
|
167
|
+
end
|
168
|
+
|
169
|
+
should 'add the difference when adding datapoints but store orginal value as well' do
|
170
|
+
@table.add(120125)
|
171
|
+
@table.add(120127)
|
172
|
+
assert_equal 120127, @table.last[:original_value] #original_value is not added as column to the Sequel model
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'mocha'
|
12
|
+
require 'shoulda'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
|
17
|
+
require 'data_store'
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
|
21
|
+
DataStore.configure do |config|
|
22
|
+
config.database = ENV['DB'] || :postgres
|
23
|
+
config.enable_logging = false
|
24
|
+
end
|
25
|
+
|
26
|
+
def time_now_utc_returns(value)
|
27
|
+
time = mock
|
28
|
+
Time.stubs(:now).returns(time)
|
29
|
+
time.stubs(:utc).returns(value)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
CHANGED
@@ -1,93 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_store
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Frank Oxener
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
name: shoulda
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
version: "0"
|
30
|
-
type: :development
|
31
|
-
version_requirements: *id001
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: rspec
|
34
|
-
prerelease: false
|
35
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - ">="
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
segments:
|
40
|
-
- 0
|
41
|
-
version: "0"
|
42
|
-
type: :development
|
43
|
-
version_requirements: *id002
|
44
|
-
description: DataStore is designed to store real time data but still manage the growth of your dataset and still keeping historical data
|
45
|
-
email:
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: DataStore is designed to store real time data but still manage the growth
|
15
|
+
of your dataset and still keeping historical data
|
16
|
+
email:
|
46
17
|
- frank.oxener@gmail.com
|
47
18
|
executables: []
|
48
|
-
|
49
19
|
extensions: []
|
50
|
-
|
51
20
|
extra_rdoc_files: []
|
52
|
-
|
53
|
-
files:
|
21
|
+
files:
|
54
22
|
- .gitignore
|
23
|
+
- .rvmrc
|
24
|
+
- .travis.yml
|
25
|
+
- CHANGELOG.md
|
55
26
|
- Gemfile
|
27
|
+
- Guardfile
|
56
28
|
- LICENSE
|
57
29
|
- README.md
|
30
|
+
- REMINDERS
|
58
31
|
- Rakefile
|
32
|
+
- config/database.yml
|
59
33
|
- data_store.gemspec
|
34
|
+
- db/data_store.db
|
60
35
|
- lib/data_store.rb
|
36
|
+
- lib/data_store/average_calculator.rb
|
37
|
+
- lib/data_store/base.rb
|
38
|
+
- lib/data_store/configuration.rb
|
39
|
+
- lib/data_store/connector.rb
|
40
|
+
- lib/data_store/definitions.rb
|
41
|
+
- lib/data_store/table.rb
|
61
42
|
- lib/data_store/version.rb
|
62
|
-
|
63
|
-
|
64
|
-
|
43
|
+
- test/average_calculator_test.rb
|
44
|
+
- test/configuration_test.rb
|
45
|
+
- test/connector_test.rb
|
46
|
+
- test/data_store_test.rb
|
47
|
+
- test/integration_test.rb
|
48
|
+
- test/table_test.rb
|
49
|
+
- test/test_helper.rb
|
50
|
+
homepage: https://github.com/dovadi/data_store
|
51
|
+
licenses:
|
65
52
|
- MIT
|
66
53
|
post_install_message:
|
67
54
|
rdoc_options: []
|
68
|
-
|
69
|
-
require_paths:
|
55
|
+
require_paths:
|
70
56
|
- lib
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
- 0
|
84
|
-
version: "0"
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
85
69
|
requirements: []
|
86
|
-
|
87
70
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.8.24
|
89
72
|
signing_key:
|
90
73
|
specification_version: 3
|
91
74
|
summary: DataStore for storing real time data
|
92
|
-
test_files:
|
93
|
-
|
75
|
+
test_files:
|
76
|
+
- test/average_calculator_test.rb
|
77
|
+
- test/configuration_test.rb
|
78
|
+
- test/connector_test.rb
|
79
|
+
- test/data_store_test.rb
|
80
|
+
- test/integration_test.rb
|
81
|
+
- test/table_test.rb
|
82
|
+
- test/test_helper.rb
|
83
|
+
has_rdoc:
|