tiny_outcome 3.1.2 → 3.2.1

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 +4 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c42e1143dcbebc9e17795c5972896594ca2efd105efb6dc57c6994396e2f50a9
4
- data.tar.gz: ff222da29f706b0c362b8f6901a10efaf6df4428ee18414e709fc2f9722b94f2
3
+ metadata.gz: f41893167c62831d2a03078cf4a705942a5cd6d0e34510d210e17fed7170b477
4
+ data.tar.gz: ab471b6e5a0a742c7fee52997c09ed407e8aa4384f4fbef9da7dd9aa8f2d33c2
5
5
  SHA512:
6
- metadata.gz: a8059baa7359247f5c60198d517c8e5d3e05706c75e54347068788f450ea6bf0d438db7ae8c05df7264aaab48083697953e3d13c0f8795d2215b080c1ad3fb26
7
- data.tar.gz: e04fbe290c68b7d1226f02cda213044cf0fd0c24784a1359404133b1895d099ff5eae1192d113231ae0ba71fa920d191dd2e8cf2179b5eb2bb6c8e51b02c4b08
6
+ metadata.gz: a056a069d46f123d579da83391484bef2fdedbf4a19ca4892c37a8f9072a6b4a3589a15d6f1092b20bab61941bf013822a804543c21ec0371e93172c95b1480b
7
+ data.tar.gz: e87eac01abb118a67e151a7f5919f659e8d1ce22bd9ebc01ea1fda9045183a0addd3b81e6e3a144be905f9bdf670137c6070721381bf9ea1abf83b2187d9f195
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.1
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
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: a tiny outcome tracker with almost no features
27
+ description: track the probability of a binary outcome
28
28
  email: jefflunt@gmail.com
29
29
  executables: []
30
30
  extensions: []
@@ -53,6 +53,5 @@ requirements: []
53
53
  rubygems_version: 3.3.7
54
54
  signing_key:
55
55
  specification_version: 4
56
- summary: want to track the outcome of binary events, and absolutely nothing else?
57
- then this library is for you.
56
+ summary: track the probability of a binary outcome
58
57
  test_files: []