2.6.2 • Published 4 years ago

qube v2.6.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Build Status

ube

What is this?

Simple implementation of an in-memory analytics cube.

How to use it?

const Qube = require('qube').Qube;

const qubeOptions = { // options to initialize qube
    measures: [ // what kind of calcs do you want to store in the cube. 
        { type: 'sum', key: 'sales', name: 'sum_sales' },
        { type: 'count', key: 'sales', name: 'count_sales' },
        { type: 'max', key: 'sales', name: 'max_sales' },
        { type: 'min', key: 'sales', name: 'min_sales' },
        { type: 'average', key: 'sales', name: 'average_sales' }
    ],
    dimensions: [ // what are the dimensions you would query on. 
        { type: 'string', key: 'year' },
        { type: 'string', key: 'location' },
        { type: 'string', key: 'product' }
    ]
}
const qube = new Qube(qubeOptions);

// Add some data
qube.push([
    { year: '2017', location: 'Seattle', product: 'Apple', sales: 10 },
    { year: '2017', location: 'Seattle', product: 'Apple', sales: 20 },
    { year: '2018', location: 'Seattle', product: 'Apple', sales: 35 },
    { year: '2018', location: 'Seattle', product: 'Apple', sales: 15 },
    { year: '2019', location: 'Seattle', product: 'Apple', sales: 25 },
    { year: '2019', location: 'Seattle', product: 'Apple', sales: 5 },
    { year: '2017', location: 'Portland', product: 'Apple', sales: 17 },
    { year: '2017', location: 'Portland', product: 'Apple', sales: 19 },
    { year: '2018', location: 'Portland', product: 'Apple', sales: 31 },
    { year: '2018', location: 'Portland', product: 'Apple', sales: 32 },
    { year: '2019', location: 'Portland', product: 'Apple', sales: 21 },
    { year: '2019', location: 'Portland', product: 'Apple', sales: 20 },
    { year: '2017', location: 'Seattle', product: 'Orange', sales: 10 },
    { year: '2017', location: 'Seattle', product: 'Orange', sales: 20 },
    { year: '2018', location: 'Seattle', product: 'Orange', sales: 25 },
    { year: '2018', location: 'Seattle', product: 'Orange', sales: 5 },
    { year: '2019', location: 'Seattle', product: 'Orange', sales: 25 },
    { year: '2019', location: 'Seattle', product: 'Orange', sales: 5 },
    { year: '2017', location: 'Portland', product: 'Orange', sales: 7 },
    { year: '2017', location: 'Portland', product: 'Orange', sales: 16 },
    { year: '2018', location: 'Portland', product: 'Orange', sales: 5 },
    { year: '2018', location: 'Portland', product: 'Orange', sales: 12 },
    { year: '2019', location: 'Portland', product: 'Orange', sales: 11 },
    { year: '2019', location: 'Portland', product: 'Orange', sales: 20 },
]);

const measureToCompute = 'sum_sales'; // try also with min, max, count

// Total Sales.
console.log(`Total sales: ${qube.one({ measure: measureToCompute })}`);

// Total Apple sales in Seattle
const sliceQuery = {
    dimensions: { product: 'Apple', location: 'Seattle'}, 
    measure: measureToCompute 
};
console.log(`Apple sales in Seattle: ${qube.slice(sliceQuery)}`)

// Total Orange sales in Portland in 2018
const diceQuery = {
    dimensions: { product: 'Orange', location: 'Portland', year: '2018'}, 
    measure: measureToCompute
};
console.log(`Portland Orange sales in 2018: ${qube.dice(diceQuery)}`)

// Total Orange sales across all years
const sliceToEnumerateQuery = {
    dimensions: { product: 'Orange'}, 
    measure: measureToCompute
};

console.log(`\nOrange sales across all years`);
console.table(qube.queryWithEnumeration('year', sliceToEnumerateQuery));

// All unique values for years
console.log(`\nList values for dimension 'year'`);
console.table(qube.enumerateDimension('year'));

/*
Expected output

Total sales: 411
Apple sales in Seattle: 110
Portland Orange sales in 2018: 17

Orange sales across all years
┌─────────┬───────┬────────┐
│ (index) │ value │  year  │
├─────────┼───────┼────────┤
│    0    │  53   │ '2017' │
│    1    │  47   │ '2018' │
│    2    │  61   │ '2019' │
└─────────┴───────┴────────┘

List values for dimension 'year'
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
│    0    │ '2017' │
│    1    │ '2018' │
│    2    │ '2019' │
└─────────┴────────┘
*/

Limitations

  1. Only supports sum, count, min, max calculation types
  2. Only supports in-memory storage.

Future

  1. support first, last, average
  2. support plug & play storage
  3. parallelize slice, dice & one (i.e map reduce)
  4. hyper cube (more than 3 dimensions)
  5. high cardinality dimension cubes. (better way to deal with timestamp as a dimension)

Contribute

Contributions are welcome! Though I would suggest you discussing your change through issues first, so to avoid throw away work. Also contributions in terms of pure ideas are welcome too!

2.6.2

4 years ago

2.6.0

5 years ago

2.5.0

5 years ago

2.4.0

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.10

5 years ago

2.1.9

5 years ago

2.1.8

5 years ago

2.1.7

5 years ago

2.1.6

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.2.3-beta

5 years ago

1.2.2-beta

5 years ago

1.2.1-beta

5 years ago

1.2.0-beta

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago