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

cube-core

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cube-core

cube-core 是一个高效的Cube求解工具,你可以借助它来实现快速的Cube运算或搭建pivot table组件。

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

cube-core

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

Package last updated on 10 Aug 2018

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