cotcube-helpers 0.1.6 → 0.1.7
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/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/cotcube-helpers/simple_series_stats.rb +54 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91263c1bbd453c5b1e6c8a3cfe7c0dee3542f5873e82d15caf8118b6b20ce603
|
4
|
+
data.tar.gz: f886c9fe330f439b61c0aee1f3c9cc55b3df161511968c25bb92df5cb85c2f0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00591395a0289380b4063ffa6766073d7619d1f7cc0576afb722854cbdc97f03d5bd651feaaf6a5f49de61770f6d16982a3ae7de26a9fd030c40efec6198e9f5'
|
7
|
+
data.tar.gz: c25f08c4677106ec7dc714653830bb6f9ef668f70df50343c443f0d0c79dccd110bf425fe7fa8cdc28b7ecf18db2d3aafd7cccd5f00b2bb5f3a8113fc17f65fa
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cotcube
|
4
|
+
# Missing top level documentation
|
5
|
+
module Helpers
|
6
|
+
# if given a block, :ind of base is set by block.call()
|
7
|
+
# dim reduces the sample size by top n% and least n%, so dim of 0.5 would remove 100% of the sample
|
8
|
+
def simple_series_stats(base:, ind: nil, dim: 0, format: '%5.2f', print: true, &block)
|
9
|
+
raise ArgumentError, 'Need :ind of type integer' if base.first.is_a?(Array) and not ind.is_a?(Integer)
|
10
|
+
raise ArgumentError, 'Need :ind to evaluate base' if base.first.is_a?(Hash) and ind.nil?
|
11
|
+
|
12
|
+
dim = dim.to_f if dim.is_a? Numeric
|
13
|
+
dim = 0 if dim==false
|
14
|
+
|
15
|
+
raise ArgumentError, 'Expecting 0 <= :dim < 0.5' unless dim.is_a?(Float) and dim >= 0 and dim < 0.5
|
16
|
+
raise ArgumentError, 'Expecting arity of one if block given' if block_given? and not block.arity==1
|
17
|
+
|
18
|
+
precision = format[-1] == 'f' ? format[..-2].split('.').last.to_i : 0
|
19
|
+
worker = base.
|
20
|
+
tap {|b| b.map{|x| x[ind] = block.call(x) } if block.is_a? Proc }.
|
21
|
+
map {|x| ind.nil? ? x : x[ind] }.
|
22
|
+
compact.
|
23
|
+
sort
|
24
|
+
unless dim.zero?
|
25
|
+
reductor = (base.size * dim).round
|
26
|
+
puts reductor
|
27
|
+
worker = worker[reductor..base.size - reductor]
|
28
|
+
puts worker.size
|
29
|
+
end
|
30
|
+
result = {}
|
31
|
+
|
32
|
+
result[:size] = worker.size
|
33
|
+
result[:min] = worker.first
|
34
|
+
result[:avg] = (worker.reduce(:+) / result[:size]).round(precision+1)
|
35
|
+
result[:lower] = worker[ (result[:size] * 1 / 4).round ]
|
36
|
+
result[:median] = worker[ (result[:size] * 2 / 4).round ]
|
37
|
+
result[:upper] = worker[ (result[:size] * 3 / 4).round ]
|
38
|
+
result[:max] = worker.last
|
39
|
+
|
40
|
+
result[:output] = result.
|
41
|
+
reject{|k,_| k == :size}.
|
42
|
+
map{|k,v| { type: k, value: v, output: "#{k}: #{format(format, v)}".colorize(k==:avg ? :light_yellow : :white) } }.
|
43
|
+
sort_by{|x| x[:value]}.
|
44
|
+
map{|x| x[:output]}
|
45
|
+
output = "[" +
|
46
|
+
" size: #{format '%6d', result[:size]} | ".light_white +
|
47
|
+
output.join(' | ') +
|
48
|
+
" ]"
|
49
|
+
|
50
|
+
puts result[:output] if print
|
51
|
+
result
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotcube-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin L. Tischendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/cotcube-helpers/range_ext.rb
|
91
91
|
- lib/cotcube-helpers/reduce.rb
|
92
92
|
- lib/cotcube-helpers/simple_output.rb
|
93
|
+
- lib/cotcube-helpers/simple_series_stats.rb
|
93
94
|
- lib/cotcube-helpers/string_ext.rb
|
94
95
|
- lib/cotcube-helpers/subpattern.rb
|
95
96
|
- lib/cotcube-helpers/swig/date.rb
|