chawk 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/.pryrc +15 -3
- data/CHANGES +8 -1
- data/README.md +86 -61
- data/chawk.gemspec +3 -1
- data/lib/chawk/migration.rb +21 -0
- data/lib/chawk/version.rb +1 -1
- data/lib/chawk.rb +39 -19
- data/lib/models.rb +10 -150
- data/lib/node.rb +313 -0
- data/lib/range.rb +70 -0
- data/test/lib/addr_test.rb +63 -33
- data/test/lib/failed_node_test.rb +2 -2
- data/test/lib/paddr_test.rb +162 -186
- data/test/lib/range_test.rb +61 -0
- data/test/lib/vaddr_test.rb +130 -160
- data/test/schema.rb +23 -0
- data/test/test_helper.rb +9 -2
- metadata +6 -16
data/test/lib/paddr_test.rb
CHANGED
@@ -2,274 +2,250 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
describe Chawk do
|
4
4
|
before do
|
5
|
-
|
5
|
+
Chawk.clear_all_data!
|
6
6
|
@agent = Chawk::Models::Agent.first || Chawk::Models::Agent.create(:name=>"Test User")
|
7
|
-
@
|
8
|
-
@addr.points.destroy_all
|
7
|
+
@node = Chawk.node(@agent,'a:b')
|
9
8
|
end
|
10
9
|
|
11
10
|
it "has length" do
|
12
|
-
@
|
11
|
+
@node.points.must_respond_to(:length)
|
13
12
|
end
|
14
13
|
|
15
14
|
it "calculates length" do
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
@node.clear_points!
|
16
|
+
@node.points.length.must_equal(0)
|
17
|
+
@node.add_points 2
|
18
|
+
@node.points.length.must_equal(1)
|
19
|
+
@node.add_points 2
|
20
|
+
@node.points.length.must_equal(2)
|
21
|
+
@node.add_points 2
|
22
|
+
@node.points.length.must_equal(3)
|
23
|
+
@node.add_points [1,2,3,4]
|
24
|
+
@node.points.length.must_equal(7)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "clears points" do
|
28
|
+
@node.must_respond_to(:clear_points!)
|
29
|
+
end
|
31
30
|
|
32
31
|
it "clears history" do
|
33
|
-
|
34
|
-
@
|
35
|
-
|
36
|
-
@
|
32
|
+
@node.add_points [1,2,3,4]
|
33
|
+
@node.points.length.must_equal(4)
|
34
|
+
@node.clear_points!
|
35
|
+
@node.points.length.must_equal(0)
|
37
36
|
end
|
38
37
|
|
39
38
|
it "doesn't clear the wrong history" do
|
40
|
-
|
41
|
-
|
42
|
-
@
|
43
|
-
|
44
|
-
@
|
45
|
-
|
46
|
-
|
47
|
-
@
|
39
|
+
node2 = Chawk.node(@agent,'a:b')
|
40
|
+
node2.clear_points!
|
41
|
+
@node.clear_points!
|
42
|
+
node2.add_points [1,2,3,4]
|
43
|
+
@node.add_points [1,2,3,4]
|
44
|
+
node2.clear_points!
|
45
|
+
node2.points.length.must_equal(0)
|
46
|
+
@node.points.length.must_equal(4)
|
48
47
|
end
|
49
48
|
|
50
49
|
it "accepts _insert_point" do
|
51
|
-
@
|
52
|
-
@
|
50
|
+
@node._insert_point(100,Time.now)
|
51
|
+
@node.points.length.must_equal(1)
|
53
52
|
end
|
54
53
|
|
55
54
|
it "accepts add_points" do
|
56
|
-
@
|
55
|
+
@node.must_respond_to(:"add_points")
|
57
56
|
end
|
58
57
|
|
59
58
|
it "accepts integers" do
|
60
|
-
@
|
61
|
-
@
|
62
|
-
@
|
63
|
-
@
|
64
|
-
@
|
65
|
-
@
|
66
|
-
@
|
59
|
+
@node.add_points 10
|
60
|
+
@node.points.length.must_equal(1)
|
61
|
+
@node.add_points 0
|
62
|
+
@node.points.length.must_equal(2)
|
63
|
+
@node.add_points 190
|
64
|
+
@node.add_points 10002
|
65
|
+
@node.add_points [10,0,190,100]
|
67
66
|
dt = Time.now.to_f
|
68
|
-
@
|
69
|
-
@
|
70
|
-
@
|
71
|
-
@
|
67
|
+
@node.add_points [[10,dt],[0,dt],[190,dt],[100,dt]]
|
68
|
+
@node.add_points [{"v"=>10},{"v"=>0},{"v"=>190},{"v"=>100,"t"=>dt}]
|
69
|
+
@node.add_points [{"v"=>10,"t"=>dt},{"v"=>0,"t"=>dt},{"v"=>190,"t"=>dt},{"v"=>100,"t"=>dt}]
|
70
|
+
@node.add_points [{"t"=>dt,"v"=>10},{"v"=>0,"t"=>dt},{"t"=>dt,"v"=>190},{"v"=>100,"t"=>dt}]
|
72
71
|
end
|
73
72
|
|
74
73
|
it "does increment" do
|
75
|
-
@
|
76
|
-
@
|
77
|
-
@
|
78
|
-
@
|
79
|
-
@
|
80
|
-
@
|
81
|
-
@
|
82
|
-
@
|
83
|
-
@
|
84
|
-
@
|
74
|
+
@node.clear_points!
|
75
|
+
@node.add_points 99
|
76
|
+
@node.must_respond_to(:increment)
|
77
|
+
@node.increment 10
|
78
|
+
@node.increment
|
79
|
+
@node.points.last.value.must_equal(110)
|
80
|
+
@node.increment -10
|
81
|
+
@node.points.last.value.must_equal(100)
|
82
|
+
@node.increment
|
83
|
+
@node.points.last.value.must_equal(101)
|
85
84
|
end
|
86
85
|
|
87
86
|
it "should only increment integers" do
|
88
|
-
lambda {@
|
89
|
-
lambda {@
|
87
|
+
lambda {@node.increment 'A'}.must_raise(ArgumentError)
|
88
|
+
lambda {@node.increment nil}.must_raise(ArgumentError)
|
90
89
|
end
|
91
90
|
|
92
91
|
it "does -" do
|
93
|
-
@
|
94
|
-
@
|
95
|
-
@
|
96
|
-
@
|
97
|
-
@
|
98
|
-
@
|
99
|
-
@
|
100
|
-
@
|
92
|
+
@node.points.must_respond_to(:"-")
|
93
|
+
@node.add_points 10
|
94
|
+
@node.decrement 100
|
95
|
+
@node.points.last.value.must_equal(-90)
|
96
|
+
@node.decrement -10
|
97
|
+
@node.points.last.value.must_equal(-80)
|
98
|
+
@node.decrement
|
99
|
+
@node.points.last.value.must_equal(-81)
|
101
100
|
end
|
102
101
|
|
103
102
|
it "should only - integers" do
|
104
|
-
lambda {@
|
105
|
-
lambda {@
|
103
|
+
lambda {@node.decrement 'A'}.must_raise(ArgumentError)
|
104
|
+
lambda {@node.decrement nil}.must_raise(ArgumentError)
|
106
105
|
end
|
107
106
|
|
108
107
|
it "only accepts integers in proper formats" do
|
109
|
-
lambda {@
|
110
|
-
lambda {@
|
111
|
-
lambda {@
|
112
|
-
lambda {@
|
108
|
+
lambda {@node.add_points 10.0}.must_raise(ArgumentError)
|
109
|
+
lambda {@node.add_points nil}.must_raise(ArgumentError)
|
110
|
+
lambda {@node.add_points [10.0,:x]}.must_raise(ArgumentError)
|
111
|
+
lambda {@node.add_points [[10,10,10],[10,10,20]]}.must_raise(ArgumentError)
|
113
112
|
dt = Time.now.to_f
|
114
|
-
lambda {@
|
113
|
+
lambda {@node.add_points [{"x"=>10,"t"=>dt},{"x"=>0,"t"=>dt}]}.must_raise(ArgumentError)
|
115
114
|
end
|
116
115
|
|
117
116
|
it "accepts string integers in proper formats" do
|
118
|
-
lambda {@
|
119
|
-
@
|
120
|
-
@
|
121
|
-
@
|
122
|
-
@
|
123
|
-
@
|
124
|
-
@
|
125
|
-
@
|
126
|
-
@
|
117
|
+
lambda {@node.add_points "X"}.must_raise(ArgumentError)
|
118
|
+
@node.add_points "10"
|
119
|
+
@node.points.length.must_equal(1)
|
120
|
+
@node.add_points "0"
|
121
|
+
@node.points.length.must_equal(2)
|
122
|
+
@node.add_points "190"
|
123
|
+
@node.add_points "10002"
|
124
|
+
@node.add_points ["10","0","190","100"]
|
125
|
+
@node.points.length.must_equal(8)
|
127
126
|
end
|
128
127
|
|
129
128
|
it "does bulk add points" do
|
130
129
|
dt = Time.now.to_f
|
131
130
|
Chawk.bulk_add_points(@agent, {"xxx"=>[1,2,3,4,5,6], "yyy"=>[[10,dt],[10,dt]], "zzz"=>[{"t"=>dt,"v"=>10},{"v"=>0,"t"=>dt}]})
|
132
131
|
|
133
|
-
Chawk.
|
134
|
-
Chawk.
|
135
|
-
Chawk.
|
132
|
+
Chawk.node(@agent,"xxx").points.length.must_equal 6
|
133
|
+
Chawk.node(@agent,"zzz").points.length.must_equal 2
|
134
|
+
Chawk.node(@agent,"zzz").points.last.value.must_equal 0
|
136
135
|
|
137
136
|
end
|
138
137
|
|
139
138
|
it "has last()" do
|
140
|
-
@
|
139
|
+
@node.points.must_respond_to(:last)
|
141
140
|
end
|
142
141
|
|
143
142
|
it "remembers last value" do
|
144
|
-
@
|
145
|
-
@
|
146
|
-
@
|
147
|
-
@
|
148
|
-
@
|
149
|
-
@
|
150
|
-
@
|
151
|
-
@
|
143
|
+
@node.add_points 10
|
144
|
+
@node.points.last.value.must_equal(10)
|
145
|
+
@node.add_points 1000
|
146
|
+
@node.points.last.value.must_equal(1000)
|
147
|
+
@node.add_points 99
|
148
|
+
@node.points.last.value.must_equal(99)
|
149
|
+
@node.add_points [10,0,190,100]
|
150
|
+
@node.points.last.value.must_equal(100)
|
152
151
|
end
|
153
152
|
|
154
153
|
it "stores meta information" do
|
155
154
|
|
156
155
|
metadata = {"info"=>"this is a test"}
|
157
|
-
@
|
158
|
-
@
|
159
|
-
|
156
|
+
@node.add_points([1,2,3,4],{:meta=>metadata})
|
157
|
+
@node.points.last.value.must_equal(4)
|
158
|
+
meta = @node.points.last.meta
|
159
|
+
JSON.parse(meta).must_equal(metadata)
|
160
160
|
|
161
161
|
metadata = {"number"=>123}
|
162
|
-
@
|
163
|
-
@
|
164
|
-
JSON.parse(@
|
162
|
+
@node.add_points([1,2,3,4],{:meta=>metadata})
|
163
|
+
@node.points.last.value.must_equal(4)
|
164
|
+
JSON.parse(@node.points.last.meta).must_equal(metadata)
|
165
|
+
|
166
|
+
metadata = ["completely wrong"]
|
167
|
+
lambda {@node.add_points([1,2,3,4],{:meta=>metadata})}.must_raise(ArgumentError)
|
165
168
|
|
166
169
|
end
|
167
170
|
|
168
171
|
|
169
172
|
it "returns ordinal last" do
|
170
|
-
@
|
171
|
-
@
|
173
|
+
@node.add_points [10,9,8,7,6,5,4,3,2,1,0]
|
174
|
+
@node.points.last(5).length.must_equal(5)
|
172
175
|
end
|
173
176
|
|
174
|
-
it "has max()" do
|
175
|
-
|
176
|
-
end
|
177
|
+
# it "has max()" do
|
178
|
+
# @node.must_respond_to(:max)
|
179
|
+
# end
|
177
180
|
|
178
|
-
it "does max()" do
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
181
|
+
# it "does max()" do
|
182
|
+
# @node.clear_points!
|
183
|
+
# @node.add_points [1,2,3,4,5]
|
184
|
+
# @node.max.must_equal(5)
|
185
|
+
# @node.add_points 100
|
186
|
+
# @node.max.must_equal(100)
|
187
|
+
# @node.add_points 100
|
188
|
+
# @node.max.must_equal(100)
|
189
|
+
# @node.add_points 99
|
190
|
+
# @node.max.must_equal(100)
|
191
|
+
# @node.add_points 0
|
192
|
+
# @node.max.must_equal(100)
|
193
|
+
# end
|
191
194
|
|
192
|
-
it "does min()" do
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
end
|
195
|
+
# it "does min()" do
|
196
|
+
# @node.add_points [11,12,13,14,15]
|
197
|
+
# @node.min.must_equal(11)
|
198
|
+
# @node.add_points 100
|
199
|
+
# @node.min.must_equal(11)
|
200
|
+
# @node.add_points 10
|
201
|
+
# @node.min.must_equal(10)
|
202
|
+
# @node.add_points 99
|
203
|
+
# @node.min.must_equal(10)
|
204
|
+
# @node.add_points 0
|
205
|
+
# @node.min.must_equal(0)
|
206
|
+
# end
|
204
207
|
|
205
208
|
it :does_range do
|
206
|
-
@
|
209
|
+
@node.must_respond_to(:points_range)
|
207
210
|
|
208
211
|
ts = Time.now
|
209
212
|
|
210
|
-
@
|
211
|
-
@
|
212
|
-
@
|
213
|
-
@
|
214
|
-
@
|
215
|
-
@
|
216
|
-
@
|
217
|
-
@
|
218
|
-
@
|
219
|
-
@
|
220
|
-
@
|
221
|
-
@
|
222
|
-
@
|
223
|
-
@
|
224
|
-
@
|
225
|
-
@
|
226
|
-
@
|
227
|
-
@
|
228
|
-
|
229
|
-
@
|
230
|
-
@
|
213
|
+
@node._insert_point(0,ts-1000)
|
214
|
+
@node._insert_point(1,ts-1000)
|
215
|
+
@node._insert_point(2,ts-1000)
|
216
|
+
@node._insert_point(3,ts-1000)
|
217
|
+
@node._insert_point(4,ts-1000)
|
218
|
+
@node._insert_point(5,ts-800)
|
219
|
+
@node._insert_point(6,ts-800)
|
220
|
+
@node._insert_point(7,ts-800)
|
221
|
+
@node._insert_point(8,ts-200)
|
222
|
+
@node._insert_point(9,ts-10)
|
223
|
+
@node._insert_point(10,ts-5)
|
224
|
+
@node.points_range(ts-1001,ts).length.must_equal 11
|
225
|
+
@node.points_range(ts-801,ts).length.must_equal 6
|
226
|
+
@node.points_range(ts-201,ts).length.must_equal 3
|
227
|
+
@node.points_range(ts-11,ts).length.must_equal 2
|
228
|
+
@node.points_range(ts-6,ts).length.must_equal 1
|
229
|
+
@node.points_range(ts-201,ts-11).length.must_equal 1
|
230
|
+
@node.points_range(ts-1001,ts-999).length.must_equal 5
|
231
|
+
|
232
|
+
@node._insert_point(0,ts-101)
|
233
|
+
@node.points_range(ts-201,ts).length.must_equal 4
|
231
234
|
end
|
232
235
|
|
233
236
|
it "does since" do
|
234
|
-
@
|
237
|
+
@node.clear_points!
|
235
238
|
|
236
239
|
|
237
240
|
ts = Time.now
|
238
241
|
|
239
|
-
@
|
240
|
-
@
|
241
|
-
@
|
242
|
-
@
|
243
|
-
@
|
244
|
-
@
|
245
|
-
@
|
242
|
+
@node._insert_point(0,ts-1000)
|
243
|
+
@node._insert_point(7,ts-800)
|
244
|
+
@node._insert_point(8,ts-200)
|
245
|
+
@node._insert_point(10,ts-5)
|
246
|
+
@node.must_respond_to(:points_since)
|
247
|
+
@node.points_since(ts-1001).length.must_equal(4)
|
248
|
+
@node.points_since(ts-301).length.must_equal(2)
|
246
249
|
end
|
247
250
|
|
248
|
-
# it :acts_like_an_integer do
|
249
|
-
# @addr.add_points 36878
|
250
|
-
# last = @addr.points.last
|
251
|
-
# last.to_i.must_equal 36878
|
252
|
-
# end
|
253
|
-
|
254
|
-
# it "does mq" do
|
255
|
-
# @board.flush_notification_queue
|
256
|
-
# @board.notification_queue_length.must_equal (0)
|
257
|
-
|
258
|
-
# pointers = []
|
259
|
-
# pointers add_points @board.paddr(['0','1','2'])
|
260
|
-
# pointers add_points @board.paddr(['0','1','3'])
|
261
|
-
# pointers add_points @board.paddr(['0','1','4'])
|
262
|
-
# pointers add_points @board.paddr(['0','1','5'])
|
263
|
-
|
264
|
-
# pointers.each{|p|padd_points10}
|
265
|
-
|
266
|
-
# @board.notification_queue_length.must_equal (4)
|
267
|
-
# x = @board.pop_from_notification_queue
|
268
|
-
# x.length.must_equal(3)
|
269
|
-
# @board.notification_queue_length.must_equal (3)
|
270
|
-
# x = @board.pop_from_notification_queue
|
271
|
-
# x = @board.pop_from_notification_queue
|
272
|
-
# @board.notification_queue_length.must_equal (1)
|
273
|
-
# x.length.must_equal(3)
|
274
|
-
# end
|
275
251
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Chawk do
|
4
|
+
before do
|
5
|
+
Chawk.clear_all_data!
|
6
|
+
@agent = Chawk::Models::Agent.first || Chawk::Models::Agent.create(:name=>"Test User")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "obeys the order" do
|
10
|
+
node1 = Chawk.node(@agent,'a:b')
|
11
|
+
Chawk::Models::Range.new(start_ts:1140.0,stop_ts:1085.0,beats:1,parent_node:node1).save.must_equal false
|
12
|
+
Chawk::Models::Range.new(start_ts:1140.0,stop_ts:1140.0,beats:1,parent_node:node1).save.must_equal false
|
13
|
+
Chawk::Models::Range.new(start_ts:1000.0,stop_ts:1140.0,beats:1,parent_node:node1).save.must_equal true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "calculates range" do
|
17
|
+
node1 = Chawk.node(@agent,'a:b')
|
18
|
+
node1.clear_points!
|
19
|
+
|
20
|
+
range = Chawk::Models::Range.create(start_ts:1085.0,stop_ts:1140.0,beats:1,parent_node:node1)
|
21
|
+
ag = Chawk::Models::NodeAggregator.new(range.data_node)
|
22
|
+
ag.sum.must_equal(0)
|
23
|
+
ag.mean.round(2).must_equal(0.0)
|
24
|
+
|
25
|
+
|
26
|
+
node1._insert_point(92,1085.2340175364745)
|
27
|
+
node1._insert_point(94,1100.0643872093362)
|
28
|
+
node1._insert_point(92,1102.3558603493182)
|
29
|
+
node1._insert_point(94,1119.2568446818536)
|
30
|
+
node1._insert_point(91,1125.283357089852)
|
31
|
+
node1._insert_point(91,1131.9783343810343)
|
32
|
+
node1._insert_point(88,1132.299788479544)
|
33
|
+
|
34
|
+
range = Chawk::Models::Range.create(start_ts:1085.0,stop_ts:1140.0,beats:1,parent_node:node1)
|
35
|
+
|
36
|
+
range.data_node.points.length.must_equal(220)
|
37
|
+
range.data_node.points[25].value.must_equal(92)
|
38
|
+
range.data_node.points[140].value.must_equal(94)
|
39
|
+
ag = Chawk::Models::NodeAggregator.new(range.data_node)
|
40
|
+
ag.sum.must_equal(20066)
|
41
|
+
ag.mean.round(2).must_equal(91.21)
|
42
|
+
|
43
|
+
node1.add_points [{'v'=>1500, 't'=>1135.0}] #invalidate range and rebuild
|
44
|
+
|
45
|
+
range.reload
|
46
|
+
range.data_node.points[200].value.must_equal(1500)
|
47
|
+
ag = Chawk::Models::NodeAggregator.new(range.data_node)
|
48
|
+
ag.sum.must_equal(48306)
|
49
|
+
ag.max.must_equal(1500)
|
50
|
+
ag.min.must_equal(0)
|
51
|
+
|
52
|
+
range = Chawk::Models::Range.create(start_ts:1088.0,stop_ts:8100.0,beats:14400,parent_node:node1)
|
53
|
+
range.data_node.points.length.must_equal(2)
|
54
|
+
|
55
|
+
ag = Chawk::Models::NodeAggregator.new(range.data_node)
|
56
|
+
ag.sum.must_equal(1592)
|
57
|
+
ag.mean.must_equal(796)
|
58
|
+
ag.stdev.round(2).must_equal(995.61)
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|