Popularity
1.9
Stable
Activity
0.0
Stable
107
1
6

Description

The Chartable gem is a lightweight and database-level library to transform any Active Record query into analytics hash ready for use with any chart library.

Monthly Downloads: 761
Programming language: Ruby
License: MIT License
Tags: Analytics     Services     Web Analytics    
Latest version: v0.0.0.2

The Chartable Ruby gem alternatives and similar gems

Based on the "Analytics" category.
Alternatively, view The Chartable Ruby gem alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of The Chartable Ruby gem or a related project?

Add another 'Analytics' Gem

README

The Chartable Ruby gem

The Chartable gem is a lightweight and database-level library to transform any Active Record query into analytics hash ready for use with any chart library.

Supported database engines: MySQL and PostgreSQL

Installation

gem install chartable

Usage examples

The gem adds the analytics class method to all Rails models. Currently, five analytics periods are available: yearly, weekly, monthly, quarterly and daily. If it's not specified then it operates on the created_at column.

User.analytics(:yearly) # => { 2017 => 5, 2018 => 30 }
User.analytics(:monthly) # => { "November 2018" => 1, "October 2018" => 1 }
User.analytics(:daily) # => {"October 09, 2018" => 1, "October 10, 2018" => 1}
User.analytics(:weekly) # => {"01/28/18 - 02/03/18" => 1, "02/11/18 - 02/17/18" => 1}
User.analytics(:quarterly) # => {"Q1 2018" => 1, "Q2 2018" => 1}

If you want to change the column used for sorting then specify the :on option:

User.analytics(:yearly, on: 'updated_at')

If you want to narrow the results you can pass from: or/and to: options. You can pass any valid value of type String, Date, DateTime or Time - it will be transformed to the date format:

User.analytics(:yearly, from: Date.yesterday, to: Date.today)

You can also call analytics on any query:

User.where(first_name: 'John').where.not(last_name: 'Doe').analytics(:daily)

Sorting

With the 0.0.0.3 version is possible to sort results:

User.analytics(:yearly, order: 'desc') # or order: 'asc'

Supported Ruby Versions

This gem was tested on the 2.5.0 version. If it's not working with older versions please add a new issue.

Committers and Contributors

TODO

  • Add the CHANGELOG file
  • Add a separated query class for each database driver
  • When a date period is restricted then return 0 for periods without the data
  • Test code with the older Ruby versions

Copyright

Copyright (c) 2018 Paweł Dąbrowski. See [LICENSE][] for details.


*Note that all licence references and agreements mentioned in the The Chartable Ruby gem README section above are relevant to that project's source code only.