![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
cube-core 是一个高效的Cube求解工具,你可以借助它来实现快速的Cube运算或搭建pivot table组件。
npm install --save cube-core
import {createCube} from 'cube-core'
let cube = createCube ({
type: 'moment' | 'period',
aggFunc: (subset, measures) => {},
factTable: [{}, {}, {}, ..., {}],
dimensions: ['dim1', 'dim2', ..., 'dimn'],
measures: ['mea1', 'mea2', ..., 'mean']
})
cube.buildTree()
此时可以从cube.tree
中获取的构建的树
cube.aggTree()
使用cube.aggTree()
可以计算树中每个节点的聚合值。但在使用period类型的cube时,我们建议按需计算,而不是预计算所有节点。同时period类型的cube会帮你保存已被访问过节点的聚合值;同时在后续有新节点加入时insertNode会帮助你清空受影响节点的聚合值。
如果你要实现数据的修改与删除,要记得清空受影响枝干上所有节点的聚合值(只需要node.clearCache()即可)
cube-core为你提供了最基本的算法正确性检验测试与时间测试,你只需要使用npm test
即可进行测试。
在./test/performance
中,有一些可以使用的对于真实数据集、尤其是那些非常大的数据集的测试脚本,你可以修改其中数据集文件的路径来使用自己的数据集进行测试。
在前端使用时,你还需要将cube.tree转化成自己的UI渲染需要的数据结构。cube-util中提供了一些常见ui需要的数据结构的转化工具。
如果你能够定义两个聚合的快速合并方法,那么这棵树的性能可以大幅度提升。例如
parent.sum = child1.sum + child2.sum + ... + childn.sum 而不是 parent.sum = sum(parent.rawData)
对于和、计数、平均值、最大、最小值甚至是K大数等,没有必要每次都重新聚合后的数组进行计算,而是根据子节点的聚合值完成O(1)的运算。但对于更复杂的场景,设计这样一个聚合运算会愈发艰难。所以,cube-core再设计Cube时仍为你提供了node.rawData这一属性以方便你应对更为复杂的场景。
但你很快会发现,如果能够通过定义节点聚合值得聚合方式,那么你会获得极高的时间与空间的收益。
FAQs
![](https://travis-ci.com/ObservedObserver/cube-core.svg?branch=master) ![](https://img.shields.io/github/license/ObservedObserver/cube-core) ![](https://img.shields.io/npm/v/cube-core)
The npm package cube-core receives a total of 0 weekly downloads. As such, cube-core popularity was classified as not popular.
We found that cube-core 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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.