Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rollup

> 编程语言
Open source

Rollup time-series data in Rails

351 stars0 likes1 views
WebsiteGitHub

About

Rollup time-series data in Rails

Rollup

:fire: Rollup time-series data in Rails

Works great with Ahoy and Searchjoy

Installation

Add this line to your application’s Gemfile:

ruby
gem "rollups"

And run:

bash
bundle install
rails generate rollups
rails db:migrate

Contents

  • Getting Started
  • Creating Rollups
  • Querying Rollups
  • Other Topics
  • Examples

Getting Started

Store the number of users created by day in the rollups table

ruby
User.rollup("New users")

Get the series

ruby
Rollup.series("New users")
# {
#   Thu, 01 Jan 2026 => 50,
#   Fri, 02 Jan 2026 => 100,
#   Sat, 03 Jan 2026 => 34
# }

Use a rake task or background job to create rollups on a regular basis. Don’t worry too much about naming - you can rename later if needed.

Creating Rollups

Time Column

Specify the time column - created_at by default

ruby
User.rollup("New users", column: :joined_at)

Change the default column for a model

ruby
class User 

For multiple series, set a name for each series before charting

ruby
series = Rollup.multi_series("Orders by platform")
series.each do |s|
  s[:name] = s[:dimensions]["platform"]
end

Other Topics

Naming

Use any naming convention you prefer. Some ideas are:

  • Human - New users
  • Underscore - new_users
  • Dots - new_users.count

Rename with:

ruby
Rollup.rename("Old name", "New name")

Date Storage

Rollup stores both dates and times in the time column depending on the interval. For date intervals (day, week, etc), it stores 00:00:00 for the time part. Cast the time column to a date when querying in SQL to get the correct value.

  • PostgreSQL: time::date
  • MySQL: CAST(time AS date)
  • SQLite: date(time)

Examples

  • Ahoy
  • Searchjoy

Ahoy

Set the default rollup column for your models

ruby
class Ahoy::Visit < ApplicationRecord
  self.rollup_column = :started_at
end

and

ruby
class Ahoy::Event < ApplicationRecord
  self.rollup_column = :time
end

Hourly visits

ruby
Ahoy::Visit.rollup("Visits", interval: "hour")

Visits by browser

ruby
Ahoy::Visit.group(:browser).rollup("Visits by browser")

Unique homepage views

ruby
Ahoy::Event.where(name: "Viewed homepage").joins(:visit).rollup("Homepage views") { |r| r.distinct.count(:visitor_token) }

Product views

ruby
Ahoy::Event.where(name: "Viewed product").group_prop(:product_id).rollup("Product views")

Searchjoy

Daily searches

ruby
Searchjoy::Search.rollup("Searches")

Searches by query

ruby
Searchjoy::Search.group(:normalized_query).rollup("Searches by query", dimension_names: ["query"])

Conversion rate

ruby
Searchjoy::Search.rollup("Search conversion rate") { |r| r.average("(converted_at IS NOT NULL)::int") }

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

To get started with development:

bash
git clone https://github.com/ankane/rollup.git
cd rollup
bundle install

# create databases
createdb rollup_test
mysqladmin create rollup_test

# run tests
bundle exec rake test

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言