Git Product home page Git Product logo

fast_stats's Introduction

FastStats

Travis CI
Build Status

Welcome to FastStats! This gem is for computing stats in an efficient manner. It manages a collection of arithmetic and geometric means to help reduce the data clump code smell.

To experiment with the gem, clone it, run bundle install and then bin/console for an interactive pry session (a great Ruby REPL).

Installation

Add this line to your application's Gemfile:

gem 'fast_stats'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fast_stats

Usage

FastStats::Mean

Build up the arithmetic and geometric means for a metric.

Initialize

mean = FastStats::Mean.new

Instance Methods

add(val) -> value
Adds the val to the mean and returns the new n (count).
Alias: <<.

arithmetic -> value
arithmetic round: val -> value
Returns the current arithmetic mean.

geometric -> value
geometric round: val -> value
Returns the current geometric mean.

summary -> hsh
summary round: value -> hsh
Returns a Hash with the arithmetic and geometric means.

Example

mean = FastStats::Mean.new name: "foobar"
10.times { |i| mean << i }  # or mean.add(i)

puts mean.arithmetic
# => 4.5

puts mean.arithmetic round: 2
# => 4.5

puts mean.geometric
# => 3.597297064377001

puts mean.geometric round: 3
# => 3.597

puts mean.summary
# => {
#   "arithmetic"=>4.5,
#   "geometric"=>3.597297064377001
#   }

puts mean.summary round: 3
# => {
#   "arithmetic"=>4.5,
#   "geometric"=>3.597
#   }

FastStats::Means

Collect means for multiple metrics:

Initialize

means = FastStats::Means.new

Instance Methods

add(metric_name, val) -> value
Adds the val to the name mean and returns the new n (count) for that mean.

summary -> hsh
summary round: value -> hsh
Returns a Hash of each mean's summary.

Example

# Say you have some "post_fetcher" that is an enumerator for your posts.
means = FastStats::Means.new

post_fetcher.each do |post|
   # do stuff with post
   means.add "likes", post["like_count"]
   means.add "comments", post["share_count"]
end

means.summary
# =>
#{
#   "likes_arithmetic"=>4.888888888888889,
#   "likes_geometric"=>3.345423581422162,
#   "comments_arithmetic"=>13.636363636363637,
#   "comments_geometric"=>7.1824970648723765
#}

# You can also pass a round: value
means.summary round: 2
# =>
#{
#   "likes_arithmetic"=>4.89,
#   "likes_geometric"=>3.35,
#   "comments_arithmetic"=>13.64,
#   "comments_geometric"=>7.18
#}

Change Log

Changes and plans for future changes can be found in the Change Log.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fast_stats. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the FastStats project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

fast_stats's People

Contributors

bryanp avatar

Watchers

Nathan Carnes avatar Amiel Martin avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.