tiny_outcome 3.1.2 → 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 +15 -1
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c42e1143dcbebc9e17795c5972896594ca2efd105efb6dc57c6994396e2f50a9
4
- data.tar.gz: ff222da29f706b0c362b8f6901a10efaf6df4428ee18414e709fc2f9722b94f2
3
+ metadata.gz: 222afbe6c83b56651c435d5359c27eee5f0e6eba0692ebfb6fdce8e7754b7702
4
+ data.tar.gz: ede91ff6d13e6e978a61780f0a1f9c9bb4e76451bbff21c3b6c30ed666722265
5
5
  SHA512:
6
- metadata.gz: a8059baa7359247f5c60198d517c8e5d3e05706c75e54347068788f450ea6bf0d438db7ae8c05df7264aaab48083697953e3d13c0f8795d2215b080c1ad3fb26
7
- data.tar.gz: e04fbe290c68b7d1226f02cda213044cf0fd0c24784a1359404133b1895d099ff5eae1192d113231ae0ba71fa920d191dd2e8cf2179b5eb2bb6c8e51b02c4b08
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?
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.2
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-20 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