mini_histogram 0.1.0 → 0.1.1
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/.github/workflows/check_changelog.yml +10 -0
- data/.gitignore +2 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +9 -0
- data/README.md +1 -1
- data/Rakefile +3 -4
- data/lib/mini_histogram.rb +17 -6
- data/lib/mini_histogram/version.rb +1 -1
- metadata +4 -3
- data/Gemfile.lock +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b30a210cd0f63b3f9cba87a75876fe936cbdb5ccb8f0d9130a3fbb7edabb253
|
4
|
+
data.tar.gz: 36bf1ad5fc457f2b8766ea3e902952a9aea49e4c48bc4c07828deac4c7a764e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1de6bd55a51f9b5dfa8e31b91a069a52aa6737f76ca9f7ae05f2a77e925ffd9f19e94751daa6f9bdc1026cfde9a7822e1dfccd8b6deaf281d200be2407df20b8
|
7
|
+
data.tar.gz: 765c3657976e4ca6a56570af53ba22ac7d3c7fd910d9cff8d5bbcc2059da7dd8f0c49323ca3469fc0482dfcd1ce07dc17d3a1151690c4a32aef0a46bc1b7583d
|
@@ -0,0 +1,10 @@
|
|
1
|
+
name: Check Changelog
|
2
|
+
on: [pull_request]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
steps:
|
7
|
+
- uses: actions/checkout@v1
|
8
|
+
- name: Check that CHANGELOG is touched
|
9
|
+
run: |
|
10
|
+
cat $GITHUB_EVENT_PATH | jq .pull_request.title | grep -i '\[\(\(changelog skip\)\|\(ci skip\)\)\]' || git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# MiniHistogram
|
1
|
+
# MiniHistogram [](https://travis-ci.org/zombocom/mini_histogram)
|
2
2
|
|
3
3
|
What's a histogram and why should you care? First read [Lies, Damned Lies, and Averages: Perc50, Perc95 explained for Programmers](https://schneems.com/2020/03/17/lies-damned-lies-and-averages-perc50-perc95-explained-for-programmers/). This library lets you build histograms in pure Ruby.
|
4
4
|
|
data/Rakefile
CHANGED
@@ -19,8 +19,8 @@ task :bench do
|
|
19
19
|
|
20
20
|
array = 1000.times.map { rand }
|
21
21
|
|
22
|
-
|
23
|
-
my_weights =
|
22
|
+
histogram = MiniHistogram.new(array)
|
23
|
+
my_weights = histogram.weights
|
24
24
|
puts array.histogram.weights == my_weights
|
25
25
|
puts array.histogram.weights.inspect
|
26
26
|
puts my_weights.inspect
|
@@ -29,8 +29,7 @@ task :bench do
|
|
29
29
|
Benchmark.ips do |x|
|
30
30
|
x.report("enumerable stats") { array.histogram }
|
31
31
|
x.report("mini histogram ") {
|
32
|
-
|
33
|
-
MiniHistogram.counts_from_edges(array, edges: edges)
|
32
|
+
MiniHistogram.new(array).weights
|
34
33
|
}
|
35
34
|
x.compare!
|
36
35
|
end
|
data/lib/mini_histogram.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "mini_histogram/version"
|
2
|
-
require 'math'
|
3
2
|
|
4
3
|
# A class for building histogram info
|
5
4
|
#
|
@@ -20,13 +19,14 @@ require 'math'
|
|
20
19
|
#
|
21
20
|
class MiniHistogram
|
22
21
|
class Error < StandardError; end
|
23
|
-
attr_reader :array, :left_p
|
22
|
+
attr_reader :array, :left_p, :max
|
24
23
|
|
25
24
|
def initialize(array, left_p: false, edges: nil)
|
26
25
|
@array = array
|
27
26
|
@left_p = left_p
|
28
27
|
@edges = edges
|
29
28
|
@weights = nil
|
29
|
+
@max = array.max
|
30
30
|
end
|
31
31
|
|
32
32
|
def edges_min
|
@@ -37,10 +37,19 @@ class MiniHistogram
|
|
37
37
|
edges.max
|
38
38
|
end
|
39
39
|
|
40
|
+
def histogram(*_)
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def closed
|
45
|
+
:left
|
46
|
+
end
|
47
|
+
|
40
48
|
# Sets the edge value to something new,
|
41
49
|
# also clears any previously calculated values
|
42
|
-
def
|
43
|
-
@edges =
|
50
|
+
def update_values(edges:, max: )
|
51
|
+
@edges = edges
|
52
|
+
@max = max
|
44
53
|
@weights = nil # clear memoized value
|
45
54
|
end
|
46
55
|
|
@@ -81,7 +90,7 @@ class MiniHistogram
|
|
81
90
|
lo = edges.first
|
82
91
|
step = edges[1] - edges[0]
|
83
92
|
|
84
|
-
max_index = ((
|
93
|
+
max_index = ((@max - lo) / step).floor
|
85
94
|
@weights = Array.new(max_index + 1, 0)
|
86
95
|
|
87
96
|
array.each do |x|
|
@@ -194,6 +203,8 @@ class MiniHistogram
|
|
194
203
|
steps = array_of_histograms.map(&:bin_size)
|
195
204
|
avg_step_size = steps.inject(&:+).to_f / steps.length
|
196
205
|
|
206
|
+
max_value = array_of_histograms.map(&:max).max
|
207
|
+
|
197
208
|
max_edge = array_of_histograms.map(&:edges_max).max
|
198
209
|
min_edge = array_of_histograms.map(&:edges_min).min
|
199
210
|
|
@@ -202,7 +213,7 @@ class MiniHistogram
|
|
202
213
|
average_edges << average_edges.last + avg_step_size
|
203
214
|
end
|
204
215
|
|
205
|
-
array_of_histograms.each {|h| h.
|
216
|
+
array_of_histograms.each {|h| h.update_values(edges: average_edges, max: max_value) }
|
206
217
|
|
207
218
|
return array_of_histograms
|
208
219
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_histogram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- schneems
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: m
|
@@ -32,11 +32,12 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
+
- ".github/workflows/check_changelog.yml"
|
35
36
|
- ".gitignore"
|
36
37
|
- ".travis.yml"
|
38
|
+
- CHANGELOG.md
|
37
39
|
- CODE_OF_CONDUCT.md
|
38
40
|
- Gemfile
|
39
|
-
- Gemfile.lock
|
40
41
|
- LICENSE.txt
|
41
42
|
- README.md
|
42
43
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
mini_histogram (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
m (1.5.1)
|
10
|
-
method_source (>= 0.6.7)
|
11
|
-
rake (>= 0.9.2.2)
|
12
|
-
method_source (0.9.2)
|
13
|
-
minitest (5.14.0)
|
14
|
-
rake (12.3.3)
|
15
|
-
|
16
|
-
PLATFORMS
|
17
|
-
ruby
|
18
|
-
|
19
|
-
DEPENDENCIES
|
20
|
-
m
|
21
|
-
mini_histogram!
|
22
|
-
minitest (~> 5.0)
|
23
|
-
rake (~> 12.0)
|
24
|
-
|
25
|
-
BUNDLED WITH
|
26
|
-
2.1.2
|