{"id":13747320,"url":"https://github.com/ankane/active_median","last_synced_at":"2025-11-17T14:02:37.506Z","repository":{"id":9862299,"uuid":"11859691","full_name":"ankane/active_median","owner":"ankane","description":"Median and percentile for Active Record, Mongoid, arrays, and hashes","archived":false,"fork":false,"pushed_at":"2025-10-22T03:36:27.000Z","size":146,"stargazers_count":477,"open_issues_count":3,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-11-05T22:09:03.459Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-08-03T07:25:26.000Z","updated_at":"2025-11-04T09:51:08.000Z","dependencies_parsed_at":"2025-01-16T10:06:46.301Z","dependency_job_id":"97b917a4-c3ca-4446-b2e7-8e7cbc90c514","html_url":"https://github.com/ankane/active_median","commit_stats":{"total_commits":220,"total_committers":2,"mean_commits":110.0,"dds":0.004545454545454519,"last_synced_commit":"70b19fceca7126d6142262c5bca24a925af8f3fd"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/active_median","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Factive_median","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Factive_median/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Factive_median/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Factive_median/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/active_median/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Factive_median/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283442434,"owners_count":26836629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-08T02:00:06.281Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T06:01:25.031Z","updated_at":"2025-11-17T14:02:37.477Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Ruby","Gems","ActiveRecord"],"sub_categories":["Query Enhancement"],"readme":"# ActiveMedian\n\nMedian and percentile for Active Record, Mongoid, arrays, and hashes\n\nSupports:\n\n- PostgreSQL\n- SQLite\n- MariaDB\n- MySQL (with an extension)\n- SQL Server\n- MongoDB\n\n:fire: Uses native functions for blazing performance\n\n[![Build Status](https://github.com/ankane/active_median/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/active_median/actions)\n\n## Getting Started\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"active_median\"\n```\n\nFor MySQL, also follow [these instructions](#additional-instructions).\n\n## Models\n\nMedian\n\n```ruby\nItem.median(:price)\n```\n\nPercentile\n\n```ruby\nRequest.percentile(:response_time, 0.95)\n```\n\nWorks with grouping, too\n\n```ruby\nOrder.group(:store_id).median(:total)\n```\n\n## Arrays and Hashes\n\nMedian\n\n```ruby\n[1, 2, 3].median\n```\n\nPercentile\n\n```ruby\n[1, 2, 3].percentile(0.95)\n```\n\nYou can also pass a block\n\n```ruby\n{a: 1, b: 2, c: 3}.median { |k, v| v }\n```\n\n## Additional Instructions\n\n### MySQL\n\nMySQL requires the `PERCENTILE_CONT` function from [udf_infusion](https://github.com/infusion/udf_infusion). To install it, do:\n\n```sh\ngit clone https://github.com/infusion/udf_infusion.git\ncd udf_infusion\n./configure --enable-functions=\"percentile_cont\"\nmake\nsudo make install\nmysql \u003coptions\u003e \u003c load.sql\n```\n\n### SQLite\n\nImprove performance with SQLite with an extension. Download [percentile.c](https://www.sqlite.org/src/file?name=ext/misc/percentile.c\u0026ci=d49c32e6e7cc341b) and follow the [instructions for compiling loadable extensions](https://www.sqlite.org/loadext.html#compiling_a_loadable_extension) for your platform.\n\nOn Linux, use:\n\n```sh\ngcc -g -fPIC -shared -lsqlite3 percentile.c -o percentile.so\n```\n\nOn Mac, use:\n\n```sh\ngcc -g -fPIC -dynamiclib -L/usr/local/opt/sqlite/lib -lsqlite3 percentile.c -o percentile.dylib\n```\n\nTo load it in Rails, create an initializer with:\n\n```ruby\ndb = ActiveRecord::Base.connection.raw_connection\ndb.enable_load_extension(1)\ndb.load_extension(\"percentile.so\") # or percentile.dylib\ndb.enable_load_extension(0)\n```\n\n## History\n\nView the [changelog](https://github.com/ankane/active_median/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/active_median/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/active_median/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/active_median.git\ncd active_median\nbundle install\n\n# Postgres\ncreatedb active_median_test\nbundle exec rake test\n\n# SQLite\nADAPTER=sqlite3 BUNDLE_GEMFILE=gemfiles/sqlite3.gemfile bundle exec rake test\n\n# MariaDB and MySQL (for MySQL, install the extension first)\nmysqladmin create active_median_test\nADAPTER=mysql2 BUNDLE_GEMFILE=gemfiles/mysql2.gemfile bundle exec rake test\n\n# SQL Server\ndocker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest\ndocker exec -it \u003ccontainer-id\u003e /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P YourStrong\\!Passw0rd -C -Q \"CREATE DATABASE active_median_test\"\nADAPTER=sqlserver BUNDLE_GEMFILE=gemfiles/sqlserver.gemfile bundle exec rake test\n\n# MongoDB\nBUNDLE_GEMFILE=gemfiles/mongoid7.gemfile bundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Factive_median","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Factive_median","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Factive_median/lists"}