Coder Social home page Coder Social logo

punching_bag's Introduction

Punching Bag Build Status

Punching Bag is a hit tracking plugin for Ruby on Rails that specializes in simple trending.

Features

  • Total hit count
  • Hit counts for the last day, week, month, etc.
  • Simple trending based on most hits in the last day, week, month, etc.
  • Rake task to group old hit records for better performance
  • ActsAsTaggableOn integration for trending tags/topics support
  • Voight-Kampff integration for bot checking

Requirements

  • An existing Rails app
  • Ruby >= 2.3

Installation

In your Gemfile add:

gem "punching_bag"

In the terminal run:

bundle install
rails g punching_bag
rake db:migrate

In your model add:

acts_as_punchable

Usage

Tracking hits in your controller

class PostsController < ApplicationController
  def show
    @post.punch(request)
  end
end

Getting a total hit count in your view

@post.hits

Getting a hit count for a time period in your view

@post.hits(1.week.ago)

Getting a list of the five all-time most hit posts

Post.most_hit

Getting a list of the 10 most hit posts for the last 24 hours

Post.most_hit(1.day.ago, 10)  # limit is 5 by default, pass nil for no limits

Sorting posts based on all time hit count

Post.sort_by_popularity('DESC')   # DESC by default, can also use ASC

Getting a hit count on a tag for the last month

tag.hits(1.month.ago)

Getting a list of the 10 most hit tags in the last week

ActsAsTaggableOn::Tag.most_hit(1.month.ago, 10)

Compressing old hit records to improve performance
The default settings combine records by day if they're older than 7 days, by month if they're older than 1 month and by year if they're older than 1 year

rake punching_bag:combine

Compressing old hit records using custom settings
This time we'll combine records by day if they're older than 14 days, by month if they're older than 3 months and by year if they're older than 2 years

rake punching_bag:combine[14,3,2]

Notes

  • The punching_bag:combine rake tasks is not run automatically. You'll have to run it manually or add it as a cron job.
  • The punching_bag:combine rake task can take a while depending on how many records need to be combined.
  • Passing the request object to the punch method is optional but without it requests from bots, crawlers and spiders will be tracked.
  • See the Voight-Kampff documentation if you'd like to customize the list of user-agents considered bots.
  • The tag related features will only work if you have ActsAsTaggableOn installed and enabled on the same models as Punching Bag.

punching_bag's People

Contributors

adamcrown avatar cdimartino avatar simonhildebrandt avatar zedtux avatar vicomte avatar n-rodriguez avatar

Watchers

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.