pulse-meter 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pulse-meter/sensor/timeline.rb +20 -3
- data/lib/pulse-meter/version.rb +1 -1
- data/lib/pulse-meter/visualize/public/js/application.coffee +3 -1
- data/lib/pulse-meter/visualize/public/js/application.js +4 -2
- data/lib/pulse-meter/visualize/views/main.haml +5 -5
- data/spec/shared_examples/timeline_sensor.rb +9 -0
- metadata +2 -2
@@ -7,6 +7,8 @@ module PulseMeter
|
|
7
7
|
class Timeline < Base
|
8
8
|
include PulseMeter::Mixins::Utils
|
9
9
|
|
10
|
+
MAX_TIMESPAN_POINTS = 1000
|
11
|
+
|
10
12
|
# @!attribute [r] interval
|
11
13
|
# @return [Fixnum] Rotation interval
|
12
14
|
# @!attribute [r] ttl
|
@@ -109,13 +111,14 @@ module PulseMeter
|
|
109
111
|
def timeline_within(from, till)
|
110
112
|
raise ArgumentError unless from.kind_of?(Time) && till.kind_of?(Time)
|
111
113
|
start_time, end_time = from.to_i, till.to_i
|
112
|
-
|
114
|
+
actual_interval = optimized_inteval(start_time, end_time)
|
115
|
+
current_interval_id = get_interval_id(start_time) + actual_interval
|
113
116
|
keys = []
|
114
117
|
ids = []
|
115
118
|
while current_interval_id < end_time
|
116
119
|
ids << current_interval_id
|
117
120
|
keys << data_key(current_interval_id)
|
118
|
-
current_interval_id +=
|
121
|
+
current_interval_id += actual_interval
|
119
122
|
end
|
120
123
|
values = if keys.empty?
|
121
124
|
[]
|
@@ -133,7 +136,21 @@ module PulseMeter
|
|
133
136
|
res
|
134
137
|
end
|
135
138
|
|
136
|
-
#
|
139
|
+
# Makes interval optimization so that the requested timespan contains less than MAX_TIMESPAN_POINTS values
|
140
|
+
# @param start_time [Fixnum] unix timestamp of timespan start
|
141
|
+
# @param end_time [Fixnum] unix timestamp of timespan start
|
142
|
+
# @return [Fixnum] optimized interval in seconds.
|
143
|
+
def optimized_inteval(start_time, end_time)
|
144
|
+
res_interval = interval
|
145
|
+
timespan = end_time - start_time
|
146
|
+
while timespan / res_interval > MAX_TIMESPAN_POINTS - 1
|
147
|
+
res_interval *= 2
|
148
|
+
end
|
149
|
+
res_interval
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
# Returns sensor data for given interval making in-memory summarization
|
137
154
|
# and returns calculated value
|
138
155
|
# @param interval_id [Fixnum]
|
139
156
|
# @return [SensorData]
|
data/lib/pulse-meter/version.rb
CHANGED
@@ -108,6 +108,7 @@ $ ->
|
|
108
108
|
|
109
109
|
cutoff: (min, max) ->
|
110
110
|
_.each(@get('series'), (s) ->
|
111
|
+
console.log s.data.length
|
111
112
|
_.each( s.data, (v) ->
|
112
113
|
@cutoffValue(v, min, max)
|
113
114
|
, this)
|
@@ -212,7 +213,8 @@ $ ->
|
|
212
213
|
true
|
213
214
|
|
214
215
|
extendTimespan: ->
|
215
|
-
|
216
|
+
select = @$el.find("#extend-timespan-val")
|
217
|
+
val = select.first().val()
|
216
218
|
@model.increaseTimespan(parseInt(val))
|
217
219
|
|
218
220
|
resetTimespan: ->
|
@@ -111,6 +111,7 @@
|
|
111
111
|
},
|
112
112
|
cutoff: function(min, max) {
|
113
113
|
return _.each(this.get('series'), function(s) {
|
114
|
+
console.log(s.data.length);
|
114
115
|
return _.each(s.data, function(v) {
|
115
116
|
return this.cutoffValue(v, min, max);
|
116
117
|
}, this);
|
@@ -216,8 +217,9 @@
|
|
216
217
|
return true;
|
217
218
|
},
|
218
219
|
extendTimespan: function() {
|
219
|
-
var val;
|
220
|
-
|
220
|
+
var select, val;
|
221
|
+
select = this.$el.find("#extend-timespan-val");
|
222
|
+
val = select.first().val();
|
221
223
|
return this.model.increaseTimespan(parseInt(val));
|
222
224
|
},
|
223
225
|
resetTimespan: function() {
|
@@ -14,7 +14,7 @@
|
|
14
14
|
#plotarea
|
15
15
|
#chart-controls
|
16
16
|
.form-inline
|
17
|
-
%
|
17
|
+
%button#refresh.btn.btn-mini
|
18
18
|
%i.icon-refresh
|
19
19
|
Refresh
|
20
20
|
%span.space
|
@@ -32,9 +32,6 @@
|
|
32
32
|
<% if(type != 'pie'){ %>
|
33
33
|
%label
|
34
34
|
Timespan:
|
35
|
-
%span.btn.btn-mini#extend-timespan
|
36
|
-
%i.icon-arrow-left
|
37
|
-
Extend
|
38
35
|
%select#extend-timespan-val.btn-mini.span1
|
39
36
|
%option{value: 60, selected: true} 1 minute
|
40
37
|
%option{value: 60 * 5} 5 minutes
|
@@ -46,7 +43,10 @@
|
|
46
43
|
%option{value: 60 * 60 * 24 * 7} 1 week
|
47
44
|
%option{value: 60 * 60 * 24 * 7 * 2} 2 weeks
|
48
45
|
%option{value: 60 * 60 * 24 * 30} 1 month
|
49
|
-
%
|
46
|
+
%button#extend-timespan.btn.btn-mini
|
47
|
+
%i.icon-arrow-left
|
48
|
+
Extend
|
49
|
+
%button#reset-timespan.btn.btn-mini
|
50
50
|
%i.icon-arrow-right
|
51
51
|
Reset
|
52
52
|
<% } %>
|
@@ -202,6 +202,15 @@ shared_examples_for "timeline sensor" do |extra_init_values, default_event|
|
|
202
202
|
).size.should == 0
|
203
203
|
end
|
204
204
|
end
|
205
|
+
|
206
|
+
it "should not return more than #{PulseMeter::Sensor::Timeline::MAX_TIMESPAN_POINTS} points" do
|
207
|
+
max = PulseMeter::Sensor::Timeline::MAX_TIMESPAN_POINTS
|
208
|
+
(1..10).each do |i|
|
209
|
+
timespan = sensor.interval * max * (2**i)
|
210
|
+
sensor.timeline_within(Time.now, Time.now - timespan).size.should < max
|
211
|
+
|
212
|
+
end
|
213
|
+
end
|
205
214
|
end
|
206
215
|
|
207
216
|
describe "#timeline" do
|
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.1.
|
4
|
+
version: 0.1.6
|
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-06-
|
13
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gon-sinatra
|