Git Product home page Git Product logo

cross_table's Introduction

CrossTable

Cross tabulation (Pivot table) utility to convert table data to a pivot table form.

Source (List table)

os lang price
win ruby 123
linux ruby 12
mac php 270
win java 560
win php 750
linux java 950
win java 1200
win php 500
mac php 10
mac java 566
win ruby 210

 >>> 

Destination (Pivot table)

ruby java php
win 333 1760 1250
linux 12 950 0
mac 0 566 280

The test code to get the sample table above.

Installation

Add this line to your application's Gemfile:

gem 'cross_table'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cross_table

Usage

Records Count

require 'cross_table'

cross_tbl = CrossTable.counts_from(
  recs: [],         # Source List Table(Enumerable)
  group_rules: [],  # Grouping Rules (Array of Hash)
  y_keys: [],       # Y-axis Keys (Array)
  x_keys: []        # X-axis Keys (Array)
  ret_type: nil     # Type of returned Pivot table. (nil|:xy_titles|:data_only)
)

Sample test code of CrossTable.counts_from

Sample data and group_rule setting

Fields Summary

require 'cross_table'

cross_tbl = CrossTable.sums_from(
  recs: [],         # Source List Table(Enumerable of Hash)
  field: :fld_name  # Target field name to be summarised
  group_rules: [],  # Grouping Rules (Array of Hash)
  y_keys: [],       # Y-axis Keys (Array)
  x_keys: []        # X-axis Keys (Array)
  ret_type: nil     # Type of returned Pivot table. (nil|:xy_titles|:data_only)
)

Sample test code of CrossTable.sums_from

Sample data and group_rule setting

Fields Average

require 'cross_table'

cross_tbl = CrossTable.avgs_from(
  recs: [],         # Source List Table(Enumerable of Hash)
  field: :fld_name  # Target field name to be summarised
  group_rules: [],  # Grouping Rules (Array of Hash)
  y_keys: [],       # Y-axis Keys (Array)
  x_keys: []        # X-axis Keys (Array)
  ret_type: nil     # Type of returned Pivot table. (nil|:xy_titles|:data_only)
)

Sample test code of CrossTable.avgs_from

Sample data and group_rule setting

Arbitrary property of grouped records

require 'cross_table'

cross_tbl = CrossTable.from(
  recs: [],         # Source List Table(Enumerable of Hash)
  group_rules: [],  # Grouping Rules (Array of Hash)
  y_keys: [],       # Y-axis Keys (Array)
  x_keys: []        # X-axis Keys (Array)
  ret_type: nil     # Type of returned Pivot table. (nil|:xy_titles|:data_only)
  &aggr_proc        # Proc/block to get a value from the arg "group_recs"
)

Sample test code of CrossTable.from to get a Minumum value.

Sample data and group_rule setting

Multiple Keys Grouping

Sample test code of using multilpe keys.

Development

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/masa-kunikata/cross_table.

License

The gem is available as open source under the terms of the MIT License.

cross_table's People

Contributors

masa-kunikata avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

cross_table's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.