fast_stats 0.1.0.pre.beta.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +26 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +87 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +178 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fast_stats.gemspec +35 -0
- data/lib/fast_stats/mean.rb +55 -0
- data/lib/fast_stats/means.rb +29 -0
- data/lib/fast_stats/version.rb +3 -0
- data/lib/fast_stats.rb +7 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1c20510d123e84d596758254770637794e673378abc7b3af6e0986a346bd062e
|
4
|
+
data.tar.gz: 5ce72e0c23a0a30d0fb9faebc13296afd709404b5879d08e92fab54d868de084
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb08bea0d8317ae23c0e2bb54012ad2a1e0f886d3f0c49166615423696275f37d3346510c65a9dec363a6f1c82792d94d368d1cfe2d3001955bf29ebdd4a7029
|
7
|
+
data.tar.gz: 311d9068faf57092978be015a137b05749c616eb342b82b4edcd3360646bc14798bfd9a57f043b86a4e6b6f7a219a2219ad313a8da45a372eaf050e0a877a25f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.0.0
|
5
|
+
- 2.3.3
|
6
|
+
- 2.4.1
|
7
|
+
- 2.5.0
|
8
|
+
|
9
|
+
before_install: gem install bundler
|
10
|
+
|
11
|
+
deploy:
|
12
|
+
provider: rubygems
|
13
|
+
api_key:
|
14
|
+
secure: ZcW3GM+Z+x6G6hdIQDFj9VB16Gts9Wd/35sD12dgMtiytN5JvDzQyf8jXrFI1VNNm8YsW7GgCETBVgbBEFufWT2bPdGTRo73qxt2Fxe8L+cl+OjvQXO/4NcDB9ZHm/bLryDyVJyTRct9aBk+tOPvtuUVX7Yq0T2mVkrWc17zbAYy2NyOYk9AraiuqAmnIWHU9uK1cnKE/HHkBg6O0du2PIW8ko1DbME6pAm4Gof1dxJ6KfYpJPwFkI73sj0efPmsLaBsMGSqf+chMVvL2SvXYcUwMYxEf2SKSwMC3JE88bR9OfPj+Llm8+XwZfrXUaYarOYpfv0jMVTTTAg45FuLLv0mvKWAS4Q0TYfNEtQWJl/75ApIBqwbvPf04T9ufXlJ8zUfu9MmrfLpCzyEk22o981Acd2X39DW9DQ5B06rc/7kinCIZSFVvgjz2dEryDqVToRJLjjpffoeskOFja+M/blMZmIMKiZq0n1zzElI+n5F/Z+PeUKoGYv6fpUcCCE4XfgQxg1xhXhwK3NmxwrxojWdYt8aZzpyTHL8WAvCblrurduxDE+HaMyOWrXTgh68aE4ZOXeTOgaNZobhHrB4wnZTew0KY/HOSfrQdExaz82stE3D0IEvR8aeVMRFn4EvbYcqgV1KC2SqBJ4HTnXs7N047L7GTCUDaAuveTe6yj0=
|
15
|
+
gem: fast_stats
|
16
|
+
on:
|
17
|
+
repo: kyle-rader/fast_stats
|
18
|
+
branch: master
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
6
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
### Added
|
10
|
+
- Include the harmonic mean
|
11
|
+
- Enable zero handling configuration for geometric mean.
|
12
|
+
|
13
|
+
## [0.1.0] - 2018-02-22
|
14
|
+
### Added
|
15
|
+
- `FastStats::Means` for building up several arithmetic and geometric means over time.
|
16
|
+
- `FastStats::Mean` build up the arithmetic and geometric mean for one metric.
|
17
|
+
- Add CHANGELOG
|
18
|
+
- Add README
|
19
|
+
- Setup Travis CI deployment to RubyGems
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
### Removed
|
24
|
+
|
25
|
+
[Unreleased]: https://github.com/kyle-raderfast_stats/compare/v0.1.0...HEAD
|
26
|
+
[0.1.0]: https://github.com/kyle-raderfast_stats/compare/7bf3c67...v0.1.0
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at kyle@kylerader.ninja. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fast_stats (0.1.0.pre.beta.pre.1)
|
5
|
+
activesupport (>= 4.0, < 5.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (5.1.5)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (~> 0.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
coderay (1.1.2)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
ffi (1.9.21)
|
19
|
+
formatador (0.2.5)
|
20
|
+
guard (2.14.2)
|
21
|
+
formatador (>= 0.2.4)
|
22
|
+
listen (>= 2.7, < 4.0)
|
23
|
+
lumberjack (>= 1.0.12, < 2.0)
|
24
|
+
nenv (~> 0.1)
|
25
|
+
notiffany (~> 0.0)
|
26
|
+
pry (>= 0.9.12)
|
27
|
+
shellany (~> 0.0)
|
28
|
+
thor (>= 0.18.1)
|
29
|
+
guard-compat (1.2.1)
|
30
|
+
guard-rspec (4.7.3)
|
31
|
+
guard (~> 2.1)
|
32
|
+
guard-compat (~> 1.1)
|
33
|
+
rspec (>= 2.99.0, < 4.0)
|
34
|
+
i18n (0.9.5)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
listen (3.1.5)
|
37
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
38
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
39
|
+
ruby_dep (~> 1.2)
|
40
|
+
lumberjack (1.0.12)
|
41
|
+
method_source (0.9.0)
|
42
|
+
minitest (5.11.3)
|
43
|
+
nenv (0.3.0)
|
44
|
+
notiffany (0.1.1)
|
45
|
+
nenv (~> 0.1)
|
46
|
+
shellany (~> 0.0)
|
47
|
+
pry (0.11.3)
|
48
|
+
coderay (~> 1.1.0)
|
49
|
+
method_source (~> 0.9.0)
|
50
|
+
rake (10.5.0)
|
51
|
+
rb-fsevent (0.10.2)
|
52
|
+
rb-inotify (0.9.10)
|
53
|
+
ffi (>= 0.5.0, < 2)
|
54
|
+
rspec (3.7.0)
|
55
|
+
rspec-core (~> 3.7.0)
|
56
|
+
rspec-expectations (~> 3.7.0)
|
57
|
+
rspec-mocks (~> 3.7.0)
|
58
|
+
rspec-core (3.7.1)
|
59
|
+
rspec-support (~> 3.7.0)
|
60
|
+
rspec-expectations (3.7.0)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.7.0)
|
63
|
+
rspec-mocks (3.7.0)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.7.0)
|
66
|
+
rspec-support (3.7.1)
|
67
|
+
ruby_dep (1.5.0)
|
68
|
+
shellany (0.0.1)
|
69
|
+
thor (0.20.0)
|
70
|
+
thread_safe (0.3.6)
|
71
|
+
tzinfo (1.2.5)
|
72
|
+
thread_safe (~> 0.1)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
bundler (~> 1.16)
|
79
|
+
fast_stats!
|
80
|
+
guard (~> 2.0)
|
81
|
+
guard-rspec (~> 4.0)
|
82
|
+
pry
|
83
|
+
rake (~> 10.0)
|
84
|
+
rspec (~> 3.0)
|
85
|
+
|
86
|
+
BUNDLED WITH
|
87
|
+
1.16.1
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Kyle Rader
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# FastStats
|
2
|
+
|
3
|
+
| Travis CI|
|
4
|
+
|----------|
|
5
|
+
| [![Build Status](https://travis-ci.org/kyle-rader/fast_stats.svg?branch=master)](https://travis-ci.org/kyle-rader/fast_stats) |
|
6
|
+
|
7
|
+
Welcome to FastStats!
|
8
|
+
This gem is for computing stats in an efficient manner.
|
9
|
+
It manages a collection of arithmetic and geometric means to help reduce the
|
10
|
+
[data clump code smell](https://sourcemaking.com/refactoring/smells/data-clumps).
|
11
|
+
|
12
|
+
To experiment with the gem, clone it, run `bundle install` and then
|
13
|
+
`bin/console` for an interactive [pry](http://pryrepl.org/)
|
14
|
+
session (a great Ruby REPL).
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'fast_stats'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install fast_stats
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### `FastStats::Mean`
|
35
|
+
|
36
|
+
Build up the arithmetic and geometric means for a metric.
|
37
|
+
|
38
|
+
#### Initialize
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
mean = FastStats::Mean.new
|
42
|
+
```
|
43
|
+
|
44
|
+
#### Instance Methods
|
45
|
+
|
46
|
+
**`add(val) -> value`**<br>
|
47
|
+
Adds the `val` to the mean and returns the new `n` (count). <br>
|
48
|
+
Alias: `<<`.
|
49
|
+
|
50
|
+
**`arithmetic -> value`**<br>
|
51
|
+
**`arithmetic round: val -> value`**<br>
|
52
|
+
Returns the current arithmetic mean.
|
53
|
+
|
54
|
+
**`geometric -> value`**<br>
|
55
|
+
**`geometric round: val -> value`**<br>
|
56
|
+
Returns the current geometric mean.
|
57
|
+
|
58
|
+
**`summary -> hsh`** <br>
|
59
|
+
**`summary round: value -> hsh`** <br>
|
60
|
+
Returns a Hash with the arithmetic and geometric means.
|
61
|
+
|
62
|
+
#### Example
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
mean = FastStats::Mean.new name: "foobar"
|
66
|
+
10.times { |i| mean << i } # or mean.add(i)
|
67
|
+
|
68
|
+
puts mean.arithmetic
|
69
|
+
# => 4.5
|
70
|
+
|
71
|
+
puts mean.arithmetic round: 2
|
72
|
+
# => 4.5
|
73
|
+
|
74
|
+
puts mean.geometric
|
75
|
+
# => 3.597297064377001
|
76
|
+
|
77
|
+
puts mean.geometric round: 3
|
78
|
+
# => 3.597
|
79
|
+
|
80
|
+
puts mean.summary
|
81
|
+
# => {
|
82
|
+
# "arithmetic"=>4.5,
|
83
|
+
# "geometric"=>3.597297064377001
|
84
|
+
# }
|
85
|
+
|
86
|
+
puts mean.summary round: 3
|
87
|
+
# => {
|
88
|
+
# "arithmetic"=>4.5,
|
89
|
+
# "geometric"=>3.597
|
90
|
+
# }
|
91
|
+
```
|
92
|
+
|
93
|
+
### `FastStats::Means`
|
94
|
+
|
95
|
+
Collect means for multiple metrics:
|
96
|
+
|
97
|
+
#### Initialize
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
means = FastStats::Means.new
|
101
|
+
```
|
102
|
+
|
103
|
+
#### Instance Methods
|
104
|
+
|
105
|
+
**`add(metric_name, val) -> value`**<br>
|
106
|
+
Adds the `val` to the `name` mean and returns the new `n` (count) for that
|
107
|
+
mean. <br>
|
108
|
+
|
109
|
+
**`summary -> hsh`** <br>
|
110
|
+
**`summary round: value -> hsh`** <br>
|
111
|
+
Returns a Hash of each mean's summary.
|
112
|
+
|
113
|
+
#### Example
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
# Say you have some "post_fetcher" that is an enumerator for your posts.
|
117
|
+
means = FastStats::Means.new
|
118
|
+
|
119
|
+
post_fetcher.each do |post|
|
120
|
+
# do stuff with post
|
121
|
+
means.add "likes", post["like_count"]
|
122
|
+
means.add "comments", post["share_count"]
|
123
|
+
end
|
124
|
+
|
125
|
+
means.summary
|
126
|
+
# =>
|
127
|
+
#{
|
128
|
+
# "likes_arithmetic"=>4.888888888888889,
|
129
|
+
# "likes_geometric"=>3.345423581422162,
|
130
|
+
# "comments_arithmetic"=>13.636363636363637,
|
131
|
+
# "comments_geometric"=>7.1824970648723765
|
132
|
+
#}
|
133
|
+
|
134
|
+
# You can also pass a round: value
|
135
|
+
means.summary round: 2
|
136
|
+
# =>
|
137
|
+
#{
|
138
|
+
# "likes_arithmetic"=>4.89,
|
139
|
+
# "likes_geometric"=>3.35,
|
140
|
+
# "comments_arithmetic"=>13.64,
|
141
|
+
# "comments_geometric"=>7.18
|
142
|
+
#}
|
143
|
+
|
144
|
+
```
|
145
|
+
|
146
|
+
## Change Log
|
147
|
+
|
148
|
+
Changes and plans for future changes can be found in [the Change Log](./CHANGELOG.md).
|
149
|
+
|
150
|
+
## Development
|
151
|
+
|
152
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
153
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
154
|
+
prompt that will allow you to experiment.
|
155
|
+
|
156
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
157
|
+
To release a new version, update the version number in `version.rb`, and then
|
158
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
159
|
+
push git commits and tags, and push the `.gem` file
|
160
|
+
to [rubygems.org](https://rubygems.org).
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
Bug reports and pull requests are welcome on GitHub at
|
165
|
+
https://github.com/[USERNAME]/fast_stats. This project is intended to be a safe,
|
166
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
167
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
168
|
+
|
169
|
+
## License
|
170
|
+
|
171
|
+
The gem is available as open source under the terms of the
|
172
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
173
|
+
|
174
|
+
## Code of Conduct
|
175
|
+
|
176
|
+
Everyone interacting in the FastStats project’s codebases, issue trackers, chat
|
177
|
+
rooms and mailing lists is expected to follow the
|
178
|
+
[code of conduct](https://github.com/[USERNAME]/fast_stats/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fast_stats"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/fast_stats.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "fast_stats/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fast_stats"
|
8
|
+
spec.version = FastStats::VERSION
|
9
|
+
spec.authors = ["Kyle Rader"]
|
10
|
+
spec.email = ["kyle@kylerader.ninja"]
|
11
|
+
|
12
|
+
spec.summary = %q{A small Ruby Gem for doing fast stats}
|
13
|
+
spec.description = %q{A small Ruby Gem for doing fast stats to help manage metrics calculations}
|
14
|
+
spec.homepage = "https://github.com/kyle-rader/fast_stats"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
# Development Dependencies
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "guard", "~> 2.0"
|
27
|
+
spec.add_development_dependency "guard-rspec", "~> 4.0"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
|
32
|
+
# Runtime Dependencies
|
33
|
+
spec.add_runtime_dependency 'activesupport', '< 5.2', '>= 4.0'
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A class for managing the arithmetic and geometric means
|
4
|
+
# of positive numbers
|
5
|
+
module FastStats
|
6
|
+
class Mean
|
7
|
+
|
8
|
+
DEFAULT_ROUND = 15
|
9
|
+
attr_reader :sum, :log_sum, :n
|
10
|
+
|
11
|
+
def initialize()
|
12
|
+
@sum = 0.0
|
13
|
+
@n = 0
|
14
|
+
@log_sum = 0.0
|
15
|
+
@log_n = 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def add(val)
|
19
|
+
throw ArgumentError.new "#add, val must be >= 0" if val < 0
|
20
|
+
@sum += val
|
21
|
+
@log_sum += safe_log(val)
|
22
|
+
@n += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :<<, :add
|
26
|
+
|
27
|
+
def arithmetic(round: DEFAULT_ROUND)
|
28
|
+
return nil if n == 0
|
29
|
+
(sum / n).round round
|
30
|
+
end
|
31
|
+
|
32
|
+
def geometric(round: DEFAULT_ROUND)
|
33
|
+
return nil if n == 0
|
34
|
+
(2 ** (log_sum / n)).round round
|
35
|
+
end
|
36
|
+
|
37
|
+
def summary(round: DEFAULT_ROUND)
|
38
|
+
{
|
39
|
+
"arithmetic" => arithmetic(round: round),
|
40
|
+
"geometric" => geometric(round: round),
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def safe_log(val)
|
47
|
+
Math.log2 safe_geometric_mean_val(val)
|
48
|
+
end
|
49
|
+
|
50
|
+
def safe_geometric_mean_val(val)
|
51
|
+
val > 0 ? val : 1
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A class for managing the arithmetic and geometric means
|
4
|
+
# of positive numbers
|
5
|
+
module FastStats
|
6
|
+
class Means
|
7
|
+
|
8
|
+
attr_reader :means
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@means = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(name, val)
|
15
|
+
mean_for(name) << val
|
16
|
+
end
|
17
|
+
|
18
|
+
def summary(round: Mean::DEFAULT_ROUND)
|
19
|
+
means.transform_values { |m| m.summary round: 2 }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def mean_for(name)
|
25
|
+
@means[name] ||= Mean.new
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/fast_stats.rb
ADDED
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.pre.beta.pre.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyle Rader
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "<"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.2'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '4.0'
|
107
|
+
type: :runtime
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "<"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '5.2'
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '4.0'
|
117
|
+
description: A small Ruby Gem for doing fast stats to help manage metrics calculations
|
118
|
+
email:
|
119
|
+
- kyle@kylerader.ninja
|
120
|
+
executables: []
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- ".gitignore"
|
125
|
+
- ".rspec"
|
126
|
+
- ".travis.yml"
|
127
|
+
- CHANGELOG.md
|
128
|
+
- CODE_OF_CONDUCT.md
|
129
|
+
- Gemfile
|
130
|
+
- Gemfile.lock
|
131
|
+
- Guardfile
|
132
|
+
- LICENSE.txt
|
133
|
+
- README.md
|
134
|
+
- Rakefile
|
135
|
+
- bin/console
|
136
|
+
- bin/setup
|
137
|
+
- fast_stats.gemspec
|
138
|
+
- lib/fast_stats.rb
|
139
|
+
- lib/fast_stats/mean.rb
|
140
|
+
- lib/fast_stats/means.rb
|
141
|
+
- lib/fast_stats/version.rb
|
142
|
+
homepage: https://github.com/kyle-rader/fast_stats
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.3.1
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.7.3
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: A small Ruby Gem for doing fast stats
|
166
|
+
test_files: []
|