Project

gatoroid

0.01
No commit activity in last 3 years
No release in over 3 years
Gatoroid is a way to store analytics using the poweful features of MongoDB for scalability
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 2.2.0

Runtime

>= 2.1.0
 Project Readme

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