rbbt-util 5.34.13 → 5.34.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/persist/tsv.rb +16 -2
- data/lib/rbbt/resource.rb +4 -0
- data/lib/rbbt/tsv/csv.rb +3 -1
- data/lib/rbbt/tsv/excel.rb +2 -2
- data/lib/rbbt/tsv/manipulate.rb +1 -1
- data/lib/rbbt/util/misc/development.rb +10 -0
- data/lib/rbbt/util/misc.rb +4 -1
- data/lib/rbbt/util/open.rb +5 -4
- data/lib/rbbt/workflow/step/accessor.rb +1 -1
- data/share/Rlib/plot.R +6 -0
- data/share/Rlib/util.R +1 -1
- data/share/rbbt_commands/tsv/info +6 -1
- data/test/rbbt/util/test_misc.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eff409b235c1e08141d4c3c4f30600e91d3c033598731ff6457f1e826389597
|
4
|
+
data.tar.gz: 279844e3cda015f07db9429faf3e9941f12080be28b21bafa2f8472d784969b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1047b4a4449dd169bb572790f7dec2ac15f3ee99a6ed45a81108a102f00870d16f0c07776addd9746bf7656d86285e472234f880308ce8ca8c1d5c8fb3df2ad7
|
7
|
+
data.tar.gz: 227c22590c7d08d4e47121c1f814af71d11b9afa7f5fd71aabed014a8e857b6ebd7424b70ed669b8bc3aa993461339209ca1a67a15c3ab9cf81ac9fd85a83cbe
|
data/lib/rbbt/persist/tsv.rb
CHANGED
@@ -146,9 +146,22 @@ module Persist
|
|
146
146
|
data.serializer = :type
|
147
147
|
end
|
148
148
|
|
149
|
-
|
150
|
-
yield
|
149
|
+
if persist_options[:persist] == :preload
|
150
|
+
tmp_tsv = yield({})
|
151
|
+
tmp_tsv.annotate data
|
152
|
+
data.serializer = tmp_tsv.type
|
153
|
+
data.write_and_read do
|
154
|
+
tmp_tsv.each do |k,v|
|
155
|
+
data[k] = v
|
156
|
+
end
|
157
|
+
end
|
158
|
+
else
|
159
|
+
data.write_and_read do
|
160
|
+
yield data
|
161
|
+
end
|
162
|
+
end
|
151
163
|
|
164
|
+
data.write_and_read do
|
152
165
|
FileUtils.mv data.persistence_path, path if File.exist? data.persistence_path and not File.exist? path
|
153
166
|
tsv = CONNECTIONS[path] = CONNECTIONS.delete tmp_path
|
154
167
|
tsv.persistence_path = path
|
@@ -165,6 +178,7 @@ module Persist
|
|
165
178
|
end
|
166
179
|
end
|
167
180
|
end
|
181
|
+
|
168
182
|
end
|
169
183
|
|
170
184
|
require 'rbbt/persist/tsv/sharder'
|
data/lib/rbbt/resource.rb
CHANGED
@@ -204,6 +204,10 @@ module Resource
|
|
204
204
|
case type
|
205
205
|
when :string
|
206
206
|
Misc.sensiblewrite(final_path, content)
|
207
|
+
when :csv
|
208
|
+
require 'rbbt/tsv/csv'
|
209
|
+
tsv = TSV.csv Open.open(content)
|
210
|
+
Misc.sensiblewrite(final_path, tsv.to_s)
|
207
211
|
when :url
|
208
212
|
options = {}
|
209
213
|
options[:noz] = true if Open.gzip?(final_path) || Open.bgzip?(final_path) || Open.zip?(final_path)
|
data/lib/rbbt/tsv/csv.rb
CHANGED
data/lib/rbbt/tsv/excel.rb
CHANGED
@@ -266,7 +266,7 @@ module TSV
|
|
266
266
|
|
267
267
|
def self.xls(filename, options ={})
|
268
268
|
if Open.remote? filename
|
269
|
-
TmpFile.with_file do |tmp|
|
269
|
+
TmpFile.with_file nil, :extension => 'xls' do |tmp|
|
270
270
|
Open.download(filename, tmp)
|
271
271
|
TSV::XLS.read(tmp, options)
|
272
272
|
end
|
@@ -278,7 +278,7 @@ module TSV
|
|
278
278
|
def self.xlsx(filename, options ={})
|
279
279
|
if Open.remote? filename
|
280
280
|
|
281
|
-
TmpFile.with_file do |tmp|
|
281
|
+
TmpFile.with_file nil, :extension => 'xlsx' do |tmp|
|
282
282
|
Open.download(filename, tmp)
|
283
283
|
TSV::XLSX.read(tmp, options)
|
284
284
|
end
|
data/lib/rbbt/tsv/manipulate.rb
CHANGED
@@ -360,7 +360,7 @@ module TSV
|
|
360
360
|
new = TSV.setup({}, :key_field => key_field, :fields => fields, :type => type, :filename => filename, :identifiers => identifiers)
|
361
361
|
self.with_unnamed do
|
362
362
|
keys.each do |k|
|
363
|
-
new[k] = self[k]
|
363
|
+
new[k] = self[k] if self.include?(k)
|
364
364
|
end
|
365
365
|
end
|
366
366
|
new
|
@@ -193,6 +193,16 @@ def self.add_libdir(dir=nil)
|
|
193
193
|
insist(3, &block)
|
194
194
|
end
|
195
195
|
|
196
|
+
def self.chunk(array, num)
|
197
|
+
total = array.length
|
198
|
+
current = 0
|
199
|
+
while current < total
|
200
|
+
last = current + num - 1
|
201
|
+
yield array[current..last]
|
202
|
+
current = last + 1
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
196
206
|
# Divides the array into +num+ chunks of the same size by placing one
|
197
207
|
# element in each chunk iteratively.
|
198
208
|
def self.divide(array, num)
|
data/lib/rbbt/util/misc.rb
CHANGED
@@ -71,6 +71,9 @@ module Misc
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def self.timespan(str, default = "s")
|
74
|
+
|
75
|
+
return - timespan(str[1..-1], default) if str[0] == "-"
|
76
|
+
|
74
77
|
if str.include?(":")
|
75
78
|
seconds, minutes, hours = str.split(":").reverse
|
76
79
|
return seconds.to_i + minutes.to_i * 60 + hours.to_i * 60 * 60
|
@@ -86,7 +89,7 @@ module Misc
|
|
86
89
|
"h" => (60 * 60),
|
87
90
|
"d" => (60 * 60 * 24),
|
88
91
|
"w" => (60 * 60 * 24 * 7),
|
89
|
-
"mo" => (60 * 60 * 24 *
|
92
|
+
"mo" => (60 * 60 * 24 * 31),
|
90
93
|
"y" => (60 * 60 * 24 * 365),
|
91
94
|
}
|
92
95
|
|
data/lib/rbbt/util/open.rb
CHANGED
@@ -640,7 +640,7 @@ module Open
|
|
640
640
|
io
|
641
641
|
end
|
642
642
|
|
643
|
-
def self.
|
643
|
+
def self.download_old(url, file)
|
644
644
|
Open.open(url, :mode => 'rb', :noz => true) do |sin|
|
645
645
|
Open.open(file, :mode => 'wb') do |sout|
|
646
646
|
Misc.consume_stream(sin, false, sout)
|
@@ -648,6 +648,10 @@ module Open
|
|
648
648
|
end
|
649
649
|
end
|
650
650
|
|
651
|
+
def self.download(url, path)
|
652
|
+
Open.wget(url, "--output-document" => path, :pipe => false)
|
653
|
+
end
|
654
|
+
|
651
655
|
def self.can_open?(file)
|
652
656
|
String === file and (Open.exist?(file) or remote?(file))
|
653
657
|
end
|
@@ -841,7 +845,4 @@ module Open
|
|
841
845
|
File.symlink?(path) && ! File.exist?(File.readlink(path))
|
842
846
|
end
|
843
847
|
|
844
|
-
def self.download(url, path)
|
845
|
-
Open.wget(url, "--output-document" => path)
|
846
|
-
end
|
847
848
|
end
|
data/share/Rlib/plot.R
CHANGED
@@ -39,3 +39,9 @@ geom_entity <- function (real.geom = NULL, mapping = NULL, data = NULL, stat = "
|
|
39
39
|
}
|
40
40
|
|
41
41
|
rbbt.ggplot2.rotate_x_labels <- function(){ theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) }
|
42
|
+
|
43
|
+
rbbt.ggplot2.theme <- function(plot){
|
44
|
+
|
45
|
+
plot + theme_classic() + scale_y_continuous(labels=scales::comma) + scale_x_continuous(labels=scales::comma) + rbbt.ggplot2.rotate_x_labels()
|
46
|
+
|
47
|
+
}
|
data/share/Rlib/util.R
CHANGED
@@ -812,7 +812,7 @@ rbbt.plot.text_scatter <- function(formula, data) {
|
|
812
812
|
rbbt.install.CRAN <- function(pkg){
|
813
813
|
cat("Try CRAN install:", pkg, "\n")
|
814
814
|
res = FALSE
|
815
|
-
tryCatch({ install.packages(pkg); library(pkg); res = TRUE; }, error = function(e){ str(e); warning(paste("Could not install CRAN ", pkg)); res = FALSE })
|
815
|
+
tryCatch({ install.packages(pkg); library(pkg, character.only=T); res = TRUE; }, error = function(e){ str(e); warning(paste("Could not install CRAN ", pkg)); res = FALSE })
|
816
816
|
return(res)
|
817
817
|
}
|
818
818
|
|
@@ -18,6 +18,7 @@ Display summary information. Works with Tokyocabinet HDB and BDB as well.
|
|
18
18
|
-hh--header_hash* Change the character used to mark the header line (defaults to #)
|
19
19
|
-k--key_field* Change the key field
|
20
20
|
-f--fields* Change the fields to load
|
21
|
+
-fp--fingerprint Fingerprint values
|
21
22
|
-s--sep* Change the fields separator (default TAB)
|
22
23
|
-h--help Help
|
23
24
|
EOF
|
@@ -70,7 +71,11 @@ else
|
|
70
71
|
|
71
72
|
puts "Rows: #{Log.color :blue, rows}"
|
72
73
|
parts = []
|
73
|
-
header.first_line.split(header.sep, -1).each_with_index
|
74
|
+
header.first_line.split(header.sep, -1).each_with_index do |p,i|
|
75
|
+
p.strip!
|
76
|
+
p = Misc.fingerprint p.split("|") if %w(double flat).include?(header.options[:type].to_s) && options[:fingerprint]
|
77
|
+
parts << (Log.color(:cyan, "(#{i}) ") << p.strip)
|
78
|
+
end
|
74
79
|
puts parts * "\t"
|
75
80
|
puts
|
76
81
|
end
|
data/test/rbbt/util/test_misc.rb
CHANGED
@@ -610,6 +610,8 @@ EOF
|
|
610
610
|
assert_equal 60*60*24, Misc.timespan('1d')
|
611
611
|
assert_equal 60*60*24, Misc.timespan('1d')
|
612
612
|
assert_equal 60*60*24, Misc.timespan('24:00:00')
|
613
|
+
|
614
|
+
assert_equal Misc.timespan('1min'), - Misc.timespan('-1min')
|
613
615
|
end
|
614
616
|
|
615
617
|
def test_remove_long_items
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.34.
|
4
|
+
version: 5.34.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|