mini_histogram 0.1.0 → 0.1.1

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: a1d07dadd88ba1bc23f7a24c225a8a7146a657f932122e4681843478ef61ec14
4
- data.tar.gz: fed4add367a52b8dc55f67389877ed6444413c10899c6cb1979af262aa279f7c
3
+ metadata.gz: 0b30a210cd0f63b3f9cba87a75876fe936cbdb5ccb8f0d9130a3fbb7edabb253
4
+ data.tar.gz: 36bf1ad5fc457f2b8766ea3e902952a9aea49e4c48bc4c07828deac4c7a764e8
5
5
  SHA512:
6
- metadata.gz: 407f81d19278447ed837bf983e7794a229eefeee71d5f68f1b1b20929e755057a5047296554c84ec0af6144f2340c6d08dd1770327aa1f28633b80ca01e5e0ef
7
- data.tar.gz: 989f6b2acc56666c9c20c9bb05944a828ed2cef0cab0fc8a54fd7aa7ebb272e2ce7bbee37ecf465d489021be07cc1777e249d54f1fb088c4ffdfc754c3dddf60
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
@@ -6,3 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+
10
+ Gemfile.lock
@@ -7,4 +7,3 @@ rvm:
7
7
  - 2.5
8
8
  - 2.6
9
9
  - 2.7.0
10
- before_install: gem install bundler -v 2.1.2
@@ -0,0 +1,9 @@
1
+ ## Master
2
+
3
+ ## 0.1.1
4
+
5
+ - Fix multi histogram weights, with set_average_edges! method (https://github.com/zombocom/mini_histogram/pull/1)
6
+
7
+ ## 0.1.0
8
+
9
+ - First
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # MiniHistogram
1
+ # MiniHistogram [![Build Status](https://travis-ci.org/zombocom/mini_histogram.svg?branch=master)](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
- edges = MiniHistogram.edges(array)
23
- my_weights = MiniHistogram.counts_from_edges(array, edges: edges)
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
- edges = MiniHistogram.edges(array)
33
- MiniHistogram.counts_from_edges(array, edges: edges)
32
+ MiniHistogram.new(array).weights
34
33
  }
35
34
  x.compare!
36
35
  end
@@ -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 set_edges(value)
43
- @edges = value
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 = ((array.max - lo) / step).floor
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.set_edges(average_edges) }
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
@@ -1,3 +1,3 @@
1
1
  class MiniHistogram
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
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-21 00:00:00.000000000 Z
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
@@ -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