pulse-meter 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ module PulseMeter
8
8
  include PulseMeter::Mixins::Utils
9
9
 
10
10
  MAX_TIMESPAN_POINTS = 1000
11
+ MAX_INTERVALS = 100
11
12
 
12
13
  # @!attribute [r] interval
13
14
  # @return [Fixnum] Rotation interval
@@ -82,12 +83,21 @@ module PulseMeter
82
83
 
83
84
  # Reduces data in all raw interval
84
85
  def reduce_all_raw
85
- min_time = Time.now - reduce_delay - interval
86
- redis.keys(raw_data_key('*')).each do |key|
87
- interval_id = key.split(':').last
88
- next if Time.at(interval_id.to_i) > min_time
89
- reduce(interval_id)
86
+ time = Time.now
87
+ min_time = time - reduce_delay - interval
88
+ max_depth = time - reduce_delay - interval * MAX_INTERVALS
89
+ ids = []
90
+ while (time > max_depth)
91
+ time -= interval
92
+ interval_id = get_interval_id(time)
93
+ next if Time.at(interval_id) > min_time
94
+
95
+ reduced_key = data_key(interval_id)
96
+ raw_key = raw_data_key(interval_id)
97
+ break if redis.exists(reduced_key)
98
+ ids << interval_id
90
99
  end
100
+ ids.reverse.each {|id| reduce(id)}
91
101
  end
92
102
 
93
103
  def self.reduce_all_raw
@@ -1,3 +1,3 @@
1
1
  module PulseMeter
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -6,8 +6,8 @@ shared_examples_for "timeline sensor" do |extra_init_values, default_event|
6
6
  end
7
7
 
8
8
  let(:name){ :some_value_with_history }
9
- let(:ttl){ 100 }
10
- let(:raw_data_ttl){ 30 }
9
+ let(:ttl){ 10000 }
10
+ let(:raw_data_ttl){ 3000 }
11
11
  let(:interval){ 5 }
12
12
  let(:reduce_delay){ 3 }
13
13
  let(:good_init_values){ {:ttl => ttl, :raw_data_ttl => raw_data_ttl, :interval => interval, :reduce_delay => reduce_delay}.merge(extra_init_values || {}) }
@@ -179,13 +179,29 @@ shared_examples_for "timeline sensor" do |extra_init_values, default_event|
179
179
  Timecop.freeze(@start_of_interval + interval){ sensor.event(sample_event) }
180
180
  val1 = sensor.summarize(@next_raw_data_key)
181
181
  expect{
182
- Timecop.freeze(@start_of_interval + interval + interval + reduce_delay + 1) { sensor.reduce_all_raw }
182
+ Timecop.freeze(@start_of_interval + interval + interval + reduce_delay + 1) do
183
+ sensor.reduce_all_raw
184
+ end
183
185
  }.to change{ redis.keys(sensor.raw_data_key('*')).count }.from(2).to(0)
184
186
 
185
187
  redis.get(sensor.data_key(@interval_id)).should == val0.to_s
186
188
  redis.get(sensor.data_key(@interval_id + interval)).should == val1.to_s
187
189
  end
188
190
 
191
+ it "creates up to MAX_INTERVALS compresed data pieces from previously uncompressed data" do
192
+ max_count = described_class::MAX_INTERVALS
193
+ start = @start_of_interval - reduce_delay - max_count * interval
194
+ (max_count + 100).times do |i|
195
+ Timecop.freeze(start + i * interval) {sensor.event(sample_event)}
196
+ end
197
+
198
+ Timecop.freeze(@start_of_interval) do
199
+ expect {
200
+ sensor.reduce_all_raw
201
+ }.to change {redis.keys(sensor.data_key('*')).count}.from(0).to(max_count)
202
+ end
203
+ end
204
+
189
205
  it "should not reduce fresh data" do
190
206
  Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
191
207
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pulse-meter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-17 00:00:00.000000000 Z
13
+ date: 2012-11-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gon-sinatra
@@ -585,9 +585,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
585
585
  - - ! '>='
586
586
  - !ruby/object:Gem::Version
587
587
  version: '0'
588
- segments:
589
- - 0
590
- hash: 2422587240922148030
591
588
  requirements: []
592
589
  rubyforge_project:
593
590
  rubygems_version: 1.8.23