├── .eslintignore ├── .npmignore ├── tsconfig.json ├── src ├── index.ts ├── util.ts ├── .eslintrc.yaml ├── id.ts ├── types.ts └── aggregate.ts ├── package.json ├── README.md ├── .gitignore ├── dist ├── ecSimpleTransform.min.js ├── ecSimpleTransform.js └── ecSimpleTransform.js.map ├── .eslintrc-common.yaml └── LICENSE /.eslintignore: -------------------------------------------------------------------------------- 1 | /dist 2 | /node_modules 3 | /build 4 | /lib 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | /build 2 | /npm-debug.log 3 | /src 4 | /node_modules 5 | tsconfig.json 6 | .DS_Store 7 | .eslintignore 8 | .eslintrc-common.yaml 9 | Thumbs.db 10 | Desktop.ini 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES3", 4 | 5 | "noImplicitAny": true, 6 | "noImplicitThis": true, 7 | "strictBindCallApply": true, 8 | "removeComments": true, 9 | "sourceMap": true, 10 | 11 | // https://github.com/ezolenko/rollup-plugin-typescript2/issues/12#issuecomment-536173372 12 | "moduleResolution": "node", 13 | 14 | "declaration": true, 15 | "declarationMap": false, 16 | 17 | "importHelpers": true, 18 | 19 | "pretty": true, 20 | 21 | "outDir": "lib" 22 | }, 23 | "include": [ 24 | "src/**/*.ts" 25 | ] 26 | } -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | 21 | export { transform as id } from './id'; 22 | export { transform as aggregate } from './aggregate'; 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "echarts-simple-transform", 3 | "version": "1.0.0", 4 | "description": "Some simple data transforms for Apache ECharts 5", 5 | "license": "Apache-2.0", 6 | "main": "dist/ecSimpleTransform.js", 7 | "jsdelivr": "dist/ecSimpleTransform.min.js", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/100pah/echarts-simple-transform.git" 11 | }, 12 | "scripts": { 13 | "build": "node build/build.js", 14 | "release": "node build/build.js --release", 15 | "lint": "./node_modules/.bin/eslint src/**/*.ts", 16 | "cp2echarts": "cp ./dist/ecSimpleTransform.js ../echarts/test/lib/ecSimpleTransform.js" 17 | }, 18 | "dependencies": { 19 | "tslib": "2.0.3" 20 | }, 21 | "devDependencies": { 22 | "@microsoft/api-extractor": "7.7.2", 23 | "@typescript-eslint/eslint-plugin": "^2.15.0", 24 | "@typescript-eslint/parser": "^2.18.0", 25 | "chalk": "^3.0.0", 26 | "commander": "2.11.0", 27 | "eslint": "6.3.0", 28 | "fs-extra": "0.26.7", 29 | "rollup": "2.34.2", 30 | "rollup-plugin-typescript2": "^0.25.3", 31 | "rollup-plugin-terser": "^7.0.2", 32 | "terser": "^5.3.8", 33 | "typescript": "^4.1.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/util.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | export function assert(condition: any, message?: string) { 21 | if (!condition) { 22 | throw new Error(message); 23 | } 24 | } 25 | 26 | export function hasOwn(own: object, prop: string): boolean { 27 | return own.hasOwnProperty(prop); 28 | } 29 | 30 | export function quantile(ascArr: number[], p: number): number { 31 | const H = (ascArr.length - 1) * p + 1; 32 | const h = Math.floor(H); 33 | const v = +ascArr[h - 1]; 34 | const e = H - h; 35 | return e ? v + e * (ascArr[h] - v) : v; 36 | } 37 | -------------------------------------------------------------------------------- /src/.eslintrc.yaml: -------------------------------------------------------------------------------- 1 | 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | # Note: 20 | # If eslint does not work in VSCode, please check: 21 | # (1) Whether "@typescript-eslint/eslint-plugin" and "@typescript-eslint/parser" 22 | # are npm installed locally. Should better in the same version. 23 | # (2) Whether "VSCode ESlint extension" is installed. 24 | # (3) If the project folder is not the root folder of your working space, please 25 | # config the "VSCode ESlint extension" in "settings": 26 | # ```json 27 | # "eslint.workingDirectories": [{"mode": "auto"}] 28 | # ``` 29 | # Note that it should be "workingDirectories" rather than "WorkingDirectories". 30 | 31 | parser: "@typescript-eslint/parser" 32 | parserOptions: 33 | ecmaVersion: 6 34 | sourceType: module 35 | ecmaFeatures: 36 | modules: true 37 | project: "tsconfig.json" 38 | plugins: ["@typescript-eslint"] 39 | env: 40 | browser: false 41 | node: false 42 | es6: false 43 | globals: 44 | jQuery: false 45 | Promise: false 46 | __DEV__: false 47 | extends: '../.eslintrc-common.yaml' 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # echarts-simple-transform 2 | 3 | This is a non-official library. 4 | 5 | There are some simple data transformers for Apache ECharts 5 in this library. Some of them might be migrated as ECharts built-in transforms in future. 6 | 7 | 8 | ## Aggregate Transform 9 | ```js 10 | echarts.registerTransform(ecSimpleTransform.aggregate); 11 | 12 | const option = { 13 | dataset: [{ 14 | source: [ 15 | ['aa', 'bb', 'cc', 'tag'], 16 | [12, 0.33, 5200, 'AA'], 17 | [21, 0.65, 7100, 'AA'], 18 | [51, 0.15, 1100, 'BB'], 19 | [71, 0.75, 9100, 'BB'], 20 | ... 21 | ] 22 | }, { 23 | transform: { 24 | type: 'ecSimpleTransform:aggregate', 25 | config: { 26 | resultDimensions: [ 27 | // by default, use the same name with `from`. 28 | { from: 'aa', method: 'sum' }, 29 | { from: 'bb', method: 'count' }, 30 | { from: 'cc' }, // method by default: use the first value. 31 | { from: 'dd', method: 'Q1' }, 32 | { from: 'tag' } 33 | ], 34 | groupBy: 'tag' 35 | } 36 | } 37 | // Then the result data will be: 38 | // [ 39 | // ['aa', 'bb', 'cc', 'tag'], 40 | // [12, 0.33, 5200, 'AA'], 41 | // [21, 0.65, 8100, 'BB'], 42 | // ... 43 | // ] 44 | }], 45 | // ... 46 | }; 47 | 48 | const myChart = echarts.init(dom); 49 | myChart.setOption(option); 50 | ``` 51 | 52 | 53 | Current supported `method`s (case insensitive): 54 | + 'sum' 55 | + 'count' 56 | + 'first' 57 | + 'average' 58 | + 'Q1' 59 | + 'Q2' or 'median' 60 | + 'Q3' 61 | + 'min' 62 | + 'max' 63 | 64 | Also see this [example](https://echarts.apache.org/examples/en/editor.html?c=data-transform-aggregate). 65 | 66 | 67 | ## Id Transform 68 | 69 | ```js 70 | echarts.registerTransform(ecSimpleTransform.aggregate); 71 | 72 | const option = { 73 | dataset: [{ 74 | source: [ 75 | ['aa', 'bb', 'cc', 'tag'], 76 | [12, 0.33, 5200, 'AA'], 77 | [21, 0.65, 8100, 'AA'], 78 | ... 79 | ] 80 | }, { 81 | transform: { 82 | type: 'ecSimpleTransform:id', 83 | config: { 84 | dimensionIndex: 4, 85 | dimensionName: 'ID' 86 | } 87 | } 88 | // Then the result data will be: 89 | // [ 90 | // ['aa', 'bb', 'cc', 'tag', 'ID'], 91 | // [12, 0.33, 5200, 'AA', 0], 92 | // [21, 0.65, 8100, 'BB', 1], 93 | // ... 94 | // ] 95 | }], 96 | // ... 97 | }; 98 | 99 | const myChart = echarts.init(dom); 100 | myChart.setOption(option); 101 | ``` 102 | -------------------------------------------------------------------------------- /src/id.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import { 21 | DataTransformOption, DimensionDefinitionLoose, DimensionIndex, 22 | DimensionName, ExternalDataTransform, OptionSourceDataArrayRows 23 | } from './types'; 24 | 25 | /** 26 | * @usage 27 | * 28 | * ```js 29 | * dataset: [{ 30 | * source: [ 31 | * ['aa', 'bb', 'cc', 'tag'], 32 | * [12, 0.33, 5200, 'AA'], 33 | * [21, 0.65, 8100, 'AA'], 34 | * ... 35 | * ] 36 | * }, { 37 | * transform: { 38 | * type: 'ecSimpleTransform:id', 39 | * config: { 40 | * dimensionIndex: 4, 41 | * dimensionName: 'ID' 42 | * } 43 | * } 44 | * // Then the result data will be: 45 | * // [ 46 | * // ['aa', 'bb', 'cc', 'tag', 'ID'], 47 | * // [12, 0.33, 5200, 'AA', 0], 48 | * // [21, 0.65, 8100, 'BB', 1], 49 | * // ... 50 | * // ] 51 | * }] 52 | * ``` 53 | */ 54 | 55 | export interface IdTransformOption extends DataTransformOption { 56 | type: 'ecSimpleTransform:id'; 57 | config: { 58 | // Mandatory. Specify where to put the new id dimension. 59 | dimensionIndex: DimensionIndex; 60 | // Optional. If not provided, left the dimension name not defined. 61 | dimensionName: DimensionName; 62 | }; 63 | } 64 | 65 | export const transform: ExternalDataTransform = { 66 | 67 | type: 'ecSimpleTransform:id', 68 | 69 | transform: function (params) { 70 | const upstream = params.upstream; 71 | const config = params.config; 72 | const dimensionIndex = config.dimensionIndex; 73 | const dimensionName = config.dimensionName; 74 | 75 | const dimsDef = upstream.cloneAllDimensionInfo() as DimensionDefinitionLoose[]; 76 | dimsDef[dimensionIndex] = dimensionName; 77 | 78 | const data = upstream.cloneRawData() as OptionSourceDataArrayRows; 79 | 80 | // TODO: support objectRows 81 | for (let i = 0, len = data.length; i < len; i++) { 82 | const line = data[i]; 83 | line[dimensionIndex] = i; 84 | } 85 | 86 | return { 87 | dimensions: dimsDef, 88 | data: data 89 | }; 90 | } 91 | }; 92 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | .svn 15 | local.properties 16 | .classpath 17 | .class 18 | .settings/ 19 | .loadpath 20 | 21 | # External tool builders 22 | .externalToolBuilders/ 23 | 24 | # Locally stored "Eclipse launch configurations" 25 | *.launch 26 | 27 | # CDT-specific 28 | .cproject 29 | 30 | # PDT-specific 31 | .buildpath 32 | 33 | 34 | ################# 35 | ## Visual Studio 36 | ################# 37 | 38 | ## Ignore Visual Studio temporary files, build results, and 39 | ## files generated by popular Visual Studio add-ons. 40 | 41 | # User-specific files 42 | *.suo 43 | *.user 44 | *.sln.docstates 45 | 46 | # Build results 47 | [Dd]ebug/ 48 | [Rr]elease/ 49 | *_i.c 50 | *_p.c 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.vspscc 65 | .builds 66 | *.dotCover 67 | 68 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 69 | #packages/ 70 | 71 | # Visual C++ cache files 72 | ipch/ 73 | *.aps 74 | *.ncb 75 | *.opensdf 76 | *.sdf 77 | 78 | # Visual Studio profiler 79 | *.psess 80 | *.vsp 81 | 82 | # ReSharper is a .NET coding add-in 83 | _ReSharper* 84 | 85 | # Installshield output folder 86 | [Ee]xpress 87 | 88 | # DocProject is a documentation generator add-in 89 | DocProject/buildhelp/ 90 | DocProject/Help/*.HxT 91 | DocProject/Help/*.HxC 92 | DocProject/Help/*.hhc 93 | DocProject/Help/*.hhk 94 | DocProject/Help/*.hhp 95 | DocProject/Help/Html2 96 | DocProject/Help/html 97 | 98 | # Click-Once directory 99 | publish 100 | 101 | # Others 102 | [Bb]in 103 | [Oo]bj 104 | sql 105 | TestResults 106 | *.Cache 107 | ClientBin 108 | stylecop.* 109 | ~$* 110 | *.dbmdl 111 | Generated_Code #added for RIA/Silverlight projects 112 | 113 | # Backup & report files from converting an old project file to a newer 114 | # Visual Studio version. Backup files are not needed, because we have git ;-) 115 | _UpgradeReport_Files/ 116 | Backup*/ 117 | UpgradeLog*.XML 118 | 119 | 120 | 121 | ############ 122 | ## Windows 123 | ############ 124 | 125 | # Windows image file caches 126 | Thumbs.db 127 | 128 | # Folder config file 129 | Desktop.ini 130 | 131 | 132 | ############# 133 | ## Python 134 | ############# 135 | 136 | *.py[co] 137 | 138 | # Packages 139 | *.egg 140 | *.egg-info 141 | # dist 142 | eggs 143 | parts 144 | bin 145 | var 146 | sdist 147 | develop-eggs 148 | .installed.cfg 149 | 150 | # Installer logs 151 | pip-log.txt 152 | 153 | # Unit test / coverage reports 154 | coverage 155 | .coverage 156 | .tox 157 | 158 | #Translations 159 | *.mo 160 | 161 | #Mr Developer 162 | .mr.developer.cfg 163 | 164 | # Mac crap 165 | .DS_Store 166 | .idea 167 | .ideaout 168 | rat.iml 169 | 170 | node_modules 171 | 172 | pre-publish-tmp 173 | todo 174 | *.log 175 | *.sublime-workspace 176 | *.sublime-project 177 | 178 | *.tgz 179 | 180 | # Result of node.js perf 181 | *.asm 182 | -------------------------------------------------------------------------------- /dist/ecSimpleTransform.min.js: -------------------------------------------------------------------------------- 1 | !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ecSimpleTransform={})}(this,(function(e){"use strict";function n(e,n){if(!e)throw new Error(n)}function t(e,n){return e.hasOwnProperty(n)}var r={SUM:!0,COUNT:!0,FIRST:!0,AVERAGE:!0,Q1:!0,Q2:!0,Q3:!0,MIN:!0,MAX:!0},o={AVERAGE:["COUNT"]},i={Q1:!0,Q2:!0,Q3:!0},u={MEDIAN:"Q2"},a=function(){function e(e,n,t,r,o){this.collectionInfoList=[],this.gatheredValuesByGroup={},this.gatheredValuesNoGroup=[],this.needGatherValues=!1,this._collectionInfoMap={},this.method=t,this.name=r,this.index=e,this.indexInUpstream=n,this.needGatherValues=o}return e.prototype.addCollectionInfo=function(e){this._collectionInfoMap[e.method]=this.collectionInfoList.length,this.collectionInfoList.push(e)},e.prototype.getCollectionInfo=function(e){return this.collectionInfoList[this._collectionInfoMap[e]]},e.prototype.gatherValue=function(e,n,t){if(t=+t,e){if(null!=n){var r=n+"";(this.gatheredValuesByGroup[r]||(this.gatheredValuesByGroup[r]=[])).push(t)}}else this.gatheredValuesNoGroup.push(t)},e}(),l={type:"ecSimpleTransform:aggregate",transform:function(e){var r,u=e.upstream,l=e.config,p=function(e,t){var r,o=e.groupBy;null!=o&&n(r=t.getDimensionInfo(o),"Can not find dimension by `groupBy`: "+o);return r}(l,u),I=function(e,r,u){for(var l=e.resultDimensions,f=[],c=[],h=0,d=0;d = { 26 | [key: string]: T 27 | }; 28 | export type DimensionIndex = number; 29 | export type DimensionName = string; 30 | export type DimensionIndexLoose = DimensionIndex | string; 31 | export type DimensionLoose = DimensionName | DimensionIndexLoose; 32 | 33 | export type DataTransformType = string; 34 | export type DataTransformConfig = unknown; 35 | 36 | export type ParsedValue = ParsedValueNumeric | OrdinalRawValue; 37 | export type ParsedValueNumeric = number | OrdinalNumber; 38 | export type OrdinalRawValue = string | number; 39 | export type OrdinalNumber = number; 40 | 41 | export const SOURCE_FORMAT_ORIGINAL = 'original' as const; 42 | export const SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows' as const; 43 | export const SOURCE_FORMAT_OBJECT_ROWS = 'objectRows' as const; 44 | export const SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns' as const; 45 | export const SOURCE_FORMAT_TYPED_ARRAY = 'typedArray' as const; 46 | export const SOURCE_FORMAT_UNKNOWN = 'unknown' as const; 47 | 48 | export type SourceFormat = 49 | typeof SOURCE_FORMAT_ORIGINAL 50 | | typeof SOURCE_FORMAT_ARRAY_ROWS 51 | | typeof SOURCE_FORMAT_OBJECT_ROWS 52 | | typeof SOURCE_FORMAT_KEYED_COLUMNS 53 | | typeof SOURCE_FORMAT_TYPED_ARRAY 54 | | typeof SOURCE_FORMAT_UNKNOWN; 55 | 56 | const dataCtors = { 57 | 'float': typeof Float64Array === UNDEFINED 58 | ? Array : Float64Array, 59 | 'int': typeof Int32Array === UNDEFINED 60 | ? Array : Int32Array, 61 | // Ordinal data type can be string or int 62 | 'ordinal': Array, 63 | 'number': Array, 64 | 'time': Array 65 | }; 66 | export type ListDimensionType = keyof typeof dataCtors; 67 | export type DimensionDefinition = { 68 | type?: ListDimensionType, 69 | name?: DimensionName, 70 | displayName?: string 71 | }; 72 | export type DimensionDefinitionLoose = DimensionDefinition['name'] | DimensionDefinition; 73 | 74 | export interface DataTransformOption { 75 | type: DataTransformType; 76 | config: DataTransformConfig; 77 | // Print the result via `console.log` when transform performed. Only work in dev mode for debug. 78 | print?: boolean; 79 | } 80 | 81 | export type OptionDataValue = string | number | Date; 82 | 83 | export type OptionSourceDataArrayRows = 84 | Array>; 85 | export type OptionSourceDataObjectRows = 86 | Array>; 87 | 88 | export interface ExternalDataTransform { 89 | // Must include namespace like: 'ecStat:regression' 90 | type: string; 91 | __isBuiltIn?: boolean; 92 | transform: ( 93 | param: ExternalDataTransformParam 94 | ) => ExternalDataTransformResultItem | ExternalDataTransformResultItem[]; 95 | } 96 | 97 | interface ExternalDataTransformParam { 98 | // This is the first source in upstreamList. In most cases, 99 | // there is only one upstream source. 100 | upstream: ExternalSource; 101 | upstreamList: ExternalSource[]; 102 | config: TO['config']; 103 | } 104 | 105 | export interface ExternalDataTransformResultItem { 106 | /** 107 | * If `data` is null/undefined, inherit upstream data. 108 | */ 109 | data: OptionSourceDataArrayRows | OptionSourceDataObjectRows; 110 | /** 111 | * A `transform` can optionally return a dimensions definition. 112 | * The rule: 113 | * If this `transform result` have different dimensions from the upstream, it should return 114 | * a new dimension definition. For example, this transform inherit the upstream data totally 115 | * but add a extra dimension. 116 | * Otherwise, do not need to return that dimension definition. echarts will inherit dimension 117 | * definition from the upstream. 118 | */ 119 | dimensions?: DimensionDefinitionLoose[]; 120 | } 121 | 122 | export type DataTransformDataItem = ExternalDataTransformResultItem['data'][number]; 123 | 124 | export interface ExternalDimensionDefinition extends Partial { 125 | // Mandatory 126 | index: DimensionIndex; 127 | } 128 | 129 | export interface ExternalSource { 130 | sourceFormat: SourceFormat; 131 | getRawDataItem(dataIndex: number): number; 132 | getRawDataItem(dataIndex: number): DataTransformDataItem; 133 | cloneRawData(): OptionSourceDataArrayRows | OptionSourceDataObjectRows; 134 | getDimensionInfo(dim: DimensionLoose): ExternalDimensionDefinition; 135 | cloneAllDimensionInfo(): ExternalDimensionDefinition[]; 136 | count(): number; 137 | retrieveValue(dataIndex: number, dimIndex: DimensionIndex): OptionDataValue; 138 | retrieveValueFromItem(dataItem: DataTransformDataItem, dimIndex: DimensionIndex): OptionDataValue; 139 | convertValue(rawVal: unknown, dimInfo: ExternalDimensionDefinition): ParsedValue; 140 | } 141 | -------------------------------------------------------------------------------- /.eslintrc-common.yaml: -------------------------------------------------------------------------------- 1 | 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | # Note: 20 | # If eslint does not work in VSCode, please check: 21 | # (1) Whether "@typescript-eslint/eslint-plugin" and "@typescript-eslint/parser" 22 | # are npm installed locally. Should better in the same version. 23 | # (2) Whether "VSCode ESlint extension" is installed. 24 | # (3) If the project folder is not the root folder of your working space, please 25 | # config the "VSCode ESlint extension" in "settings": 26 | # ```json 27 | # "eslint.workingDirectories": [{"mode": "auto"}] 28 | # ``` 29 | # Note that it should be "workingDirectories" rather than "WorkingDirectories". 30 | 31 | rules: 32 | # Check the rules in: node_modules/@typescript-eslint/eslint-plugin/README.md 33 | no-console: 34 | - 2 35 | - 36 | allow: 37 | - "warn" 38 | - "error" 39 | prefer-const: 1 40 | no-constant-condition: 0 41 | comma-dangle: 2 42 | no-debugger: 2 43 | no-dupe-keys: 2 44 | no-empty-character-class: 2 45 | no-ex-assign: 2 46 | no-extra-boolean-cast: 0 47 | no-func-assign: 2 48 | no-inner-declarations: 2 49 | no-invalid-regexp: 2 50 | no-negated-in-lhs: 2 51 | no-obj-calls: 2 52 | no-sparse-arrays: 2 53 | no-unreachable: 2 54 | use-isnan: 2 55 | valid-typeof: 2 56 | block-scoped-var: 2 57 | curly: 58 | - 2 59 | - "all" 60 | eqeqeq: 61 | - 2 62 | - "allow-null" 63 | guard-for-in: 2 64 | no-else-return: 0 65 | no-labels: 66 | - 2 67 | - 68 | allowLoop: true 69 | no-eval: 2 70 | no-extend-native: 2 71 | no-extra-bind: 0 72 | no-implied-eval: 2 73 | no-iterator: 2 74 | no-irregular-whitespace: 2 75 | no-lone-blocks: 2 76 | no-loop-func: 2 77 | no-multi-str: 2 78 | no-native-reassign: 2 79 | no-new-wrappers: 2 80 | no-octal: 2 81 | no-octal-escape: 2 82 | no-proto: 2 83 | no-redeclare: 2 84 | no-self-compare: 2 85 | no-unneeded-ternary: 2 86 | no-with: 2 87 | radix: 2 88 | wrap-iife: 89 | - 2 90 | - "any" 91 | no-delete-var: 2 92 | no-dupe-args: 2 93 | no-duplicate-case: 2 94 | no-label-var: 2 95 | no-shadow-restricted-names: 2 96 | no-undef: 2 97 | no-undef-init: 2 98 | "no-use-before-define": "off" 99 | "@typescript-eslint/no-use-before-define": 0 100 | brace-style: 101 | - 2 102 | - "stroustrup" 103 | - {} 104 | comma-spacing: 105 | - 2 106 | - 107 | before: false 108 | after: true 109 | comma-style: 110 | - 2 111 | - "last" 112 | new-parens: 2 113 | no-array-constructor: 2 114 | no-multi-spaces: 115 | - 1 116 | - 117 | ignoreEOLComments: true 118 | exceptions: 119 | Property: true 120 | no-new-object: 2 121 | no-trailing-spaces: 2 122 | no-extra-parens: 123 | - 2 124 | - "functions" 125 | no-mixed-spaces-and-tabs: 2 126 | one-var: 127 | - 2 128 | - "never" 129 | operator-linebreak: 130 | - 2 131 | - "before" 132 | - 133 | overrides: 134 | "=": "after" 135 | "quotes": "off" 136 | "@typescript-eslint/quotes": 137 | - 2 138 | - "single" 139 | "semi": "off" 140 | "@typescript-eslint/semi": 141 | - 2 142 | - "always" 143 | semi-spacing: 2 144 | keyword-spacing: 2 145 | key-spacing: 146 | - 2 147 | - 148 | beforeColon: false 149 | afterColon: true 150 | "space-before-function-paren": "off" 151 | "@typescript-eslint/space-before-function-paren": 152 | - 2 153 | - 154 | anonymous: "always" 155 | named: "never" 156 | space-before-blocks: 157 | - 2 158 | - "always" 159 | computed-property-spacing: 160 | - 2 161 | - "never" 162 | space-in-parens: 163 | - 2 164 | - "never" 165 | space-unary-ops: 2 166 | spaced-comment: 0 167 | 168 | max-nested-callbacks: 169 | - 1 170 | - 5 171 | max-depth: 172 | - 1 173 | - 6 174 | max-len: 175 | - 2 176 | - 120 177 | - 4 178 | - 179 | ignoreUrls: true 180 | ignoreComments: true 181 | max-params: 182 | - 1 183 | - 15 184 | 185 | space-infix-ops: 2 186 | dot-notation: 187 | - 2 188 | - 189 | allowKeywords: true 190 | allowPattern: "^catch$" 191 | 192 | arrow-spacing: 2 193 | constructor-super: 2 194 | no-confusing-arrow: 195 | - 2 196 | - 197 | allowParens: true 198 | no-class-assign: 2 199 | no-const-assign: 2 200 | # no-dupe-class-members: 2 201 | no-this-before-super: 0 202 | no-var: 2 203 | no-duplicate-imports: 2 204 | prefer-rest-params: 0 205 | unicode-bom: 2 206 | max-statements-per-line: 2 207 | 208 | no-useless-constructor: 0 209 | 210 | "func-call-spacing": "off" 211 | "@typescript-eslint/func-call-spacing": "error" 212 | 213 | "no-unused-vars": "off" 214 | "@typescript-eslint/no-unused-vars": 215 | - 1 216 | - 217 | vars: "local" 218 | args: "none" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /dist/ecSimpleTransform.js: -------------------------------------------------------------------------------- 1 | (function (global, factory) { 2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : 3 | typeof define === 'function' && define.amd ? define(['exports'], factory) : 4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ecSimpleTransform = {})); 5 | }(this, (function (exports) { 'use strict'; 6 | 7 | var transform = { 8 | type: 'ecSimpleTransform:id', 9 | transform: function (params) { 10 | var upstream = params.upstream; 11 | var config = params.config; 12 | var dimensionIndex = config.dimensionIndex; 13 | var dimensionName = config.dimensionName; 14 | var dimsDef = upstream.cloneAllDimensionInfo(); 15 | dimsDef[dimensionIndex] = dimensionName; 16 | var data = upstream.cloneRawData(); 17 | for (var i = 0, len = data.length; i < len; i++) { 18 | var line = data[i]; 19 | line[dimensionIndex] = i; 20 | } 21 | return { 22 | dimensions: dimsDef, 23 | data: data 24 | }; 25 | } 26 | }; 27 | 28 | function assert(condition, message) { 29 | if (!condition) { 30 | throw new Error(message); 31 | } 32 | } 33 | function hasOwn(own, prop) { 34 | return own.hasOwnProperty(prop); 35 | } 36 | function quantile(ascArr, p) { 37 | var H = (ascArr.length - 1) * p + 1; 38 | var h = Math.floor(H); 39 | var v = +ascArr[h - 1]; 40 | var e = H - h; 41 | return e ? v + e * (ascArr[h] - v) : v; 42 | } 43 | 44 | var METHOD_INTERNAL = { 45 | 'SUM': true, 46 | 'COUNT': true, 47 | 'FIRST': true, 48 | 'AVERAGE': true, 49 | 'Q1': true, 50 | 'Q2': true, 51 | 'Q3': true, 52 | 'MIN': true, 53 | 'MAX': true 54 | }; 55 | var METHOD_NEEDS_COLLECT = { 56 | AVERAGE: ['COUNT'] 57 | }; 58 | var METHOD_NEEDS_GATHER_VALUES = { 59 | Q1: true, 60 | Q2: true, 61 | Q3: true 62 | }; 63 | var METHOD_ALIAS = { 64 | MEDIAN: 'Q2' 65 | }; 66 | var ResultDimInfoInternal = (function () { 67 | function ResultDimInfoInternal(index, indexInUpstream, method, name, needGatherValues) { 68 | this.collectionInfoList = []; 69 | this.gatheredValuesByGroup = {}; 70 | this.gatheredValuesNoGroup = []; 71 | this.needGatherValues = false; 72 | this._collectionInfoMap = {}; 73 | this.method = method; 74 | this.name = name; 75 | this.index = index; 76 | this.indexInUpstream = indexInUpstream; 77 | this.needGatherValues = needGatherValues; 78 | } 79 | ResultDimInfoInternal.prototype.addCollectionInfo = function (item) { 80 | this._collectionInfoMap[item.method] = this.collectionInfoList.length; 81 | this.collectionInfoList.push(item); 82 | }; 83 | ResultDimInfoInternal.prototype.getCollectionInfo = function (method) { 84 | return this.collectionInfoList[this._collectionInfoMap[method]]; 85 | }; 86 | ResultDimInfoInternal.prototype.gatherValue = function (groupByDimInfo, groupVal, value) { 87 | value = +value; 88 | if (groupByDimInfo) { 89 | if (groupVal != null) { 90 | var groupValStr = groupVal + ''; 91 | var values = this.gatheredValuesByGroup[groupValStr] 92 | || (this.gatheredValuesByGroup[groupValStr] = []); 93 | values.push(value); 94 | } 95 | } 96 | else { 97 | this.gatheredValuesNoGroup.push(value); 98 | } 99 | }; 100 | return ResultDimInfoInternal; 101 | }()); 102 | var transform$1 = { 103 | type: 'ecSimpleTransform:aggregate', 104 | transform: function (params) { 105 | var upstream = params.upstream; 106 | var config = params.config; 107 | var groupByDimInfo = prepareGroupByDimInfo(config, upstream); 108 | var _a = prepareDimensions(config, upstream, groupByDimInfo), finalResultDimInfoList = _a.finalResultDimInfoList, collectionDimInfoList = _a.collectionDimInfoList; 109 | var collectionResult; 110 | if (collectionDimInfoList.length) { 111 | collectionResult = travel(groupByDimInfo, upstream, collectionDimInfoList, createCollectionResultLine, updateCollectionResultLine); 112 | } 113 | for (var i = 0; i < collectionDimInfoList.length; i++) { 114 | var dimInfo = collectionDimInfoList[i]; 115 | dimInfo.__collectionResult = collectionResult; 116 | asc(dimInfo.gatheredValuesNoGroup); 117 | var gatheredValuesByGroup = dimInfo.gatheredValuesByGroup; 118 | for (var key in gatheredValuesByGroup) { 119 | if (hasOwn(gatheredValuesByGroup, key)) { 120 | asc(gatheredValuesByGroup[key]); 121 | } 122 | } 123 | } 124 | var finalResult = travel(groupByDimInfo, upstream, finalResultDimInfoList, createFinalResultLine, updateFinalResultLine); 125 | var dimensions = []; 126 | for (var i = 0; i < finalResultDimInfoList.length; i++) { 127 | dimensions.push(finalResultDimInfoList[i].name); 128 | } 129 | return { 130 | dimensions: dimensions, 131 | data: finalResult.outList 132 | }; 133 | } 134 | }; 135 | function prepareDimensions(config, upstream, groupByDimInfo) { 136 | var resultDimensionsConfig = config.resultDimensions; 137 | var finalResultDimInfoList = []; 138 | var collectionDimInfoList = []; 139 | var gIndexInLine = 0; 140 | for (var i = 0; i < resultDimensionsConfig.length; i++) { 141 | var resultDimInfoConfig = resultDimensionsConfig[i]; 142 | var dimInfoInUpstream = upstream.getDimensionInfo(resultDimInfoConfig.from); 143 | assert(dimInfoInUpstream, 'Can not find dimension by `from`: ' + resultDimInfoConfig.from); 144 | var rawMethod = resultDimInfoConfig.method; 145 | assert(groupByDimInfo.index !== dimInfoInUpstream.index || rawMethod == null, "Dimension " + dimInfoInUpstream.name + " is the \"groupBy\" dimension, must not have any \"method\"."); 146 | var method = normalizeMethod(rawMethod); 147 | assert(method, 'method is required'); 148 | var name_1 = resultDimInfoConfig.name != null ? resultDimInfoConfig.name : dimInfoInUpstream.name; 149 | var finalResultDimInfo = new ResultDimInfoInternal(finalResultDimInfoList.length, dimInfoInUpstream.index, method, name_1, hasOwn(METHOD_NEEDS_GATHER_VALUES, method)); 150 | finalResultDimInfoList.push(finalResultDimInfo); 151 | var needCollect = false; 152 | if (hasOwn(METHOD_NEEDS_COLLECT, method)) { 153 | needCollect = true; 154 | var collectionTargetMethods = METHOD_NEEDS_COLLECT[method]; 155 | for (var j = 0; j < collectionTargetMethods.length; j++) { 156 | finalResultDimInfo.addCollectionInfo({ 157 | method: collectionTargetMethods[j], 158 | indexInLine: gIndexInLine++ 159 | }); 160 | } 161 | } 162 | if (hasOwn(METHOD_NEEDS_GATHER_VALUES, method)) { 163 | needCollect = true; 164 | } 165 | if (needCollect) { 166 | collectionDimInfoList.push(finalResultDimInfo); 167 | } 168 | } 169 | return { collectionDimInfoList: collectionDimInfoList, finalResultDimInfoList: finalResultDimInfoList }; 170 | } 171 | function prepareGroupByDimInfo(config, upstream) { 172 | var groupByConfig = config.groupBy; 173 | var groupByDimInfo; 174 | if (groupByConfig != null) { 175 | groupByDimInfo = upstream.getDimensionInfo(groupByConfig); 176 | assert(groupByDimInfo, 'Can not find dimension by `groupBy`: ' + groupByConfig); 177 | } 178 | return groupByDimInfo; 179 | } 180 | function travel(groupByDimInfo, upstream, resultDimInfoList, doCreate, doUpdate) { 181 | var outList = []; 182 | var mapByGroup; 183 | if (groupByDimInfo) { 184 | mapByGroup = {}; 185 | for (var dataIndex = 0, len = upstream.count(); dataIndex < len; dataIndex++) { 186 | var groupByVal = upstream.retrieveValue(dataIndex, groupByDimInfo.index); 187 | if (groupByVal == null) { 188 | continue; 189 | } 190 | var groupByValStr = groupByVal + ''; 191 | if (!hasOwn(mapByGroup, groupByValStr)) { 192 | var newLine = doCreate(upstream, dataIndex, resultDimInfoList, groupByDimInfo, groupByVal); 193 | outList.push(newLine); 194 | mapByGroup[groupByValStr] = newLine; 195 | } 196 | else { 197 | var targetLine = mapByGroup[groupByValStr]; 198 | doUpdate(upstream, dataIndex, targetLine, resultDimInfoList, groupByDimInfo, groupByVal); 199 | } 200 | } 201 | } 202 | else { 203 | var targetLine = doCreate(upstream, 0, resultDimInfoList); 204 | outList.push(targetLine); 205 | for (var dataIndex = 1, len = upstream.count(); dataIndex < len; dataIndex++) { 206 | doUpdate(upstream, dataIndex, targetLine, resultDimInfoList); 207 | } 208 | } 209 | return { mapByGroup: mapByGroup, outList: outList }; 210 | } 211 | function normalizeMethod(method) { 212 | if (method == null) { 213 | return 'FIRST'; 214 | } 215 | var methodInternal = method.toUpperCase(); 216 | methodInternal = hasOwn(METHOD_ALIAS, methodInternal) 217 | ? METHOD_ALIAS[methodInternal] 218 | : methodInternal; 219 | assert(hasOwn(METHOD_INTERNAL, methodInternal), "Illegal method " + method + "."); 220 | return methodInternal; 221 | } 222 | var createCollectionResultLine = function (upstream, dataIndex, collectionDimInfoList, groupByDimInfo, groupByVal) { 223 | var newLine = []; 224 | for (var i = 0; i < collectionDimInfoList.length; i++) { 225 | var dimInfo = collectionDimInfoList[i]; 226 | var collectionInfoList = dimInfo.collectionInfoList; 227 | for (var j = 0; j < collectionInfoList.length; j++) { 228 | var collectionInfo = collectionInfoList[j]; 229 | newLine[collectionInfo.indexInLine] = +lineCreator[collectionInfo.method](upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal); 230 | } 231 | if (dimInfo.needGatherValues) { 232 | var val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 233 | dimInfo.gatherValue(groupByDimInfo, groupByVal, val); 234 | } 235 | } 236 | return newLine; 237 | }; 238 | var updateCollectionResultLine = function (upstream, dataIndex, targetLine, collectionDimInfoList, groupByDimInfo, groupByVal) { 239 | for (var i = 0; i < collectionDimInfoList.length; i++) { 240 | var dimInfo = collectionDimInfoList[i]; 241 | var collectionInfoList = dimInfo.collectionInfoList; 242 | for (var j = 0; j < collectionInfoList.length; j++) { 243 | var collectionInfo = collectionInfoList[j]; 244 | var indexInLine = collectionInfo.indexInLine; 245 | targetLine[indexInLine] = +lineUpdater[collectionInfo.method](targetLine[indexInLine], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal); 246 | } 247 | if (dimInfo.needGatherValues) { 248 | var val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 249 | dimInfo.gatherValue(groupByDimInfo, groupByVal, val); 250 | } 251 | } 252 | }; 253 | var createFinalResultLine = function (upstream, dataIndex, finalResultDimInfoList, groupByDimInfo, groupByVal) { 254 | var newLine = []; 255 | for (var i = 0; i < finalResultDimInfoList.length; i++) { 256 | var dimInfo = finalResultDimInfoList[i]; 257 | var method = dimInfo.method; 258 | newLine[i] = isGroupByDimension(groupByDimInfo, dimInfo) 259 | ? groupByVal 260 | : lineCreator[method](upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal); 261 | } 262 | return newLine; 263 | }; 264 | var updateFinalResultLine = function (upstream, dataIndex, targetLine, finalResultDimInfoList, groupByDimInfo, groupByVal) { 265 | for (var i = 0; i < finalResultDimInfoList.length; i++) { 266 | var dimInfo = finalResultDimInfoList[i]; 267 | if (isGroupByDimension(groupByDimInfo, dimInfo)) { 268 | continue; 269 | } 270 | var method = dimInfo.method; 271 | targetLine[i] = lineUpdater[method](targetLine[i], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal); 272 | } 273 | }; 274 | function isGroupByDimension(groupByDimInfo, targetDimInfo) { 275 | return groupByDimInfo && targetDimInfo.indexInUpstream === groupByDimInfo.index; 276 | } 277 | function asc(list) { 278 | list.sort(function (a, b) { 279 | return a - b; 280 | }); 281 | } 282 | var lineCreator = { 283 | 'SUM': function () { 284 | return 0; 285 | }, 286 | 'COUNT': function () { 287 | return 1; 288 | }, 289 | 'FIRST': function (upstream, dataIndex, dimInfo) { 290 | return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 291 | }, 292 | 'MIN': function (upstream, dataIndex, dimInfo) { 293 | return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 294 | }, 295 | 'MAX': function (upstream, dataIndex, dimInfo) { 296 | return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 297 | }, 298 | 'AVERAGE': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 299 | var collectLine = groupByDimInfo 300 | ? dimInfo.__collectionResult.mapByGroup[groupByVal + ''] 301 | : dimInfo.__collectionResult.outList[0]; 302 | return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) 303 | / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine]; 304 | }, 305 | 'Q1': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 306 | return lineCreatorForQ(0.25, dimInfo, groupByDimInfo, groupByVal); 307 | }, 308 | 'Q2': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 309 | return lineCreatorForQ(0.5, dimInfo, groupByDimInfo, groupByVal); 310 | }, 311 | 'Q3': function (upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 312 | return lineCreatorForQ(0.75, dimInfo, groupByDimInfo, groupByVal); 313 | } 314 | }; 315 | var lineUpdater = { 316 | 'SUM': function (val, upstream, dataIndex, dimInfo) { 317 | return val + upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 318 | }, 319 | 'COUNT': function (val) { 320 | return val + 1; 321 | }, 322 | 'FIRST': function (val) { 323 | return val; 324 | }, 325 | 'MIN': function (val, upstream, dataIndex, dimInfo) { 326 | return Math.min(val, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream)); 327 | }, 328 | 'MAX': function (val, upstream, dataIndex, dimInfo) { 329 | return Math.max(val, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream)); 330 | }, 331 | 'AVERAGE': function (val, upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 332 | var collectLine = groupByDimInfo 333 | ? dimInfo.__collectionResult.mapByGroup[groupByVal + ''] 334 | : dimInfo.__collectionResult.outList[0]; 335 | return val 336 | + upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) 337 | / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine]; 338 | }, 339 | 'Q1': function (val, upstream, dataIndex, dimInfo) { 340 | return val; 341 | }, 342 | 'Q2': function (val, upstream, dataIndex, dimInfo) { 343 | return val; 344 | }, 345 | 'Q3': function (val, upstream, dataIndex, dimInfo) { 346 | return val; 347 | } 348 | }; 349 | function lineCreatorForQ(percent, dimInfo, groupByDimInfo, groupByVal) { 350 | var gatheredValues = groupByDimInfo 351 | ? dimInfo.gatheredValuesByGroup[groupByVal + ''] 352 | : dimInfo.gatheredValuesNoGroup; 353 | return quantile(gatheredValues, percent); 354 | } 355 | 356 | exports.aggregate = transform$1; 357 | exports.id = transform; 358 | 359 | Object.defineProperty(exports, '__esModule', { value: true }); 360 | 361 | }))); 362 | //# sourceMappingURL=ecSimpleTransform.js.map 363 | -------------------------------------------------------------------------------- /src/aggregate.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | import { 21 | DataTransformOption, DimensionLoose, DimensionName, ExternalDataTransform, 22 | ExternalDimensionDefinition, ExternalSource, OptionDataValue 23 | } from './types'; 24 | import { assert, hasOwn, quantile } from './util'; 25 | 26 | /** 27 | * @usage 28 | * 29 | * ```js 30 | * dataset: [{ 31 | * source: [ 32 | * ['aa', 'bb', 'cc', 'tag'], 33 | * [12, 0.33, 5200, 'AA'], 34 | * [21, 0.65, 7100, 'AA'], 35 | * [51, 0.15, 1100, 'BB'], 36 | * [71, 0.75, 9100, 'BB'], 37 | * ... 38 | * ] 39 | * }, { 40 | * transform: { 41 | * type: 'ecSimpleTransform:aggregate', 42 | * config: { 43 | * resultDimensions: [ 44 | * // by default, use the same name with `from`. 45 | * { from: 'aa', method: 'sum' }, 46 | * { from: 'bb', method: 'count' }, 47 | * { from: 'cc' }, // method by default: use the first value. 48 | * { from: 'dd', method: 'Q1' }, 49 | * { from: 'tag' } 50 | * ], 51 | * groupBy: 'tag' 52 | * } 53 | * } 54 | * // Then the result data will be: 55 | * // [ 56 | * // ['aa', 'bb', 'cc', 'tag'], 57 | * // [12, 0.33, 5200, 'AA'], 58 | * // [21, 0.65, 8100, 'BB'], 59 | * // ... 60 | * // ] 61 | * }] 62 | * ``` 63 | */ 64 | 65 | export interface AggregateTransformOption extends DataTransformOption { 66 | type: 'ecSimpleTransform:aggregate'; 67 | config: { 68 | // Mandatory 69 | resultDimensions: { 70 | // Optional. The name of the result dimensions. 71 | // If not provided, inherit the name from `from`. 72 | name: DimensionName; 73 | // Mandatory. `from` is used to reference dimension from `source`. 74 | from: DimensionLoose; 75 | // Optional. Aggregate method. Currently only these method supported. 76 | // If not provided, use `'first'`. 77 | method: AggregateMethodLoose; 78 | }[]; 79 | // Optional 80 | groupBy: DimensionLoose; 81 | }; 82 | } 83 | 84 | const METHOD_INTERNAL = { 85 | 'SUM': true, 86 | 'COUNT': true, 87 | 'FIRST': true, 88 | 'AVERAGE': true, 89 | 'Q1': true, 90 | 'Q2': true, 91 | 'Q3': true, 92 | 'MIN': true, 93 | 'MAX': true 94 | } as const; 95 | const METHOD_NEEDS_COLLECT = { 96 | AVERAGE: ['COUNT'] 97 | } as const; 98 | const METHOD_NEEDS_GATHER_VALUES = { 99 | Q1: true, 100 | Q2: true, 101 | Q3: true 102 | } as const; 103 | const METHOD_ALIAS = { 104 | MEDIAN: 'Q2' 105 | } as const; 106 | 107 | type AggregateMethodLoose = 108 | AggregateMethodInternal 109 | | 'sum' | 'count' | 'first' | 'average' | 'Q1' | 'Q2' | 'Q3' | 'median' | 'min' | 'max'; 110 | type AggregateMethodInternal = keyof typeof METHOD_INTERNAL; 111 | 112 | 113 | class ResultDimInfoInternal { 114 | 115 | readonly method: AggregateMethodInternal; 116 | readonly name: DimensionName; 117 | readonly index: number; 118 | readonly indexInUpstream: number; 119 | 120 | readonly collectionInfoList = [] as { 121 | method: AggregateMethodInternal; 122 | indexInLine: number; 123 | }[]; 124 | 125 | // FIXME: refactor 126 | readonly gatheredValuesByGroup: { [groupVal: string]: number[] } = {}; 127 | readonly gatheredValuesNoGroup = [] as number[]; 128 | readonly needGatherValues: boolean = false; 129 | 130 | __collectionResult: TravelResult; 131 | 132 | private _collectionInfoMap = {} as { 133 | // number is the index of `list` 134 | [method in AggregateMethodInternal]: number 135 | }; 136 | 137 | constructor( 138 | index: number, 139 | indexInUpstream: number, 140 | method: AggregateMethodInternal, 141 | name: DimensionName, 142 | needGatherValues: boolean 143 | ) { 144 | this.method = method; 145 | this.name = name; 146 | this.index = index; 147 | this.indexInUpstream = indexInUpstream; 148 | this.needGatherValues = needGatherValues; 149 | } 150 | 151 | addCollectionInfo(item: ResultDimInfoInternal['collectionInfoList'][number]) { 152 | this._collectionInfoMap[item.method] = this.collectionInfoList.length; 153 | this.collectionInfoList.push(item); 154 | } 155 | 156 | getCollectionInfo(method: AggregateMethodInternal) { 157 | return this.collectionInfoList[this._collectionInfoMap[method]]; 158 | } 159 | 160 | // FIXME: temp implementation. Need refactor. 161 | gatherValue(groupByDimInfo: ExternalDimensionDefinition, groupVal: OptionDataValue, value: OptionDataValue) { 162 | // FIXME: convert to number compulsorily temporarily. 163 | value = +value; 164 | if (groupByDimInfo) { 165 | if (groupVal != null) { 166 | const groupValStr = groupVal + ''; 167 | const values = this.gatheredValuesByGroup[groupValStr] 168 | || (this.gatheredValuesByGroup[groupValStr] = []); 169 | values.push(value); 170 | } 171 | } 172 | else { 173 | this.gatheredValuesNoGroup.push(value); 174 | } 175 | } 176 | } 177 | 178 | type CreateInTravel = ( 179 | upstream: ExternalSource, 180 | dataIndex: number, 181 | dimInfoList: ResultDimInfoInternal[], 182 | groupByDimInfo?: ExternalDimensionDefinition, 183 | groupByVal?: OptionDataValue 184 | ) => LINE; 185 | type UpdateInTravel = ( 186 | upstream: ExternalSource, 187 | dataIndex: number, 188 | targetLine: LINE, 189 | dimInfoList: ResultDimInfoInternal[], 190 | groupByDimInfo?: ExternalDimensionDefinition, 191 | groupByVal?: OptionDataValue 192 | ) => void; 193 | 194 | export const transform: ExternalDataTransform = { 195 | 196 | type: 'ecSimpleTransform:aggregate', 197 | 198 | transform: function (params) { 199 | const upstream = params.upstream; 200 | const config = params.config; 201 | 202 | const groupByDimInfo = prepareGroupByDimInfo(config, upstream); 203 | const { finalResultDimInfoList, collectionDimInfoList } = prepareDimensions( 204 | config, upstream, groupByDimInfo 205 | ); 206 | 207 | // Collect 208 | let collectionResult: TravelResult; 209 | if (collectionDimInfoList.length) { 210 | collectionResult = travel( 211 | groupByDimInfo, 212 | upstream, 213 | collectionDimInfoList, 214 | createCollectionResultLine, 215 | updateCollectionResultLine 216 | ); 217 | } 218 | 219 | for (let i = 0; i < collectionDimInfoList.length; i++) { 220 | const dimInfo = collectionDimInfoList[i]; 221 | dimInfo.__collectionResult = collectionResult; 222 | // FIXME: just for Q1, Q2, Q3: need asc. 223 | asc(dimInfo.gatheredValuesNoGroup); 224 | 225 | const gatheredValuesByGroup = dimInfo.gatheredValuesByGroup; 226 | for (const key in gatheredValuesByGroup) { 227 | if (hasOwn(gatheredValuesByGroup, key)) { 228 | asc(gatheredValuesByGroup[key]); 229 | } 230 | } 231 | } 232 | 233 | // Calculate 234 | const finalResult = travel( 235 | groupByDimInfo, 236 | upstream, 237 | finalResultDimInfoList, 238 | createFinalResultLine, 239 | updateFinalResultLine 240 | ); 241 | 242 | const dimensions = []; 243 | for (let i = 0; i < finalResultDimInfoList.length; i++) { 244 | dimensions.push(finalResultDimInfoList[i].name); 245 | } 246 | 247 | return { 248 | dimensions: dimensions, 249 | data: finalResult.outList 250 | }; 251 | } 252 | }; 253 | 254 | function prepareDimensions( 255 | config: AggregateTransformOption['config'], 256 | upstream: ExternalSource, 257 | groupByDimInfo: ExternalDimensionDefinition 258 | ): { 259 | finalResultDimInfoList: ResultDimInfoInternal[]; 260 | collectionDimInfoList: ResultDimInfoInternal[]; 261 | } { 262 | const resultDimensionsConfig = config.resultDimensions; 263 | const finalResultDimInfoList: ResultDimInfoInternal[] = []; 264 | const collectionDimInfoList: ResultDimInfoInternal[] = []; 265 | let gIndexInLine = 0; 266 | 267 | for (let i = 0; i < resultDimensionsConfig.length; i++) { 268 | const resultDimInfoConfig = resultDimensionsConfig[i]; 269 | 270 | const dimInfoInUpstream = upstream.getDimensionInfo(resultDimInfoConfig.from); 271 | assert(dimInfoInUpstream, 'Can not find dimension by `from`: ' + resultDimInfoConfig.from); 272 | 273 | const rawMethod = resultDimInfoConfig.method; 274 | 275 | assert( 276 | groupByDimInfo.index !== dimInfoInUpstream.index || rawMethod == null, 277 | `Dimension ${dimInfoInUpstream.name} is the "groupBy" dimension, must not have any "method".` 278 | ); 279 | 280 | const method = normalizeMethod(rawMethod); 281 | assert(method, 'method is required'); 282 | 283 | const name = resultDimInfoConfig.name != null ? resultDimInfoConfig.name : dimInfoInUpstream.name; 284 | 285 | const finalResultDimInfo = new ResultDimInfoInternal( 286 | finalResultDimInfoList.length, 287 | dimInfoInUpstream.index, 288 | method, 289 | name, 290 | hasOwn(METHOD_NEEDS_GATHER_VALUES, method) 291 | ); 292 | finalResultDimInfoList.push(finalResultDimInfo); 293 | 294 | // For collection. 295 | let needCollect = false; 296 | if (hasOwn(METHOD_NEEDS_COLLECT, method)) { 297 | needCollect = true; 298 | const collectionTargetMethods = METHOD_NEEDS_COLLECT[method as keyof typeof METHOD_NEEDS_COLLECT]; 299 | for (let j = 0; j < collectionTargetMethods.length; j++) { 300 | finalResultDimInfo.addCollectionInfo({ 301 | method: collectionTargetMethods[j], 302 | indexInLine: gIndexInLine++ 303 | }); 304 | } 305 | } 306 | if (hasOwn(METHOD_NEEDS_GATHER_VALUES, method)) { 307 | needCollect = true; 308 | } 309 | if (needCollect) { 310 | collectionDimInfoList.push(finalResultDimInfo); 311 | } 312 | } 313 | 314 | return { collectionDimInfoList, finalResultDimInfoList }; 315 | } 316 | 317 | function prepareGroupByDimInfo( 318 | config: AggregateTransformOption['config'], 319 | upstream: ExternalSource 320 | ): ExternalDimensionDefinition { 321 | const groupByConfig = config.groupBy; 322 | let groupByDimInfo; 323 | if (groupByConfig != null) { 324 | groupByDimInfo = upstream.getDimensionInfo(groupByConfig); 325 | assert(groupByDimInfo, 'Can not find dimension by `groupBy`: ' + groupByConfig); 326 | } 327 | return groupByDimInfo; 328 | } 329 | 330 | interface TravelResult { 331 | mapByGroup: { [groupVal: string]: LINE }; 332 | outList: LINE[]; 333 | } 334 | 335 | function travel( 336 | groupByDimInfo: ExternalDimensionDefinition, 337 | upstream: ExternalSource, 338 | resultDimInfoList: ResultDimInfoInternal[], 339 | doCreate: CreateInTravel, 340 | doUpdate: UpdateInTravel 341 | ): TravelResult { 342 | const outList: TravelResult['outList'] = []; 343 | let mapByGroup: TravelResult['mapByGroup']; 344 | 345 | if (groupByDimInfo) { 346 | mapByGroup = {}; 347 | 348 | for (let dataIndex = 0, len = upstream.count(); dataIndex < len; dataIndex++) { 349 | const groupByVal = upstream.retrieveValue(dataIndex, groupByDimInfo.index); 350 | 351 | // PENDING: when value is null/undefined 352 | if (groupByVal == null) { 353 | continue; 354 | } 355 | 356 | const groupByValStr = groupByVal + ''; 357 | 358 | if (!hasOwn(mapByGroup, groupByValStr)) { 359 | const newLine = doCreate(upstream, dataIndex, resultDimInfoList, groupByDimInfo, groupByVal); 360 | outList.push(newLine); 361 | mapByGroup[groupByValStr] = newLine; 362 | } 363 | else { 364 | const targetLine = mapByGroup[groupByValStr]; 365 | doUpdate(upstream, dataIndex, targetLine, resultDimInfoList, groupByDimInfo, groupByVal); 366 | } 367 | } 368 | } 369 | else { 370 | const targetLine = doCreate(upstream, 0, resultDimInfoList); 371 | outList.push(targetLine); 372 | for (let dataIndex = 1, len = upstream.count(); dataIndex < len; dataIndex++) { 373 | doUpdate(upstream, dataIndex, targetLine, resultDimInfoList); 374 | } 375 | } 376 | 377 | return { mapByGroup, outList }; 378 | } 379 | 380 | function normalizeMethod(method: AggregateMethodLoose): AggregateMethodInternal { 381 | if (method == null) { 382 | return 'FIRST'; 383 | } 384 | let methodInternal = method.toUpperCase() as AggregateMethodInternal; 385 | methodInternal = hasOwn(METHOD_ALIAS, methodInternal) 386 | ? METHOD_ALIAS[methodInternal as keyof typeof METHOD_ALIAS] 387 | : methodInternal; 388 | assert(hasOwn(METHOD_INTERNAL, methodInternal), `Illegal method ${method}.`); 389 | return methodInternal; 390 | } 391 | 392 | 393 | 394 | type CollectionResultLine = number[]; 395 | 396 | const createCollectionResultLine: CreateInTravel = ( 397 | upstream, dataIndex, collectionDimInfoList, groupByDimInfo, groupByVal 398 | ) => { 399 | const newLine = [] as number[]; 400 | for (let i = 0; i < collectionDimInfoList.length; i++) { 401 | const dimInfo = collectionDimInfoList[i]; 402 | const collectionInfoList = dimInfo.collectionInfoList; 403 | for (let j = 0; j < collectionInfoList.length; j++) { 404 | const collectionInfo = collectionInfoList[j]; 405 | // FIXME: convert to number compulsorily temporarily. 406 | newLine[collectionInfo.indexInLine] = +lineCreator[collectionInfo.method]( 407 | upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal 408 | ); 409 | } 410 | // FIXME: refactor 411 | if (dimInfo.needGatherValues) { 412 | const val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 413 | dimInfo.gatherValue(groupByDimInfo, groupByVal, val); 414 | } 415 | } 416 | return newLine; 417 | }; 418 | 419 | const updateCollectionResultLine: UpdateInTravel = ( 420 | upstream, dataIndex, targetLine: number[], collectionDimInfoList, groupByDimInfo, groupByVal 421 | ) => { 422 | for (let i = 0; i < collectionDimInfoList.length; i++) { 423 | const dimInfo = collectionDimInfoList[i]; 424 | const collectionInfoList = dimInfo.collectionInfoList; 425 | for (let j = 0; j < collectionInfoList.length; j++) { 426 | const collectionInfo = collectionInfoList[j]; 427 | const indexInLine = collectionInfo.indexInLine; 428 | // FIXME: convert to number compulsorily temporarily. 429 | targetLine[indexInLine] = +lineUpdater[collectionInfo.method]( 430 | targetLine[indexInLine], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal 431 | ); 432 | } 433 | // FIXME: refactor 434 | if (dimInfo.needGatherValues) { 435 | const val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 436 | dimInfo.gatherValue(groupByDimInfo, groupByVal, val); 437 | } 438 | } 439 | }; 440 | 441 | 442 | 443 | type FinalResultLine = OptionDataValue[]; 444 | 445 | const createFinalResultLine: CreateInTravel = ( 446 | upstream, dataIndex, finalResultDimInfoList, groupByDimInfo, groupByVal 447 | ) => { 448 | const newLine = []; 449 | for (let i = 0; i < finalResultDimInfoList.length; i++) { 450 | const dimInfo = finalResultDimInfoList[i]; 451 | const method = dimInfo.method; 452 | newLine[i] = isGroupByDimension(groupByDimInfo, dimInfo) 453 | ? groupByVal 454 | : lineCreator[method]( 455 | upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal 456 | ); 457 | } 458 | return newLine; 459 | }; 460 | 461 | const updateFinalResultLine: UpdateInTravel = ( 462 | upstream, dataIndex, targetLine, finalResultDimInfoList, groupByDimInfo, groupByVal 463 | ) => { 464 | for (let i = 0; i < finalResultDimInfoList.length; i++) { 465 | const dimInfo = finalResultDimInfoList[i]; 466 | if (isGroupByDimension(groupByDimInfo, dimInfo)) { 467 | continue; 468 | } 469 | const method = dimInfo.method; 470 | targetLine[i] = lineUpdater[method]( 471 | targetLine[i], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal 472 | ); 473 | } 474 | }; 475 | 476 | function isGroupByDimension( 477 | groupByDimInfo: ExternalDimensionDefinition, 478 | targetDimInfo: ResultDimInfoInternal 479 | ): boolean { 480 | return groupByDimInfo && targetDimInfo.indexInUpstream === groupByDimInfo.index; 481 | } 482 | 483 | function asc(list: number[]) { 484 | list.sort((a, b) => { 485 | return a - b; 486 | }); 487 | } 488 | 489 | const lineCreator: { 490 | [key in AggregateMethodInternal]: ( 491 | upstream: ExternalSource, 492 | dataIndex: number, 493 | dimInfo: ResultDimInfoInternal, 494 | groupByDimInfo: ExternalDimensionDefinition, 495 | groupByVal: OptionDataValue 496 | ) => OptionDataValue 497 | } = { 498 | 'SUM'(upstream, dataIndex, dimInfo) { 499 | return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 500 | }, 501 | 'COUNT'() { 502 | return 1; 503 | }, 504 | 'FIRST'(upstream, dataIndex, dimInfo) { 505 | return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 506 | }, 507 | 'MIN'(upstream, dataIndex, dimInfo) { 508 | return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 509 | }, 510 | 'MAX'(upstream, dataIndex, dimInfo) { 511 | return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream); 512 | }, 513 | 'AVERAGE'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 514 | // FIXME: refactor, bad implementation. 515 | const collectLine = groupByDimInfo 516 | ? dimInfo.__collectionResult.mapByGroup[groupByVal + ''] 517 | : dimInfo.__collectionResult.outList[0]; 518 | return (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number) 519 | / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine]; 520 | }, 521 | // FIXME: refactor 522 | 'Q1'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 523 | return lineCreatorForQ(0.25, dimInfo, groupByDimInfo, groupByVal); 524 | }, 525 | 'Q2'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 526 | return lineCreatorForQ(0.5, dimInfo, groupByDimInfo, groupByVal); 527 | }, 528 | 'Q3'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 529 | return lineCreatorForQ(0.75, dimInfo, groupByDimInfo, groupByVal); 530 | } 531 | }; 532 | 533 | const lineUpdater: { 534 | [key in AggregateMethodInternal]: ( 535 | val: OptionDataValue, 536 | upstream: ExternalSource, 537 | dataIndex: number, 538 | dimInfo: ResultDimInfoInternal, 539 | groupByDimInfo: ExternalDimensionDefinition, 540 | groupByVal: OptionDataValue 541 | ) => OptionDataValue 542 | } = { 543 | 'SUM'(val, upstream, dataIndex, dimInfo) { 544 | // FIXME: handle other types 545 | return (val as number) + (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number); 546 | }, 547 | 'COUNT'(val) { 548 | return (val as number) + 1; 549 | }, 550 | 'FIRST'(val) { 551 | return val; 552 | }, 553 | 'MIN'(val, upstream, dataIndex, dimInfo) { 554 | return Math.min(val as number, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number); 555 | }, 556 | 'MAX'(val, upstream, dataIndex, dimInfo) { 557 | return Math.max(val as number, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number); 558 | }, 559 | 'AVERAGE'(val, upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) { 560 | // FIXME: refactor, bad implementation. 561 | const collectLine = groupByDimInfo 562 | ? dimInfo.__collectionResult.mapByGroup[groupByVal + ''] 563 | : dimInfo.__collectionResult.outList[0]; 564 | return (val as number) 565 | + (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number) 566 | / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine]; 567 | }, 568 | 'Q1'(val, upstream, dataIndex, dimInfo) { 569 | return val; 570 | }, 571 | 'Q2'(val, upstream, dataIndex, dimInfo) { 572 | return val; 573 | }, 574 | 'Q3'(val, upstream, dataIndex, dimInfo) { 575 | return val; 576 | } 577 | }; 578 | 579 | function lineCreatorForQ( 580 | percent: number, 581 | dimInfo: ResultDimInfoInternal, 582 | groupByDimInfo: ExternalDimensionDefinition, 583 | groupByVal: OptionDataValue 584 | ) { 585 | const gatheredValues = groupByDimInfo 586 | ? dimInfo.gatheredValuesByGroup[groupByVal + ''] 587 | : dimInfo.gatheredValuesNoGroup; 588 | return quantile(gatheredValues, percent); 589 | } 590 | -------------------------------------------------------------------------------- /dist/ecSimpleTransform.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"ecSimpleTransform.js","sources":["../src/id.ts","../src/util.ts","../src/aggregate.ts"],"sourcesContent":["/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {\n DataTransformOption, DimensionDefinitionLoose, DimensionIndex,\n DimensionName, ExternalDataTransform, OptionSourceDataArrayRows\n} from './types';\n\n/**\n * @usage\n *\n * ```js\n * dataset: [{\n * source: [\n * ['aa', 'bb', 'cc', 'tag'],\n * [12, 0.33, 5200, 'AA'],\n * [21, 0.65, 8100, 'AA'],\n * ...\n * ]\n * }, {\n * transform: {\n * type: 'ecSimpleTransform:id',\n * config: {\n * dimensionIndex: 4,\n * dimensionName: 'ID'\n * }\n * }\n * // Then the result data will be:\n * // [\n * // ['aa', 'bb', 'cc', 'tag', 'ID'],\n * // [12, 0.33, 5200, 'AA', 0],\n * // [21, 0.65, 8100, 'BB', 1],\n * // ...\n * // ]\n * }]\n * ```\n */\n\nexport interface IdTransformOption extends DataTransformOption {\n type: 'ecSimpleTransform:id';\n config: {\n // Mandatory. Specify where to put the new id dimension.\n dimensionIndex: DimensionIndex;\n // Optional. If not provided, left the dimension name not defined.\n dimensionName: DimensionName;\n };\n}\n\nexport const transform: ExternalDataTransform = {\n\n type: 'ecSimpleTransform:id',\n\n transform: function (params) {\n const upstream = params.upstream;\n const config = params.config;\n const dimensionIndex = config.dimensionIndex;\n const dimensionName = config.dimensionName;\n\n const dimsDef = upstream.cloneAllDimensionInfo() as DimensionDefinitionLoose[];\n dimsDef[dimensionIndex] = dimensionName;\n\n const data = upstream.cloneRawData() as OptionSourceDataArrayRows;\n\n // TODO: support objectRows\n for (let i = 0, len = data.length; i < len; i++) {\n const line = data[i];\n line[dimensionIndex] = i;\n }\n\n return {\n dimensions: dimsDef,\n data: data\n };\n }\n};\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nexport function assert(condition: any, message?: string) {\n if (!condition) {\n throw new Error(message);\n }\n}\n\nexport function hasOwn(own: object, prop: string): boolean {\n return own.hasOwnProperty(prop);\n}\n\nexport function quantile(ascArr: number[], p: number): number {\n const H = (ascArr.length - 1) * p + 1;\n const h = Math.floor(H);\n const v = +ascArr[h - 1];\n const e = H - h;\n return e ? v + e * (ascArr[h] - v) : v;\n}\n","/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in compliance\n* with the License. You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing,\n* software distributed under the License is distributed on an\n* \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n* KIND, either express or implied. See the License for the\n* specific language governing permissions and limitations\n* under the License.\n*/\n\nimport {\n DataTransformOption, DimensionLoose, DimensionName, ExternalDataTransform,\n ExternalDimensionDefinition, ExternalSource, OptionDataValue\n} from './types';\nimport { assert, hasOwn, quantile } from './util';\n\n/**\n * @usage\n *\n * ```js\n * dataset: [{\n * source: [\n * ['aa', 'bb', 'cc', 'tag'],\n * [12, 0.33, 5200, 'AA'],\n * [21, 0.65, 7100, 'AA'],\n * [51, 0.15, 1100, 'BB'],\n * [71, 0.75, 9100, 'BB'],\n * ...\n * ]\n * }, {\n * transform: {\n * type: 'ecSimpleTransform:aggregate',\n * config: {\n * resultDimensions: [\n * // by default, use the same name with `from`.\n * { from: 'aa', method: 'sum' },\n * { from: 'bb', method: 'count' },\n * { from: 'cc' }, // method by default: use the first value.\n * { from: 'dd', method: 'Q1' },\n * { from: 'tag' }\n * ],\n * groupBy: 'tag'\n * }\n * }\n * // Then the result data will be:\n * // [\n * // ['aa', 'bb', 'cc', 'tag'],\n * // [12, 0.33, 5200, 'AA'],\n * // [21, 0.65, 8100, 'BB'],\n * // ...\n * // ]\n * }]\n * ```\n */\n\nexport interface AggregateTransformOption extends DataTransformOption {\n type: 'ecSimpleTransform:aggregate';\n config: {\n // Mandatory\n resultDimensions: {\n // Optional. The name of the result dimensions.\n // If not provided, inherit the name from `from`.\n name: DimensionName;\n // Mandatory. `from` is used to reference dimension from `source`.\n from: DimensionLoose;\n // Optional. Aggregate method. Currently only these method supported.\n // If not provided, use `'first'`.\n method: AggregateMethodLoose;\n }[];\n // Optional\n groupBy: DimensionLoose;\n };\n}\n\nconst METHOD_INTERNAL = {\n 'SUM': true,\n 'COUNT': true,\n 'FIRST': true,\n 'AVERAGE': true,\n 'Q1': true,\n 'Q2': true,\n 'Q3': true,\n 'MIN': true,\n 'MAX': true\n} as const;\nconst METHOD_NEEDS_COLLECT = {\n AVERAGE: ['COUNT']\n} as const;\nconst METHOD_NEEDS_GATHER_VALUES = {\n Q1: true,\n Q2: true,\n Q3: true\n} as const;\nconst METHOD_ALIAS = {\n MEDIAN: 'Q2'\n} as const;\n\ntype AggregateMethodLoose =\n AggregateMethodInternal\n | 'sum' | 'count' | 'first' | 'average' | 'Q1' | 'Q2' | 'Q3' | 'median' | 'min' | 'max';\ntype AggregateMethodInternal = keyof typeof METHOD_INTERNAL;\n\n\nclass ResultDimInfoInternal {\n\n readonly method: AggregateMethodInternal;\n readonly name: DimensionName;\n readonly index: number;\n readonly indexInUpstream: number;\n\n readonly collectionInfoList = [] as {\n method: AggregateMethodInternal;\n indexInLine: number;\n }[];\n\n // FIXME: refactor\n readonly gatheredValuesByGroup: { [groupVal: string]: number[] } = {};\n readonly gatheredValuesNoGroup = [] as number[];\n readonly needGatherValues: boolean = false;\n\n __collectionResult: TravelResult;\n\n private _collectionInfoMap = {} as {\n // number is the index of `list`\n [method in AggregateMethodInternal]: number\n };\n\n constructor(\n index: number,\n indexInUpstream: number,\n method: AggregateMethodInternal,\n name: DimensionName,\n needGatherValues: boolean\n ) {\n this.method = method;\n this.name = name;\n this.index = index;\n this.indexInUpstream = indexInUpstream;\n this.needGatherValues = needGatherValues;\n }\n\n addCollectionInfo(item: ResultDimInfoInternal['collectionInfoList'][number]) {\n this._collectionInfoMap[item.method] = this.collectionInfoList.length;\n this.collectionInfoList.push(item);\n }\n\n getCollectionInfo(method: AggregateMethodInternal) {\n return this.collectionInfoList[this._collectionInfoMap[method]];\n }\n\n // FIXME: temp implementation. Need refactor.\n gatherValue(groupByDimInfo: ExternalDimensionDefinition, groupVal: OptionDataValue, value: OptionDataValue) {\n // FIXME: convert to number compulsorily temporarily.\n value = +value;\n if (groupByDimInfo) {\n if (groupVal != null) {\n const groupValStr = groupVal + '';\n const values = this.gatheredValuesByGroup[groupValStr]\n || (this.gatheredValuesByGroup[groupValStr] = []);\n values.push(value);\n }\n }\n else {\n this.gatheredValuesNoGroup.push(value);\n }\n }\n}\n\ntype CreateInTravel = (\n upstream: ExternalSource,\n dataIndex: number,\n dimInfoList: ResultDimInfoInternal[],\n groupByDimInfo?: ExternalDimensionDefinition,\n groupByVal?: OptionDataValue\n) => LINE;\ntype UpdateInTravel = (\n upstream: ExternalSource,\n dataIndex: number,\n targetLine: LINE,\n dimInfoList: ResultDimInfoInternal[],\n groupByDimInfo?: ExternalDimensionDefinition,\n groupByVal?: OptionDataValue\n) => void;\n\nexport const transform: ExternalDataTransform = {\n\n type: 'ecSimpleTransform:aggregate',\n\n transform: function (params) {\n const upstream = params.upstream;\n const config = params.config;\n\n const groupByDimInfo = prepareGroupByDimInfo(config, upstream);\n const { finalResultDimInfoList, collectionDimInfoList } = prepareDimensions(\n config, upstream, groupByDimInfo\n );\n\n // Collect\n let collectionResult: TravelResult;\n if (collectionDimInfoList.length) {\n collectionResult = travel(\n groupByDimInfo,\n upstream,\n collectionDimInfoList,\n createCollectionResultLine,\n updateCollectionResultLine\n );\n }\n\n for (let i = 0; i < collectionDimInfoList.length; i++) {\n const dimInfo = collectionDimInfoList[i];\n dimInfo.__collectionResult = collectionResult;\n // FIXME: just for Q1, Q2, Q3: need asc.\n asc(dimInfo.gatheredValuesNoGroup);\n\n const gatheredValuesByGroup = dimInfo.gatheredValuesByGroup;\n for (const key in gatheredValuesByGroup) {\n if (hasOwn(gatheredValuesByGroup, key)) {\n asc(gatheredValuesByGroup[key]);\n }\n }\n }\n\n // Calculate\n const finalResult = travel(\n groupByDimInfo,\n upstream,\n finalResultDimInfoList,\n createFinalResultLine,\n updateFinalResultLine\n );\n\n const dimensions = [];\n for (let i = 0; i < finalResultDimInfoList.length; i++) {\n dimensions.push(finalResultDimInfoList[i].name);\n }\n\n return {\n dimensions: dimensions,\n data: finalResult.outList\n };\n }\n};\n\nfunction prepareDimensions(\n config: AggregateTransformOption['config'],\n upstream: ExternalSource,\n groupByDimInfo: ExternalDimensionDefinition\n): {\n finalResultDimInfoList: ResultDimInfoInternal[];\n collectionDimInfoList: ResultDimInfoInternal[];\n} {\n const resultDimensionsConfig = config.resultDimensions;\n const finalResultDimInfoList: ResultDimInfoInternal[] = [];\n const collectionDimInfoList: ResultDimInfoInternal[] = [];\n let gIndexInLine = 0;\n\n for (let i = 0; i < resultDimensionsConfig.length; i++) {\n const resultDimInfoConfig = resultDimensionsConfig[i];\n\n const dimInfoInUpstream = upstream.getDimensionInfo(resultDimInfoConfig.from);\n assert(dimInfoInUpstream, 'Can not find dimension by `from`: ' + resultDimInfoConfig.from);\n\n const rawMethod = resultDimInfoConfig.method;\n\n assert(\n groupByDimInfo.index !== dimInfoInUpstream.index || rawMethod == null,\n `Dimension ${dimInfoInUpstream.name} is the \"groupBy\" dimension, must not have any \"method\".`\n );\n\n const method = normalizeMethod(rawMethod);\n assert(method, 'method is required');\n\n const name = resultDimInfoConfig.name != null ? resultDimInfoConfig.name : dimInfoInUpstream.name;\n\n const finalResultDimInfo = new ResultDimInfoInternal(\n finalResultDimInfoList.length,\n dimInfoInUpstream.index,\n method,\n name,\n hasOwn(METHOD_NEEDS_GATHER_VALUES, method)\n );\n finalResultDimInfoList.push(finalResultDimInfo);\n\n // For collection.\n let needCollect = false;\n if (hasOwn(METHOD_NEEDS_COLLECT, method)) {\n needCollect = true;\n const collectionTargetMethods = METHOD_NEEDS_COLLECT[method as keyof typeof METHOD_NEEDS_COLLECT];\n for (let j = 0; j < collectionTargetMethods.length; j++) {\n finalResultDimInfo.addCollectionInfo({\n method: collectionTargetMethods[j],\n indexInLine: gIndexInLine++\n });\n }\n }\n if (hasOwn(METHOD_NEEDS_GATHER_VALUES, method)) {\n needCollect = true;\n }\n if (needCollect) {\n collectionDimInfoList.push(finalResultDimInfo);\n }\n }\n\n return { collectionDimInfoList, finalResultDimInfoList };\n}\n\nfunction prepareGroupByDimInfo(\n config: AggregateTransformOption['config'],\n upstream: ExternalSource\n): ExternalDimensionDefinition {\n const groupByConfig = config.groupBy;\n let groupByDimInfo;\n if (groupByConfig != null) {\n groupByDimInfo = upstream.getDimensionInfo(groupByConfig);\n assert(groupByDimInfo, 'Can not find dimension by `groupBy`: ' + groupByConfig);\n }\n return groupByDimInfo;\n}\n\ninterface TravelResult {\n mapByGroup: { [groupVal: string]: LINE };\n outList: LINE[];\n}\n\nfunction travel(\n groupByDimInfo: ExternalDimensionDefinition,\n upstream: ExternalSource,\n resultDimInfoList: ResultDimInfoInternal[],\n doCreate: CreateInTravel,\n doUpdate: UpdateInTravel\n): TravelResult {\n const outList: TravelResult['outList'] = [];\n let mapByGroup: TravelResult['mapByGroup'];\n\n if (groupByDimInfo) {\n mapByGroup = {};\n\n for (let dataIndex = 0, len = upstream.count(); dataIndex < len; dataIndex++) {\n const groupByVal = upstream.retrieveValue(dataIndex, groupByDimInfo.index);\n\n // PENDING: when value is null/undefined\n if (groupByVal == null) {\n continue;\n }\n\n const groupByValStr = groupByVal + '';\n\n if (!hasOwn(mapByGroup, groupByValStr)) {\n const newLine = doCreate(upstream, dataIndex, resultDimInfoList, groupByDimInfo, groupByVal);\n outList.push(newLine);\n mapByGroup[groupByValStr] = newLine;\n }\n else {\n const targetLine = mapByGroup[groupByValStr];\n doUpdate(upstream, dataIndex, targetLine, resultDimInfoList, groupByDimInfo, groupByVal);\n }\n }\n }\n else {\n const targetLine = doCreate(upstream, 0, resultDimInfoList);\n outList.push(targetLine);\n for (let dataIndex = 1, len = upstream.count(); dataIndex < len; dataIndex++) {\n doUpdate(upstream, dataIndex, targetLine, resultDimInfoList);\n }\n }\n\n return { mapByGroup, outList };\n}\n\nfunction normalizeMethod(method: AggregateMethodLoose): AggregateMethodInternal {\n if (method == null) {\n return 'FIRST';\n }\n let methodInternal = method.toUpperCase() as AggregateMethodInternal;\n methodInternal = hasOwn(METHOD_ALIAS, methodInternal)\n ? METHOD_ALIAS[methodInternal as keyof typeof METHOD_ALIAS]\n : methodInternal;\n assert(hasOwn(METHOD_INTERNAL, methodInternal), `Illegal method ${method}.`);\n return methodInternal;\n}\n\n\n\ntype CollectionResultLine = number[];\n\nconst createCollectionResultLine: CreateInTravel = (\n upstream, dataIndex, collectionDimInfoList, groupByDimInfo, groupByVal\n) => {\n const newLine = [] as number[];\n for (let i = 0; i < collectionDimInfoList.length; i++) {\n const dimInfo = collectionDimInfoList[i];\n const collectionInfoList = dimInfo.collectionInfoList;\n for (let j = 0; j < collectionInfoList.length; j++) {\n const collectionInfo = collectionInfoList[j];\n // FIXME: convert to number compulsorily temporarily.\n newLine[collectionInfo.indexInLine] = +lineCreator[collectionInfo.method](\n upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal\n );\n }\n // FIXME: refactor\n if (dimInfo.needGatherValues) {\n const val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);\n dimInfo.gatherValue(groupByDimInfo, groupByVal, val);\n }\n }\n return newLine;\n};\n\nconst updateCollectionResultLine: UpdateInTravel = (\n upstream, dataIndex, targetLine: number[], collectionDimInfoList, groupByDimInfo, groupByVal\n) => {\n for (let i = 0; i < collectionDimInfoList.length; i++) {\n const dimInfo = collectionDimInfoList[i];\n const collectionInfoList = dimInfo.collectionInfoList;\n for (let j = 0; j < collectionInfoList.length; j++) {\n const collectionInfo = collectionInfoList[j];\n const indexInLine = collectionInfo.indexInLine;\n // FIXME: convert to number compulsorily temporarily.\n targetLine[indexInLine] = +lineUpdater[collectionInfo.method](\n targetLine[indexInLine], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal\n );\n }\n // FIXME: refactor\n if (dimInfo.needGatherValues) {\n const val = upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);\n dimInfo.gatherValue(groupByDimInfo, groupByVal, val);\n }\n }\n};\n\n\n\ntype FinalResultLine = OptionDataValue[];\n\nconst createFinalResultLine: CreateInTravel = (\n upstream, dataIndex, finalResultDimInfoList, groupByDimInfo, groupByVal\n) => {\n const newLine = [];\n for (let i = 0; i < finalResultDimInfoList.length; i++) {\n const dimInfo = finalResultDimInfoList[i];\n const method = dimInfo.method;\n newLine[i] = isGroupByDimension(groupByDimInfo, dimInfo)\n ? groupByVal\n : lineCreator[method](\n upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal\n );\n }\n return newLine;\n};\n\nconst updateFinalResultLine: UpdateInTravel = (\n upstream, dataIndex, targetLine, finalResultDimInfoList, groupByDimInfo, groupByVal\n) => {\n for (let i = 0; i < finalResultDimInfoList.length; i++) {\n const dimInfo = finalResultDimInfoList[i];\n if (isGroupByDimension(groupByDimInfo, dimInfo)) {\n continue;\n }\n const method = dimInfo.method;\n targetLine[i] = lineUpdater[method](\n targetLine[i], upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal\n );\n }\n};\n\nfunction isGroupByDimension(\n groupByDimInfo: ExternalDimensionDefinition,\n targetDimInfo: ResultDimInfoInternal\n): boolean {\n return groupByDimInfo && targetDimInfo.indexInUpstream === groupByDimInfo.index;\n}\n\nfunction asc(list: number[]) {\n list.sort((a, b) => {\n return a - b;\n });\n}\n\nconst lineCreator: {\n [key in AggregateMethodInternal]: (\n upstream: ExternalSource,\n dataIndex: number,\n dimInfo: ResultDimInfoInternal,\n groupByDimInfo: ExternalDimensionDefinition,\n groupByVal: OptionDataValue\n ) => OptionDataValue\n} = {\n 'SUM'() {\n return 0;\n },\n 'COUNT'() {\n return 1;\n },\n 'FIRST'(upstream, dataIndex, dimInfo) {\n return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);\n },\n 'MIN'(upstream, dataIndex, dimInfo) {\n return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);\n },\n 'MAX'(upstream, dataIndex, dimInfo) {\n return upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream);\n },\n 'AVERAGE'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {\n // FIXME: refactor, bad implementation.\n const collectLine = groupByDimInfo\n ? dimInfo.__collectionResult.mapByGroup[groupByVal + '']\n : dimInfo.__collectionResult.outList[0];\n return (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number)\n / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine];\n },\n // FIXME: refactor\n 'Q1'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {\n return lineCreatorForQ(0.25, dimInfo, groupByDimInfo, groupByVal);\n },\n 'Q2'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {\n return lineCreatorForQ(0.5, dimInfo, groupByDimInfo, groupByVal);\n },\n 'Q3'(upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {\n return lineCreatorForQ(0.75, dimInfo, groupByDimInfo, groupByVal);\n }\n};\n\nconst lineUpdater: {\n [key in AggregateMethodInternal]: (\n val: OptionDataValue,\n upstream: ExternalSource,\n dataIndex: number,\n dimInfo: ResultDimInfoInternal,\n groupByDimInfo: ExternalDimensionDefinition,\n groupByVal: OptionDataValue\n ) => OptionDataValue\n} = {\n 'SUM'(val, upstream, dataIndex, dimInfo) {\n // FIXME: handle other types\n return (val as number) + (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number);\n },\n 'COUNT'(val) {\n return (val as number) + 1;\n },\n 'FIRST'(val) {\n return val;\n },\n 'MIN'(val, upstream, dataIndex, dimInfo) {\n return Math.min(val as number, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number);\n },\n 'MAX'(val, upstream, dataIndex, dimInfo) {\n return Math.max(val as number, upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number);\n },\n 'AVERAGE'(val, upstream, dataIndex, dimInfo, groupByDimInfo, groupByVal) {\n // FIXME: refactor, bad implementation.\n const collectLine = groupByDimInfo\n ? dimInfo.__collectionResult.mapByGroup[groupByVal + '']\n : dimInfo.__collectionResult.outList[0];\n return (val as number)\n + (upstream.retrieveValue(dataIndex, dimInfo.indexInUpstream) as number)\n / collectLine[dimInfo.getCollectionInfo('COUNT').indexInLine];\n },\n 'Q1'(val, upstream, dataIndex, dimInfo) {\n return val;\n },\n 'Q2'(val, upstream, dataIndex, dimInfo) {\n return val;\n },\n 'Q3'(val, upstream, dataIndex, dimInfo) {\n return val;\n }\n};\n\nfunction lineCreatorForQ(\n percent: number,\n dimInfo: ResultDimInfoInternal,\n groupByDimInfo: ExternalDimensionDefinition,\n groupByVal: OptionDataValue\n) {\n const gatheredValues = groupByDimInfo\n ? dimInfo.gatheredValuesByGroup[groupByVal + '']\n : dimInfo.gatheredValuesNoGroup;\n return quantile(gatheredValues, percent);\n}\n"],"names":["transform"],"mappings":";;;;;;QAgEa,SAAS,GAA6C;QAE/D,IAAI,EAAE,sBAAsB;QAE5B,SAAS,EAAE,UAAU,MAAM;YACvB,IAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;YACjC,IAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YAC7B,IAAM,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;YAC7C,IAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;YAE3C,IAAM,OAAO,GAAG,QAA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