tiny_outcome 3.1.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_outcome.rb +21 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 117564a93dd35781e19d6f1420eb763f2a39ed5feb38a7a3bd3279ad8f1ed4d2
4
- data.tar.gz: 5dd7829f20e626b261a004ef3f83a8e48d8e978fc8d400d36f63d62e6f6bfd42
3
+ metadata.gz: 222afbe6c83b56651c435d5359c27eee5f0e6eba0692ebfb6fdce8e7754b7702
4
+ data.tar.gz: ede91ff6d13e6e978a61780f0a1f9c9bb4e76451bbff21c3b6c30ed666722265
5
5
  SHA512:
6
- metadata.gz: 02c0184cb9692db7ffce8fd91cd1ec1b830df1b0bebf453c7fd25744ead1cc2af5ba2e9c990b4eed23d3668231edeb79840b4121ddf65d5ac2bbf57a6e1a85c5
7
- data.tar.gz: 3fb696f998d6598d04453b5dbe1ac70216ff340884b9a6d89a6b990338619e7c34197b43a10d7a2403ea4b5ff3ba915cd988c4c1a5b0982c6f39ca7383538006
6
+ metadata.gz: d309251961ce51a7c4424019a654df5ff5b0a29bf7be56e6b16c87330dc6f56137cc991e0b6bf49e6757656fdac72a4c06fdb463a605971a8df9b313d6364232
7
+ data.tar.gz: 1f3c55cbf2c1d189e8fe28aaa464a6652515b9902921a548cfccb5731e39c7bcad128ebfc3c854fdc245748862fb4a33edded6169c9e7eeccf8d3c3663307c8d
data/lib/tiny_outcome.rb CHANGED
@@ -70,8 +70,14 @@ class TinyOutcome
70
70
  end
71
71
  end
72
72
 
73
+ # returns the array of collected samples of 1s and 0s
74
+ def collected_samples
75
+ (full? ? @value.rotate(@value_index) : @value)[..(samples-1)]
76
+ end
77
+
78
+ # converts the array of #collected_samples to a base-10 Integer
73
79
  def numeric_value
74
- (full? ? @value.rotate(@value_index) : @value)[..(samples-1)].join.to_i(2)
80
+ collected_samples.join.to_i(2)
75
81
  end
76
82
 
77
83
  # add a sample to the historic outcomes
@@ -103,6 +109,14 @@ class TinyOutcome
103
109
  @probability >= percentage
104
110
  end
105
111
 
112
+ # true if #probability is >= percentage
113
+ # false otherwise
114
+ def winner_at_lately?(percentage, max_samples)
115
+ recent_samples = collected_samples.last(max_samples)
116
+ recent_probability = recent_samples.count(1) / recent_samples.length.to_f
117
+ recent_probability >= percentage
118
+ end
119
+
106
120
  # true if we've received at least warmup number of samples
107
121
  # false otherwise
108
122
  def warm?
@@ -132,16 +146,16 @@ class TinyOutcome
132
146
  sum = 0.0
133
147
  raw = (full? ? @value.rotate(@value_index) : @value)[..(samples-1)]
134
148
  group_size = [@samples, 100].min
135
- num_groups = @samples - group_size
149
+ num_groups = (@samples - group_size) + 1
136
150
  raw.each_cons(group_size) do |samples_group|
137
- curr = samples_group.count(1) / samples.to_f
138
- sum += curr
151
+ num_ones = samples_group.count(1) / group_size.to_f
152
+ sum += num_ones
139
153
 
140
- @min = curr if curr < @min
141
- @max = curr if curr > @max
154
+ @min = num_ones if num_ones < @min
155
+ @max = num_ones if num_ones > @max
142
156
  end
143
157
 
144
- @avg = sum / (@num_groups.to_f + 1.0)
158
+ @avg = sum / num_groups.to_f
145
159
  end
146
160
 
147
161
  # convenient way to see what's up
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_outcome
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-08 00:00:00.000000000 Z
11
+ date: 2023-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest