活动记录、Mongoid、阵列和散列的中位数和百分数
Median and percentile for Active Record, Mongoid, arrays, and hashes
Supports:
:fire: Uses native functions for blazing performance
Add this line to your application’s Gemfile:
gem "active_median"For MySQL, also follow these instructions.
Median
Item.median(:price)Percentile
Request.percentile(:response_time, 0.95)Works with grouping, too
Order.group(:store_id).median(:total)Median
[1, 2, 3].medianPercentile
[1, 2, 3].percentile(0.95)You can also pass a block
{a: 1, b: 2, c: 3}.median { |k, v| v }MySQL requires the PERCENTILE_CONT function from udf_infusion. To install it, do:
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,或尚未同步最近议题。