data_store 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +2 -1
- data/CHANGELOG.md +4 -0
- data/lib/data_store/table.rb +5 -3
- data/lib/data_store/version.rb +1 -1
- data/test/table_test.rb +14 -0
- metadata +4 -4
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/data_store/table.rb
CHANGED
@@ -28,12 +28,14 @@ module DataStore
|
|
28
28
|
# * created: timestamp
|
29
29
|
# * type: gauge or counter
|
30
30
|
# * table_index: in which compressed table
|
31
|
+
# * factor: multiply value with the given factor
|
31
32
|
def add(value, options = {})
|
32
33
|
created = options[:created] || Time.now.utc.to_f
|
33
34
|
type = options[:type] || parent.type
|
35
|
+
factor = options[:factor] || 1
|
34
36
|
original_idx = @table_index
|
35
37
|
@table_index = options[:table_index] if options[:table_index]
|
36
|
-
push(value, type, created)
|
38
|
+
push(value, type, created, factor)
|
37
39
|
@table_index = original_idx
|
38
40
|
end
|
39
41
|
|
@@ -88,9 +90,9 @@ module DataStore
|
|
88
90
|
parent.table_names[index]
|
89
91
|
end
|
90
92
|
|
91
|
-
def push(value, type, created)
|
93
|
+
def push(value, type, created, factor)
|
92
94
|
value = difference_with_previous(value) if type.to_s == 'counter'
|
93
|
-
datapoint = { value: value, created: created }
|
95
|
+
datapoint = { value: value * factor, created: created }
|
94
96
|
datapoint[:original_value] = original_value if original_value
|
95
97
|
database.transaction do
|
96
98
|
dataset << datapoint
|
data/lib/data_store/version.rb
CHANGED
data/test/table_test.rb
CHANGED
@@ -46,6 +46,20 @@ class TableTest < Test::Unit::TestCase
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
|
50
|
+
context 'adding datapoints with factor' do
|
51
|
+
|
52
|
+
setup do
|
53
|
+
@table.stubs(:calculate_average_values)
|
54
|
+
end
|
55
|
+
|
56
|
+
should 'return the last datapoint' do
|
57
|
+
@table.add(0.092345, factor: 1000)
|
58
|
+
assert_equal 92.345, @table.last.value
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
49
63
|
should 'Trigger the average calculator after adding a value' do
|
50
64
|
calculator = mock
|
51
65
|
#Need to use any_parameters instead of @table because of Celluloid
|
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.
|
4
|
+
version: 0.1.8
|
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-
|
12
|
+
date: 2013-04-25 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: -
|
81
|
+
hash: -1364652122039742087
|
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: -
|
90
|
+
hash: -1364652122039742087
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
93
|
rubygems_version: 1.8.25
|