Giter Club home page Giter Club logo

gatoroid's Introduction

Gatoroid

Gatoroid is a way to store analytics using the powerful features of MongoDB for scalability

Leveraging mongoid, Gatoroid is a way to increment, decrement, add to, and reset counters in MongoDB. The data is stored using an hourly grain in a utc allowing for easy analytics for on just about anything.

Using Gatoroid to store analytics information

Simply create a class that includes Mongoid::Gator

class SiteStats
  include Mongoid::Gator
  field :siteid
  gator_field :visits
end

Use the class to increment the counter for visits to the site.

@site_stats = SiteStats.new
@site_stats.visits.inc(siteid: 100)

You can also add to the count using the add method. The following adds 10 visits to tomorrow.

@site_stats.visits.add(10, date: Today.now + 1.day)

The data will be stored in MongoDB using seconds since the epoch in hours

{
  "_id" : ObjectId("4f85b40f2a2c4e4d9709eaf9"),
  "date" : 1334160000,
  "siteid" : 100,
  "visits" : 1
}

You can view the total visits to a site by using some built in functions. For example:

@site_stats = SiteStats.new()
@site_stats.visits.today(siteid: 100)  # returns total for today as integer
@site_stats.visits.yesterday(siteid: 100) # returns total for yesterday as integer

To get a list of visits to for a range, use the range method.

@site_stats = SiteStats.new()
@site_stats.visits.range(Time.now..Time.now + 1.day,Mongoid::Gator::Readers::DAY, siteid: 100)

You can change the grain on which you would like to return the data using

Mongoid::Gator::Readers::HOUR
Mongoid::Gator::Readers::DAY
Mongoid::Gator::Readers::MONTH

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.