rbbt-util 5.18.0 → 5.18.1
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/lib/rbbt/util/misc/inspect.rb +69 -0
- data/lib/rbbt/workflow/accessor.rb +1 -2
- data/test/rbbt/util/test_misc.rb +46 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f4bb8ad71b9080b39bc7217d9f4a5dc0da2719d
|
4
|
+
data.tar.gz: 94b7dfcbd524c888c73f945cf95e223b318205a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17e4da0d2455c8c93de87d51b4166b2156552611c3bafc17ce561fcb6d278e3ad16df23ece0727fea9a783c66d97b528e889246cd5da51a183ba368ba8c7ecff
|
7
|
+
data.tar.gz: 2c981aee80405b0d9794c4568114da6c3d2916f1fac755357f081566ad9d40c17346d5fe14c3388cb66f3a490ede94ab261bb1cb5e2d79cc0f51584d8fbd7b23
|
@@ -113,6 +113,18 @@ module Misc
|
|
113
113
|
Digest::MD5.hexdigest(text)
|
114
114
|
end
|
115
115
|
|
116
|
+
def self.sample_large_obj(obj, max = 100)
|
117
|
+
length = obj.length
|
118
|
+
head = obj[0..max/2]
|
119
|
+
tail = obj[-max/2..-1]
|
120
|
+
middle = (1..9).to_a.collect{|i| pos = (length / 10) * i + i; obj[pos-1..pos+1]}.flatten
|
121
|
+
if Array === obj
|
122
|
+
head + middle + tail + ["LENGTH: #{obj.length}"]
|
123
|
+
else
|
124
|
+
head << "..." << middle*"," << "..." << tail << "(#{obj.length})"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
116
128
|
HASH2MD5_MAX_STRING_LENGTH = 1000
|
117
129
|
HASH2MD5_MAX_ARRAY_LENGTH = 100
|
118
130
|
def self.hash2md5(hash)
|
@@ -184,4 +196,61 @@ module Misc
|
|
184
196
|
end
|
185
197
|
end
|
186
198
|
|
199
|
+
|
200
|
+
def self.obj2str(obj)
|
201
|
+
_obj = obj
|
202
|
+
obj = Annotated.purge(obj) if Annotated === obj
|
203
|
+
|
204
|
+
str = case obj
|
205
|
+
when TrueClass
|
206
|
+
'true'
|
207
|
+
when FalseClass
|
208
|
+
'false'
|
209
|
+
when Hash
|
210
|
+
"{"<< obj.collect{|k,v| obj2str(k) << '=>' << obj2str(v)}*"," << "}"
|
211
|
+
when Symbol
|
212
|
+
obj.to_s
|
213
|
+
when String
|
214
|
+
if obj.length > HASH2MD5_MAX_STRING_LENGTH
|
215
|
+
sample_large_obj(obj, HASH2MD5_MAX_STRING_LENGTH)
|
216
|
+
else
|
217
|
+
obj
|
218
|
+
end
|
219
|
+
when Array
|
220
|
+
if obj.length > HASH2MD5_MAX_ARRAY_LENGTH
|
221
|
+
"[" << sample_large_obj(obj, HASH2MD5_MAX_ARRAY_LENGTH).collect{|v| obj2str(v)} * "," << "]"
|
222
|
+
else
|
223
|
+
"[" << obj.collect{|v| obj2str(v)} * "," << "]"
|
224
|
+
end
|
225
|
+
when TSV::Parser
|
226
|
+
remove_long_items(obj)
|
227
|
+
when File
|
228
|
+
"[File:" << obj.path << "]"
|
229
|
+
else
|
230
|
+
obj_ins = obj.inspect
|
231
|
+
if obj_ins =~ /:0x0/
|
232
|
+
obj_ins.sub(/:0x[a-f0-9]+@/,'')
|
233
|
+
else
|
234
|
+
obj_ins
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
if defined? Annotated and Annotated === _obj and not (defined? AssociationItem and AssociationItem === _obj)
|
239
|
+
info = Annotated.purge(_obj.info)
|
240
|
+
str << "_" << hash2str(info)
|
241
|
+
end
|
242
|
+
|
243
|
+
str
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
def self.obj2md5(obj)
|
248
|
+
str = obj2str(obj)
|
249
|
+
|
250
|
+
if str.empty?
|
251
|
+
""
|
252
|
+
else
|
253
|
+
digest(str)
|
254
|
+
end
|
255
|
+
end
|
187
256
|
end
|
@@ -586,8 +586,7 @@ module Workflow
|
|
586
586
|
if inputs.any? or dependencies.any?
|
587
587
|
tagged_jobname = case TAG
|
588
588
|
when :hash
|
589
|
-
|
590
|
-
hash_str = Misc.hash2md5(input_hash)
|
589
|
+
hash_str = Misc.obj2md5(inputs)
|
591
590
|
jobname + '_' << hash_str
|
592
591
|
else
|
593
592
|
jobname
|
data/test/rbbt/util/test_misc.rb
CHANGED
@@ -466,4 +466,50 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
466
466
|
end
|
467
467
|
end
|
468
468
|
|
469
|
+
def test_obj2md5
|
470
|
+
str = "string" * 1000000
|
471
|
+
obj1 = [1,2,"test", 0.3, [1,2,3], {:a => [1,2], :b => str}]
|
472
|
+
obj2 = [1,2,"test", 0.3, [1,2,3], {:a => [1,2,3], :b => str}]
|
473
|
+
obj3 = [1,2,:test, 0.3, [1,2,3], {:a => [1,2,"3"], :b => str}]
|
474
|
+
assert_not_equal Misc.obj2md5(obj1), Misc.obj2md5(obj2)
|
475
|
+
assert_equal Misc.obj2md5(obj2), Misc.obj2md5(obj3)
|
476
|
+
hash = Hash[*(0..obj1.length).zip(obj1).flatten]
|
477
|
+
|
478
|
+
Misc.benchmark(10000) do
|
479
|
+
Misc.hash2md5(hash)
|
480
|
+
end
|
481
|
+
Misc.benchmark(10000) do
|
482
|
+
Misc.obj2md5(obj1)
|
483
|
+
end
|
484
|
+
Misc.profile do
|
485
|
+
10.times do
|
486
|
+
Misc.hash2md5(hash)
|
487
|
+
end
|
488
|
+
end
|
489
|
+
Misc.profile do
|
490
|
+
10.times do
|
491
|
+
Misc.obj2md5(obj1)
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
def test_sample_large_string
|
497
|
+
str = "string" * 1000000
|
498
|
+
|
499
|
+
max = 100
|
500
|
+
assert_equal Misc.sample_large_obj(str, max).length, max+51
|
501
|
+
|
502
|
+
max = 1000
|
503
|
+
assert_equal Misc.sample_large_obj(str, max).length, max+51
|
504
|
+
end
|
505
|
+
|
506
|
+
def test_sample_large_array
|
507
|
+
str = (0..1000000).to_a
|
508
|
+
|
509
|
+
max = 100
|
510
|
+
assert_equal Misc.sample_large_obj(str, max).length, max+29
|
511
|
+
|
512
|
+
max = 1000
|
513
|
+
assert_equal Misc.sample_large_obj(str, max).length, max+29
|
514
|
+
end
|
469
515
|
end
|