Go to file
Washington Botelho 73b194304e
better formula explanation
2017-10-30 23:45:01 -02:00
lib first commit 2017-10-30 22:30:09 -02:00
spec first commit 2017-10-30 22:30:09 -02:00
.gitignore first commit 2017-10-30 22:30:09 -02:00
.rubocop.yml first commit 2017-10-30 22:30:09 -02:00
.rubocop_todo.yml first commit 2017-10-30 22:30:09 -02:00
.ruby-gemset first commit 2017-10-30 22:30:09 -02:00
.ruby-version first commit 2017-10-30 22:30:09 -02:00
.travis.yml first commit 2017-10-30 22:30:09 -02:00
CHANGELOG.md first commit 2017-10-30 22:30:09 -02:00
Gemfile first commit 2017-10-30 22:30:09 -02:00
Gemfile.lock first commit 2017-10-30 22:30:09 -02:00
LICENSE first commit 2017-10-30 22:30:09 -02:00
README.md better formula explanation 2017-10-30 23:45:01 -02:00
Rakefile first commit 2017-10-30 22:30:09 -02:00
rating.gemspec first commit 2017-10-30 22:30:09 -02:00

README.md

Rating

Build Status Gem Version

A true Bayesian rating system with cache enabled.

JS Rating?

This is Raty: https://github.com/wbotelhos/raty 🌟

Description

Rating uses the know as "True Bayesian Estimate" inspired on IMDb rating with the following formula:

(WR) = (v ÷ (v + m)) × R + (m ÷ (v + m)) × C

IMDb Implementation:

WR: weighted rating

R: average for the movie (mean) = (Rating)

v: number of votes for the movie = (votes)

m: minimum votes required to be listed in the Top 250

C: the mean vote across the whole report

Rating Implementation:

WR: weighted rating

R: average for the resource

v: number of votes for the resource

m: average of the number of votes

C: the average rating based on all resources

Install

Add the following code on your Gemfile and run bundle install:

gem 'rating'

Run the following task to create a Rating migration:

rails g rating:install

Then execute the migrations to create the to create tables rating_rates and rating_ratings:

rake db:migrate

Usage

Just add the callback rating to your model:

class User < ApplicationRecord
  rating
end

Now this model can vote or be voted.

rate

You can vote on some resource:

author   = User.last
resource = Article.last

author.rate(resource, 3)

rating

A voted resource exposes a cached data about it state:

resource = Article.last

resource.rating

It will return a Rating object that keeps:

average: the normal mean of votes;

estimate: the true Bayesian estimate mean value (you should use this over average);

sum: the sum of votes for this resource;

total: the total of votes for this resource.

rate_for

You can retrieve the rate of some author gave to some resource:

author   = User.last
resource = Article.last

author.rate_for resource

It will return a Rate object that keeps:

author: the author of vote;

resource: the resource that received the vote;

value: the value of the vote.

rated?

Maybe you want just to know if some author already rated some resource and receive true or false:

author   = User.last
resource = Article.last

author.rated? resource

rates

You can retrieve all rates made by some author:

author = User.last

author.rates

It will return a collection of Rate object.

rated

In the same way you can retrieve all rates that some author received:

author = User.last

author.rated

It will return a collection of Rate object.

order_by_rating

You can list resource ordered by rating data:

Article.order_by_rating

It will return a collection of resource ordered by estimate desc as default. The order column and direction can be changed:

Article.order_by_rating :average, :asc

It will return a collection of resource ordered by Rating table data.

Love it!

Via PayPal or Gratipay. Thanks! (: