Project

dateslices

0.02
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
A Rails 4 ActiveRecord plugin that adds group_by_day, group_by_month, etc. Not timezone aware, but supports sqlite.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Dateslices

This project rocks and uses MIT-LICENSE.

This project is based upon groupdate and follows a similar API.

The differences between the groupdate and dateslices are:

  • dateslices supports sqlite3in addition to PostgreSQL & MySQL.
  • dateslices has much less functionality.
  • dateslices ignores timezones.
  • dateslices is rails 4 only.
  • dateslices uses rspecs for tests.

The reason that I wrote this is that I use sqlite in development, and wanted to make sure that I could test things locally. I didn't understand the test suite of groupdate, so I ended up rewriting it.

Walkthrough

A walkthrough of how this code is written is available on my blog

Usage instructions below.

Example Usage

User.where( :created_at > 1.month.ago ).group_by_day

Summing up a column

User.group_by_day( :created_at, "sum", "karma" )

Averaging a column

Post.group_by_week( :updated_at, "avg", "comment_count")

All find methods

These methods take three optional arguments:

  1. column to group by, normally "created_at"
  2. sql function to run, normally "count". Also "sum", "avg"
  3. column to do the function on, normally "*"
  • group_by_second

  • group_by_minute

  • group_by_hour

  • group_by_day

  • group_by_week

  • group_by_month

  • group_by_year

  • group_by_hour_of_day

  • group_by_day_of_week

  • group_by_day_of_month

  • group_by_month_of_year

Configuration

The output format defaults to a Chartkick compatible hash of dates and values. If you wish to use the dateslices format, please add Dateslices.output_format = :dateslices to an initializer.

Tests

Rspec tests need to be run out of the spec/dummy directory, and you'll need to have a postgres and a mysql database named "dateslice_test" for them to succeed.