bmg 0.18.3 → 0.18.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 340efbb84309b24fd818bd8ff0c0f40b1f2ba3b3f087e3af0ea574fbd1f7c4ef
4
- data.tar.gz: d7c6af70390c893f6e198f89a019141b4d5727326183f1663aa7d2e15a7ef694
3
+ metadata.gz: 1e208e1eb958222f5ffac079296fc7279f221dddf6ed8165f5004b0a90b08c4b
4
+ data.tar.gz: 6e9e2509ae9ce0d277d226d55d29274b895a6b31dabfe9ac387d4be7fd97be4a
5
5
  SHA512:
6
- metadata.gz: 69562558e784e35f6c8a81bf8b32f8f1a24bbabc176ca8fc109e8151ad324d15dece34d58cf44196a78387b645ae21ec2cb361cc71e11f93b14fd0c916bd1573
7
- data.tar.gz: c25d6966c201c265d2b42dd976e29faf075a8ea285d609883f1f4a9d3c52c941e4c690741e5e277bd4ea8a7d8cfefa4d9adea3a575e2c6006b6993ad767351fb
6
+ metadata.gz: d142fd93326193529359a02c9e14936ffc43dd52ceab4b44e7d890b82cc0df4561e555002f0e6c12e53f6956a4541140be5214a40745ac54e1dc046bdbd4b735
7
+ data.tar.gz: 6fbbd1ad533a0beee8faf783e07c7cedcc2535ef9edf1b601f973a30a513e5ee6d00f0031c8486f4460ccb912acdbad623c86ca649d4664fdc24c63c3f5de693
@@ -31,15 +31,15 @@ module Bmg
31
31
  def each
32
32
  return to_enum unless block_given?
33
33
  @operand.each do |tuple|
34
- yield rename(tuple, renaming)
34
+ yield rename_tuple(tuple, renaming)
35
35
  end
36
36
  end
37
37
 
38
38
  def insert(arg)
39
39
  case arg
40
- when Hash then operand.insert(rename(arg, reverse_renaming))
40
+ when Hash then operand.insert(rename_tuple(arg, reverse_renaming))
41
41
  when Relation then operand.insert(arg.rename(reverse_renaming))
42
- when Enumerable then operand.insert(arg.map{|t| rename(t, reverse_renaming) })
42
+ when Enumerable then operand.insert(arg.map{|t| rename_tuple(t, reverse_renaming) })
43
43
  else
44
44
  super
45
45
  end
@@ -47,7 +47,7 @@ module Bmg
47
47
 
48
48
  def update(arg)
49
49
  case arg
50
- when Hash then operand.update(rename(arg, reverse_renaming))
50
+ when Hash then operand.update(rename_tuple(arg, reverse_renaming))
51
51
  else
52
52
  super
53
53
  end
@@ -89,7 +89,7 @@ module Bmg
89
89
 
90
90
  private
91
91
 
92
- def rename(tuple, renaming)
92
+ def rename_tuple(tuple, renaming)
93
93
  tuple.each_with_object({}){|(k,v),h|
94
94
  h[renaming[k] || k] = v
95
95
  h
@@ -25,7 +25,7 @@ module Bmg
25
25
  .each_with_index
26
26
  .each do |row, i|
27
27
  if i==0
28
- headers = row.map(&:to_sym)
28
+ headers = row.map{|c| c.to_s.strip.to_sym }
29
29
  else
30
30
  init = init_tuple(i)
31
31
  tuple = (0...headers.size)
@@ -10,10 +10,17 @@ module Bmg
10
10
  #
11
11
  class Percentile < Summarizer
12
12
 
13
- def initialize(attribute = nil, nth = 50, &bl)
14
- attribute, nth = nil, attribute if attribute.is_a?(Integer)
15
- super(*[attribute].compact, &bl)
16
- @nth = nth
13
+ DEFAULT_OPTIONS = {
14
+ :variant => :continuous
15
+ }
16
+
17
+ def initialize(*args, &bl)
18
+ @nth = args.find{|a| a.is_a?(Integer) } || 50
19
+ functor = args.find{|a| a.is_a?(Symbol) } || bl
20
+ options = args.select{|a| a.is_a?(Hash) }.inject(DEFAULT_OPTIONS){|memo,opts|
21
+ memo.merge(opts)
22
+ }.dup
23
+ super(functor, options)
17
24
  end
18
25
 
19
26
  # Returns [] as least value.
@@ -29,19 +36,44 @@ module Bmg
29
36
  # Finalizes the computation.
30
37
  def finalize(memo)
31
38
  return nil if memo.empty?
32
- index = memo.size * (@nth / 100.0)
33
- above = [[index.ceil - 1, memo.size - 1].min, 0].max
34
- below = [index.floor - 1, 0].max
39
+ index = memo.size.to_f * (@nth.to_f / 100.0)
40
+ floor, ceil = index.floor, index.ceil
41
+ ceil +=1 if floor == ceil
42
+ below = [floor - 1, 0].max
43
+ above = [[ceil - 1, memo.size - 1].min, 0].max
35
44
  sorted = memo.sort
36
- (sorted[above] + sorted[below]) / 2
45
+ if options[:variant] == :continuous
46
+ (sorted[above] + sorted[below]) / 2.0
47
+ else
48
+ sorted[below]
49
+ end
37
50
  end
38
51
 
39
52
  end # class Avg
40
53
 
41
- # Factors an average summarizer
42
54
  def self.percentile(*args, &bl)
43
55
  Percentile.new(*args, &bl)
44
56
  end
45
57
 
58
+ def self.percentile_cont(*args, &bl)
59
+ Percentile.new(*(args + [{:variant => :continuous}]), &bl)
60
+ end
61
+
62
+ def self.percentile_disc(*args, &bl)
63
+ Percentile.new(*(args + [{:variant => :discrete}]), &bl)
64
+ end
65
+
66
+ def self.median(*args, &bl)
67
+ Percentile.new(*(args + [50]), &bl)
68
+ end
69
+
70
+ def self.median_cont(*args, &bl)
71
+ Percentile.new(*(args + [50, {:variant => :continuous}]), &bl)
72
+ end
73
+
74
+ def self.median_disc(*args, &bl)
75
+ Percentile.new(*(args + [50, {:variant => :discrete}]), &bl)
76
+ end
77
+
46
78
  end # class Summarizer
47
79
  end # module Bmg
@@ -32,7 +32,16 @@ module Bmg
32
32
  }
33
33
  when Hash
34
34
  with.each_with_object(tuple.dup){|(k,v),dup|
35
- dup[k] = transform_attr(dup[k], v)
35
+ case k
36
+ when Symbol
37
+ dup[k] = transform_attr(dup[k], v)
38
+ when Class
39
+ dup.keys.each do |attrname|
40
+ dup[attrname] = transform_attr(dup[attrname], v) if dup[attrname].is_a?(k)
41
+ end
42
+ else
43
+ raise ArgumentError, "Unexpected transformation `#{with.inspect}`"
44
+ end
36
45
  }
37
46
  when Array
38
47
  with.inject(tuple){|dup,on|
data/lib/bmg/version.rb CHANGED
@@ -2,7 +2,7 @@ module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 18
5
- TINY = 3
5
+ TINY = 4
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.3
4
+ version: 0.18.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-06 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: predicate