New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chiasm-data-reduction

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chiasm-data-reduction

A Chiasm component for aggregation and filtering.

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-81.82%
Maintainers
1
Weekly downloads
 
Created
Source

chiasm-data-reduction

A Chiasm component for aggregation and filtering data.

This module is a thin wrapper around the data-reduction module that exposes its functionality within the Chiasm runtime environment.

The properties "aggregate" and "filter" are made available as public properties. These properties correspond to the options passed into data-reduction. The component expects the property "datasetIn" to be set to a dataset object (such as one generated by chiasm-dsv-dataset). The data reduction will be performed on this dataset, and the output will be assigned to the "datasetOut" property.

Example Use

The following code snippet is from the tests for this module, and shows how the component can be instantiated and used within a Chiasm instance.

var chiasm = Chiasm();
chiasm.plugins.dataReduction = ChiasmDataReduction;

chiasm.setConfig({
  reduction: {
    plugin: "dataReduction",
    state: {
      aggregate: {
        dimensions: [{
          column: "foo"
        }],
        measures: [{
          outColumn: "total", 
          operator: "count"
        }]
      }
    }
  }
});

chiasm.getComponent("reduction").then(function (reduction){
  reduction.datasetIn = {
    data: [
      { foo: "A", bar: 1 },
      { foo: "A", bar: 8 },
      { foo: "A", bar: 6 }, // A sum = 15, count = 3
      { foo: "B", bar: 4 },
      { foo: "B", bar: 3 }, // B sum = 7, count = 2
      { foo: "C", bar: 6 },
      { foo: "C", bar: 1 },
      { foo: "C", bar: 3 },
      { foo: "C", bar: 6 },
      { foo: "C", bar: 4 } // C sum = 20, count = 5
    ]
  };
  reduction.when("datasetOut", function (result){
    assert.equal(result.data.length, 3);
    assert.equal(where(result, "foo", "A")[0].total, 3);
    assert.equal(where(result, "foo", "B")[0].total, 2);
    assert.equal(where(result, "foo", "C")[0].total, 5);
    assert.equal(where(result, "foo", "A")[0].total, 3);
    done();
  });
});

function where(result, column, value){
  return result.data.filter(function (d) {
    return d[column] === value;
  });
}

Keywords

FAQs

Package last updated on 03 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc