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

active_median

> 编程语言
Open source

Median and percentile for Active Record, Mongoid, arrays, and hashes

474 stars0 likes3 views
WebsiteGitHub

About

Median and percentile for Active Record, Mongoid, arrays, and hashes

ActiveMedian

Median and percentile for Active Record, Mongoid, arrays, and hashes

Supports:

  • PostgreSQL
  • SQLite
  • MariaDB
  • MySQL (with an extension)
  • SQL Server
  • MongoDB

:fire: Uses native functions for blazing performance

Getting Started

Add this line to your application’s Gemfile:

ruby
gem "active_median"

For MySQL, also follow these instructions.

Models

Median

ruby
Item.median(:price)

Percentile

ruby
Request.percentile(:response_time, 0.95)

Works with grouping, too

ruby
Order.group(:store_id).median(:total)

Arrays and Hashes

Median

ruby
[1, 2, 3].median

Percentile

ruby
[1, 2, 3].percentile(0.95)

You can also pass a block

ruby
{a: 1, b: 2, c: 3}.median { |k, v| v }

Additional Instructions

MySQL

MySQL requires the PERCENTILE_CONT function from udf_infusion. To install it, do:

bash
git clone https://github.com/infusion/udf_infusion.git
cd udf_infusion
./configure --enable-functions="percentile_cont"
make
sudo make install
mysql   /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P YourStrong\!Passw0rd -C -Q "CREATE DATABASE active_median_test"
ADAPTER=sqlserver BUNDLE_GEMFILE=gemfiles/sqlserver.gemfile bundle exec rake test

# MongoDB
BUNDLE_GEMFILE=gemfiles/mongoid7.gemfile bundle exec rake test

Issues· 3 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 推出的简洁高效系统语言