data_store 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ##0.1.7
2
+
3
+ * BUG FIX: keep table_index unchanged during calculation of averages
4
+
1
5
  ##0.1.6
2
6
 
3
7
  * BUG FIX: calculate timeborders on local setttings instead of global settings
@@ -15,10 +15,10 @@ module DataStore
15
15
  DataStore::Base.find(identifier: identifier)
16
16
  end
17
17
 
18
- # Return a table object enriched with Sequel::Model behaviour
19
- def model
20
- @model ||= Class.new(Sequel::Model(dataset))
21
- end
18
+ # # Return a table object enriched with Sequel::Model behaviour
19
+ # def model
20
+ # Class.new(Sequel::Model(dataset))
21
+ # end
22
22
 
23
23
  # Add a new datapoint to the table
24
24
  # In case of a counter type, store the difference between current and last value
@@ -31,13 +31,19 @@ module DataStore
31
31
  def add(value, options = {})
32
32
  created = options[:created] || Time.now.utc.to_f
33
33
  type = options[:type] || parent.type
34
+ original_idx = @table_index
34
35
  @table_index = options[:table_index] if options[:table_index]
35
36
  push(value, type, created)
37
+ @table_index = original_idx
38
+ end
39
+
40
+ def model
41
+ @model ||= Class.new(Sequel::Model(dataset))
36
42
  end
37
43
 
38
44
  # Return the most recent datapoint added
39
45
  def last
40
- model.order(:created).last
46
+ model.last
41
47
  end
42
48
 
43
49
  # Return the total number of datapoints in the table
@@ -107,7 +113,7 @@ module DataStore
107
113
  end
108
114
 
109
115
  def database
110
- DataStore::Base.db
116
+ @database ||= DataStore::Base.db
111
117
  end
112
118
 
113
119
  def table_name
@@ -1,3 +1,3 @@
1
1
  module DataStore
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
@@ -30,8 +30,8 @@ class AverageCalculatorTest < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  should 'calculate the average value for the first' do
33
- @table.model.insert(value: 10, created: 0)
34
- @table.model.insert(value: 11, created: 10)
33
+ @table.dataset << {value: 10, created: 0}
34
+ @table.dataset << {value: 11, created: 10}
35
35
 
36
36
  @calculator.perform
37
37
  assert_equal 10.5, DataStore::Base.db[:ds_1_2].order(:created).last[:value]
@@ -41,15 +41,15 @@ class AverageCalculatorTest < Test::Unit::TestCase
41
41
  should 'calculate the average values' do
42
42
  time_now_utc_returns(10)
43
43
 
44
- @table.model.insert(value: 10, created: 0)
45
- @table.model.insert(value: 11, created: 10)
44
+ @table.dataset << {value: 10, created: 0}
45
+ @table.dataset << {value: 11, created: 10}
46
46
 
47
47
  @calculator.perform
48
48
 
49
- assert_equal 10.5, DataStore::Base.db[:ds_1_2].order(:created).first[:value]
49
+ assert_equal 10.5, DataStore::Base.db[:ds_1_2].order(:created).first[:value]
50
50
 
51
- @table.model.insert(value: 12, created: 20)
52
- @table.model.insert(value: 13, created: 30)
51
+ @table.dataset << {value: 12, created: 20}
52
+ @table.dataset << {value: 13, created: 30}
53
53
 
54
54
  time_now_utc_returns(30)
55
55
 
@@ -58,8 +58,8 @@ class AverageCalculatorTest < Test::Unit::TestCase
58
58
  assert_equal 12.5, DataStore::Base.db[:ds_1_2].order(:created).last[:value]
59
59
  assert_equal 11.5, DataStore::Base.db[:ds_1_4].order(:created).last[:value]
60
60
 
61
- @table.model.insert(value: 14, created: 40)
62
- @table.model.insert(value: 15, created: 50)
61
+ @table.dataset << {value: 14, created: 40}
62
+ @table.dataset << {value: 15, created: 50}
63
63
 
64
64
  time_now_utc_returns(50)
65
65
 
@@ -67,8 +67,8 @@ class AverageCalculatorTest < Test::Unit::TestCase
67
67
 
68
68
  assert_equal 14.5, DataStore::Base.db[:ds_1_2].order(:created).last[:value]
69
69
 
70
- @table.model.insert(value: 16, created: 60)
71
- @table.model.insert(value: 17, created: 70)
70
+ @table.dataset << {value: 16, created: 60}
71
+ @table.dataset << {value: 17, created: 70}
72
72
 
73
73
  time_now_utc_returns(70)
74
74
 
@@ -86,17 +86,17 @@ class AverageCalculatorTest < Test::Unit::TestCase
86
86
  should 'calculate the average values' do
87
87
  time_now_utc_returns(10)
88
88
 
89
- @table.model.insert(value: 10, created: 0)
90
- @table.model.insert(value: 11, created: 10)
89
+ @table.dataset << {value: 10, created: 0}
90
+ @table.dataset << {value: 11, created: 10}
91
91
 
92
92
  @calculator.perform
93
93
 
94
94
  assert_equal 10.5, DataStore::Base.db[:ds_1_2].order(:created).first[:value]
95
95
 
96
- @table.model.insert(value: 12, created: 20)
96
+ @table.dataset << {value: 12, created: 20}
97
97
 
98
98
  #No value at timestamp 30!
99
- @table.model.insert(value: 14, created: 40)
99
+ @table.dataset << {value: 14, created: 40}
100
100
 
101
101
  time_now_utc_returns(40)
102
102
 
@@ -105,8 +105,8 @@ class AverageCalculatorTest < Test::Unit::TestCase
105
105
  assert_equal 13.0, DataStore::Base.db[:ds_1_2].order(:created).last[:value]
106
106
  assert_equal 11.75, DataStore::Base.db[:ds_1_4].order(:created).last[:value]
107
107
 
108
- @table.model.insert(value: 15, created: 50)
109
- @table.model.insert(value: 16, created: 60)
108
+ @table.dataset << {value: 15, created: 50}
109
+ @table.dataset << {value: 16, created: 60}
110
110
 
111
111
  time_now_utc_returns(60)
112
112
 
@@ -114,8 +114,8 @@ class AverageCalculatorTest < Test::Unit::TestCase
114
114
 
115
115
  assert_equal 15.5, DataStore::Base.db[:ds_1_2].order(:created).last[:value]
116
116
 
117
- @table.model.insert(value: 17, created: 70)
118
- @table.model.insert(value: 18, created: 80)
117
+ @table.dataset << {value: 17, created: 70}
118
+ @table.dataset << {value: 18, created: 80}
119
119
 
120
120
  time_now_utc_returns(80)
121
121
 
@@ -156,8 +156,8 @@ class AverageCalculatorTest < Test::Unit::TestCase
156
156
  end
157
157
 
158
158
  should 'calculate the average value' do
159
- @table.model.insert(value: 10, original_value: 1010, created: 10)
160
- @table.model.insert(value: 10, original_value: 1020, created: 20)
159
+ @table.dataset << {value: 10, original_value: 1010, created: 10}
160
+ @table.dataset << {value: 10, original_value: 1020, created: 20}
161
161
 
162
162
  @calculator.perform
163
163
 
@@ -165,14 +165,14 @@ class AverageCalculatorTest < Test::Unit::TestCase
165
165
  end
166
166
 
167
167
  should 'calculate the average values according to compression_schema' do
168
- @table.model.insert(value: 10, original_value: 1010, created: 10)
169
- @table.model.insert(value: 10, original_value: 1020, created: 20)
168
+ @table.dataset << {value: 10, original_value: 1010, created: 10}
169
+ @table.dataset << {value: 10, original_value: 1020, created: 20}
170
170
 
171
171
  time_now_utc_returns(20)
172
172
  @calculator.perform
173
173
 
174
- @table.model.insert(value: 20, original_value: 1040, created: 30)
175
- @table.model.insert(value: 30, original_value: 1070, created: 40)
174
+ @table.dataset << {value: 20, original_value: 1040, created: 30}
175
+ @table.dataset << {value: 30, original_value: 1070, created: 40}
176
176
 
177
177
  time_now_utc_returns(40)
178
178
  @calculator.perform
@@ -183,8 +183,8 @@ class AverageCalculatorTest < Test::Unit::TestCase
183
183
  end
184
184
 
185
185
  should 'calculate the average value by ignoring the original values' do
186
- @table.model.insert(value: 20, original_value: 12345, created: 10)
187
- @table.model.insert(value: 30, original_value: 67890, created: 20)
186
+ @table.dataset << {value: 20, original_value: 12345, created: 10}
187
+ @table.dataset << {value: 30, original_value: 67890, created: 20}
188
188
 
189
189
  @calculator.perform
190
190
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-13 00:00:00.000000000 Z
12
+ date: 2013-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  segments:
80
80
  - 0
81
- hash: -1644989345688288543
81
+ hash: -4573179353281624558
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  segments:
89
89
  - 0
90
- hash: -1644989345688288543
90
+ hash: -4573179353281624558
91
91
  requirements: []
92
92
  rubyforge_project:
93
93
  rubygems_version: 1.8.25