
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
bitkompagniet-statistics-aggregator
Advanced tools
A group-reduce function interface for statistical presentation
A slim wrapper of logic and sanity around a standard group-reduce operation that provides an interface specific to statistical data presentation.
It revolves around the concept of sets, dimensions and metrics, which are common to data presentation API's such as Google Adx.
In most cases, you don't need this package. Instead, you should use the relevant database aggregate functions (SQL GROUP BY / SUM or mongodb's .mapReduce(), for example).
npm install --save bitkompagniet-statistics-aggregator
It contains just a single function:
var dataset = [
{ website: 'some.com', date: '2016-06-06', revenue: 56.5 },
{ website: 'some.com', date: '2016-06-07', revenue: 80 },
{ website: 'other.com', date: '2016-06-05', revenue: 20.5 },
{ website: 'other.com', date: '2016-06-05', revenue: 10 },
{ website: 'other.com', date: '2016-06-06', revenue: 100 },
];
var aggregator = require('bitkompagniet-statistics-aggregator');
var perWebsite = aggregator(dataset, ['website'], { revenue: 'sum' });
// [
// { website: 'some.com', revenue: 136.6 },
// { website: 'other.com', revenue: 130.5 }
// ];
var perDate = aggregator(dataset, ['date'], { revenue: 'sum' });
// [
// { date: '2016-06-06', revenue: 156.5 },
// { date: '2016-06-05', revenue: 30.5 },
// { date: '2016-06-07', revenue: 80 }
// ];
aggregator(dataset, dimensions, metrics)
array
[ { website: 'some.com', revenue: 80 }, { website: 'other.com', revenue: 70 } ]
Dataset is assumed to be an array of (relatively) uniform plain objects. Some of the keys in these objects are data we want to query, filter, sort and group by. We call these the dimensional fields. Others are those we want to reduce or map. We call these the metrics.
array
[ 'website', 'date' ]
The dataset is first grouped by a combination of all dimensions. The dimensions are given as an array of strings, each corresponding to an object key. All reductions are performed in these groups, so the resulting set will be of the same length as the number of combinations in the dataset.
object
{ revenue: 'sum', visitors: (total, value) => total + value }
An object where keys represent dataset keys, and values are strings denoting the standard function for aggregation, or, alternatively, a custom function. The only built-in functions at this time is:
sum
average
(untested)If supplied as a custom function, it has the following signature:
function(total, value, index, item) { ... }
array
The result will be an array of the aggregation results, similar to the dataset, but will only contain the keys given in dimensions and metrics, respectively. Any extra keys will be removed in the reduction.
FAQs
A group-reduce function interface for statistical presentation
We found that bitkompagniet-statistics-aggregator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.