dtable-statistic 4.0.2-test-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/es/api/dtable-db-api.js +43 -0
- package/es/assets/css/color-picker.css +53 -0
- package/es/assets/css/color-rules-popover.css +144 -0
- package/es/assets/css/color-theme-dialog.css +40 -0
- package/es/assets/css/dashboard.css +562 -0
- package/es/assets/css/dialog.css +415 -0
- package/es/assets/css/mobile-dashboard.module.css +91 -0
- package/es/assets/css/slider.css +77 -0
- package/es/assets/css/statistic-chart.module.css +11 -0
- package/es/assets/css/statistic-custom-title.module.css +3 -0
- package/es/assets/css/statistic-custom.module.css +4 -0
- package/es/assets/css/statistic-numeric-column-item.module.css +43 -0
- package/es/assets/css/statistic-time-picker.module.css +21 -0
- package/es/assets/css/theme.css +61 -0
- package/es/assets/images/icon.png +0 -0
- package/es/calculator/base-calculator.js +111 -0
- package/es/calculator/basic-chart-calculator.js +571 -0
- package/es/calculator/combination-calculator.js +296 -0
- package/es/calculator/compare-bar-calculator.js +291 -0
- package/es/calculator/completeness-calculator.js +307 -0
- package/es/calculator/copy-value.js +47 -0
- package/es/calculator/dashboard-calculator.js +146 -0
- package/es/calculator/heat-map-calculator.js +225 -0
- package/es/calculator/horizontal-bar-calculator.js +100 -0
- package/es/calculator/index.js +88 -0
- package/es/calculator/map-calculator.js +169 -0
- package/es/calculator/mirror-calculator.js +217 -0
- package/es/calculator/number-card-calculator.js +135 -0
- package/es/calculator/pivot-table-calculator.js +810 -0
- package/es/calculator/scatter-calculator.js +150 -0
- package/es/calculator/thread-manager.js +70 -0
- package/es/calculator/trend-calculator.js +204 -0
- package/es/calculator/workers/basic-chart-calculator-worker.js +410 -0
- package/es/calculator/workers/calculator.worker.js +22 -0
- package/es/calculator/workers/card-calculator-worker.js +28 -0
- package/es/calculator/workers/combination-calculator-worker.js +257 -0
- package/es/calculator/workers/compare-bar-chart-calculator-worker.js +149 -0
- package/es/calculator/workers/completeness-calculator-worker.js +153 -0
- package/es/calculator/workers/dashboard-calculator-worker.js +56 -0
- package/es/calculator/workers/mirror-calculator-worker.js +132 -0
- package/es/calculator/workers/pivot-table-calculator-worker.js +615 -0
- package/es/calculator/workers/scatter-calculator-worker.js +67 -0
- package/es/calculator/workers/trend-calculator-worker.js +93 -0
- package/es/calculator/world-map-calculator.js +193 -0
- package/es/components/common-add-tool.js +19 -0
- package/es/components/dialog/chart-addition-edit-dialog.js +89 -0
- package/es/components/dialog/chart-addition-widgets/chart-selector.js +261 -0
- package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +74 -0
- package/es/components/dialog/color-theme-dialog.js +71 -0
- package/es/components/dialog/enlarged-chart-dialog.js +73 -0
- package/es/components/dialog/new-table-dialog.js +113 -0
- package/es/components/dialog/new-view-dialog.js +87 -0
- package/es/components/dialog/rename-view-dialog.js +87 -0
- package/es/components/dialog/statistic-record-dialog/index.css +114 -0
- package/es/components/dialog/statistic-record-dialog/index.js +174 -0
- package/es/components/dialog/table-select-dialog.js +93 -0
- package/es/components/dropdown-menu/statistic-dropdown-menu.js +94 -0
- package/es/components/dtable-popover.js +109 -0
- package/es/components/dtable-search-input.js +137 -0
- package/es/components/dtable-select.js +104 -0
- package/es/components/index.js +11 -0
- package/es/components/loading.js +8 -0
- package/es/components/modal-portal.js +36 -0
- package/es/components/popover/color-rules/color-rule.js +179 -0
- package/es/components/popover/color-rules/index.js +87 -0
- package/es/components/popover/color-rules/rule-filters/filter.js +214 -0
- package/es/components/popover/color-rules/rule-filters/index.css +214 -0
- package/es/components/popover/color-rules/rule-filters/index.js +97 -0
- package/es/components/popover/color-rules/rule-filters/number-input.js +85 -0
- package/es/components/popover/color-rules-popover.js +213 -0
- package/es/components/popover/color-selector-popover.js +85 -0
- package/es/components/seatable-radio/index.css +51 -0
- package/es/components/seatable-radio/index.js +28 -0
- package/es/components/select/index.js +2 -0
- package/es/components/select/option-group.css +104 -0
- package/es/components/select/option-group.js +225 -0
- package/es/components/select/option.js +51 -0
- package/es/components/select/select.css +211 -0
- package/es/components/select/select.js +157 -0
- package/es/components/toast/alert.js +130 -0
- package/es/components/toast/index.js +3 -0
- package/es/components/toast/toast.js +164 -0
- package/es/components/toast/toastManager.js +150 -0
- package/es/components/toast/toaster.js +64 -0
- package/es/constants/color-rules.js +8 -0
- package/es/constants/dtable-select-style.js +61 -0
- package/es/constants/event-types.js +1 -0
- package/es/constants/index.js +501 -0
- package/es/constants/key-codes.js +102 -0
- package/es/constants/zIndexes.js +1 -0
- package/es/custom-g2.js +614 -0
- package/es/dashboard.js +408 -0
- package/es/desktop-dashboard.js +299 -0
- package/es/index.js +33 -0
- package/es/locale/index.js +17 -0
- package/es/locale/lang/de.js +237 -0
- package/es/locale/lang/en.js +237 -0
- package/es/locale/lang/fr.js +237 -0
- package/es/locale/lang/zh_CN.js +237 -0
- package/es/mobile-dashboard.js +103 -0
- package/es/model/collaborators.js +11 -0
- package/es/model/stat-item.js +340 -0
- package/es/model/statistic-dashboard.js +8 -0
- package/es/service/chart-service.js +192 -0
- package/es/service/dashboard-service.js +415 -0
- package/es/stat-editor/chart-name-editor.js +75 -0
- package/es/stat-editor/index.js +74 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +149 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +415 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +193 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +13 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +107 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/index.js +332 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +170 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +141 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +219 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +89 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +132 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +319 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +138 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +135 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +156 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +147 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +195 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +126 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +169 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +352 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +145 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +153 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/index.js +466 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +183 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +542 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +111 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +86 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +169 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +273 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +105 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +243 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +65 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +318 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +49 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +124 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +150 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +267 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +109 -0
- package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +351 -0
- package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +60 -0
- package/es/stat-editor/stat-settings/color-setting/color-picker.js +129 -0
- package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +348 -0
- package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +102 -0
- package/es/stat-editor/stat-settings/public-setting/base-settings.js +124 -0
- package/es/stat-editor/stat-settings/public-setting/calender.js +124 -0
- package/es/stat-editor/stat-settings/public-setting/column-settings.js +15 -0
- package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +60 -0
- package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +57 -0
- package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +41 -0
- package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +64 -0
- package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +118 -0
- package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +39 -0
- package/es/stat-list/chart-preview.js +139 -0
- package/es/stat-list/index.js +275 -0
- package/es/stat-view/area-chart.js +521 -0
- package/es/stat-view/bar-chart.js +568 -0
- package/es/stat-view/base-chart.js +44 -0
- package/es/stat-view/basic-number-card.js +255 -0
- package/es/stat-view/combination-chart.js +558 -0
- package/es/stat-view/compare-chart.js +485 -0
- package/es/stat-view/completeness-chart.js +389 -0
- package/es/stat-view/custom-bar.js +433 -0
- package/es/stat-view/dashboard-chart.js +317 -0
- package/es/stat-view/heat-map.js +501 -0
- package/es/stat-view/horizontal-bar-chart.js +569 -0
- package/es/stat-view/index.js +183 -0
- package/es/stat-view/line-chart.js +505 -0
- package/es/stat-view/map.js +428 -0
- package/es/stat-view/mirror.js +285 -0
- package/es/stat-view/pie-chart.js +326 -0
- package/es/stat-view/pivot-table/index.js +206 -0
- package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +133 -0
- package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +164 -0
- package/es/stat-view/pivot-table/statistic-pivot-table.module.css +132 -0
- package/es/stat-view/pivot-table/two-dimension-table.js +344 -0
- package/es/stat-view/ring-chart.js +416 -0
- package/es/stat-view/scatter-chart.js +367 -0
- package/es/stat-view/treemap-chart.js +318 -0
- package/es/stat-view/trend-chart.js +299 -0
- package/es/stat-view/world-map.js +443 -0
- package/es/tabs/index.js +252 -0
- package/es/tabs/statistic-tabs.module.css +154 -0
- package/es/tabs/tab.js +167 -0
- package/es/utils/basic-chart-utils.js +24 -0
- package/es/utils/cell-format.js +110 -0
- package/es/utils/cell-value.js +27 -0
- package/es/utils/collaborator.js +31 -0
- package/es/utils/color-utils.js +112 -0
- package/es/utils/column-utils.js +18 -0
- package/es/utils/column.js +13 -0
- package/es/utils/common-utils.js +303 -0
- package/es/utils/date-format.js +65 -0
- package/es/utils/export-table-utils.js +632 -0
- package/es/utils/index.js +26 -0
- package/es/utils/object.js +26 -0
- package/es/utils/row-utils.js +115 -0
- package/es/utils/search.js +67 -0
- package/es/utils/sql-utils.js +293 -0
- package/es/utils/stat-utils.js +353 -0
- package/es/utils/trend-utils.js +136 -0
- package/index.js +1 -0
- package/package.json +188 -0
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
6
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
7
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
8
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
9
|
+
import dayjs from 'dayjs';
|
|
10
|
+
import { CellType, filter2SqlCondition, isDateColumn, isNumericColumn, TableUtils } from 'dtable-store';
|
|
11
|
+
import BaseCalculator from './base-calculator';
|
|
12
|
+
import { DTABLE_DB_SUMMARY_METHOD, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, SUMMARY_TYPE, TIME_COLUMN_LIST } from '../constants';
|
|
13
|
+
import { getSummaryColumnMethod } from '../utils/common-utils';
|
|
14
|
+
import StatUtils from '../utils/stat-utils';
|
|
15
|
+
import { getFormattedLabel } from '../utils/row-utils';
|
|
16
|
+
var PivotTableCalculator = /*#__PURE__*/function (_BaseCalculator) {
|
|
17
|
+
_inherits(PivotTableCalculator, _BaseCalculator);
|
|
18
|
+
var _super = _createSuper(PivotTableCalculator);
|
|
19
|
+
function PivotTableCalculator(_ref) {
|
|
20
|
+
var value = _ref.value,
|
|
21
|
+
statisticThreadManager = _ref.statisticThreadManager,
|
|
22
|
+
username = _ref.username,
|
|
23
|
+
userId = _ref.userId;
|
|
24
|
+
_classCallCheck(this, PivotTableCalculator);
|
|
25
|
+
return _super.call(this, {
|
|
26
|
+
value: value,
|
|
27
|
+
statisticThreadManager: statisticThreadManager,
|
|
28
|
+
username: username,
|
|
29
|
+
userId: userId
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
_createClass(PivotTableCalculator, [{
|
|
33
|
+
key: "isValidChart",
|
|
34
|
+
value: function isValidChart(chart) {
|
|
35
|
+
if (!this.validateBaseConfigs(chart)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
var table_id = chart.table_id,
|
|
39
|
+
groupby_column_key = chart.groupby_column_key,
|
|
40
|
+
summary_type = chart.summary_type,
|
|
41
|
+
summary_column_key = chart.summary_column_key,
|
|
42
|
+
column_groupby_column_key = chart.column_groupby_column_key,
|
|
43
|
+
summary_columns_option = chart.summary_columns_option;
|
|
44
|
+
var table = this.getTableById(table_id);
|
|
45
|
+
if (!groupby_column_key || !TableUtils.getTableColumnByKey(table, groupby_column_key)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (column_groupby_column_key && !TableUtils.getTableColumnByKey(table, column_groupby_column_key)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
52
|
+
var summaryColumnsKeys = summary_columns_option ? summary_columns_option.map(function (item) {
|
|
53
|
+
return item.key;
|
|
54
|
+
}) : [];
|
|
55
|
+
if (!table.columns.find(function (column) {
|
|
56
|
+
return column.key === summary_column_key || summaryColumnsKeys.includes(column.key);
|
|
57
|
+
})) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "calculate",
|
|
65
|
+
value: function () {
|
|
66
|
+
var _calculate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(chart) {
|
|
67
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
68
|
+
while (1) {
|
|
69
|
+
switch (_context.prev = _context.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
if (this.isValidChart(chart)) {
|
|
72
|
+
_context.next = 2;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return _context.abrupt("return", {});
|
|
76
|
+
case 2:
|
|
77
|
+
if (!this.isCalcByQueryDB(chart)) {
|
|
78
|
+
_context.next = 6;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
_context.next = 5;
|
|
82
|
+
return this.queryDb(chart);
|
|
83
|
+
case 5:
|
|
84
|
+
return _context.abrupt("return", _context.sent);
|
|
85
|
+
case 6:
|
|
86
|
+
_context.next = 8;
|
|
87
|
+
return this.calculateWithWorker(chart);
|
|
88
|
+
case 8:
|
|
89
|
+
return _context.abrupt("return", _context.sent);
|
|
90
|
+
case 9:
|
|
91
|
+
case "end":
|
|
92
|
+
return _context.stop();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, _callee, this);
|
|
96
|
+
}));
|
|
97
|
+
function calculate(_x) {
|
|
98
|
+
return _calculate.apply(this, arguments);
|
|
99
|
+
}
|
|
100
|
+
return calculate;
|
|
101
|
+
}()
|
|
102
|
+
}, {
|
|
103
|
+
key: "queryDb",
|
|
104
|
+
value: function () {
|
|
105
|
+
var _queryDb = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chart) {
|
|
106
|
+
var table_id, view_id, column_groupby_column_key, groupby_column_key, summary_column_key, table, view, groupbyColumn, columnGroupbyColumn, summaryColumn, sqlMap, columnMap, result, status, data, sqlRows;
|
|
107
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
108
|
+
while (1) {
|
|
109
|
+
switch (_context2.prev = _context2.next) {
|
|
110
|
+
case 0:
|
|
111
|
+
table_id = chart.table_id, view_id = chart.view_id, column_groupby_column_key = chart.column_groupby_column_key, groupby_column_key = chart.groupby_column_key, summary_column_key = chart.summary_column_key;
|
|
112
|
+
table = this.getTableById(table_id);
|
|
113
|
+
view = this.getViewById(view_id, table);
|
|
114
|
+
groupbyColumn = TableUtils.getTableColumnByKey(table, groupby_column_key);
|
|
115
|
+
columnGroupbyColumn = TableUtils.getTableColumnByKey(table, column_groupby_column_key);
|
|
116
|
+
summaryColumn = TableUtils.getTableColumnByKey(table, summary_column_key);
|
|
117
|
+
sqlMap = this.generateSqlFromChart(chart, table, view);
|
|
118
|
+
columnMap = {
|
|
119
|
+
groupbyColumn: groupbyColumn,
|
|
120
|
+
columnGroupbyColumn: columnGroupbyColumn,
|
|
121
|
+
summaryColumn: summaryColumn
|
|
122
|
+
};
|
|
123
|
+
_context2.next = 10;
|
|
124
|
+
return this.sqlQuery(sqlMap.sql);
|
|
125
|
+
case 10:
|
|
126
|
+
result = _context2.sent;
|
|
127
|
+
status = result.status, data = result.data;
|
|
128
|
+
if (!(!status === 200 || !data || !data.success)) {
|
|
129
|
+
_context2.next = 14;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
return _context2.abrupt("return", {});
|
|
133
|
+
case 14:
|
|
134
|
+
sqlRows = data.results;
|
|
135
|
+
if (column_groupby_column_key) {
|
|
136
|
+
_context2.next = 17;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
return _context2.abrupt("return", this.oneDimensionTableSQLResult2JavaScript(chart, sqlRows, sqlMap, columnMap));
|
|
140
|
+
case 17:
|
|
141
|
+
return _context2.abrupt("return", this.twoDimensionTableSQLResult2JavaScript(chart, sqlRows, sqlMap, columnMap));
|
|
142
|
+
case 18:
|
|
143
|
+
case "end":
|
|
144
|
+
return _context2.stop();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, _callee2, this);
|
|
148
|
+
}));
|
|
149
|
+
function queryDb(_x2) {
|
|
150
|
+
return _queryDb.apply(this, arguments);
|
|
151
|
+
}
|
|
152
|
+
return queryDb;
|
|
153
|
+
}()
|
|
154
|
+
}, {
|
|
155
|
+
key: "generateSqlFromChart",
|
|
156
|
+
value: function generateSqlFromChart(chart, table, view) {
|
|
157
|
+
if (!chart || !table || !view) return '';
|
|
158
|
+
var column_groupby_column_key = chart.column_groupby_column_key,
|
|
159
|
+
groupby_column_key = chart.groupby_column_key;
|
|
160
|
+
if (!groupby_column_key) return '';
|
|
161
|
+
var condition = filter2SqlCondition(table, view);
|
|
162
|
+
if (!column_groupby_column_key) {
|
|
163
|
+
return this.oneDimensionStatisticTable2sql(chart, condition);
|
|
164
|
+
}
|
|
165
|
+
return this.twoDimensionStatisticTable2sql(chart, condition);
|
|
166
|
+
}
|
|
167
|
+
}, {
|
|
168
|
+
key: "oneDimensionStatisticTable2sql",
|
|
169
|
+
value: function oneDimensionStatisticTable2sql(chart, condition) {
|
|
170
|
+
var _this = this;
|
|
171
|
+
var table_id = chart.table_id,
|
|
172
|
+
groupby_column_key = chart.groupby_column_key,
|
|
173
|
+
summary_type = chart.summary_type,
|
|
174
|
+
summary_column_key = chart.summary_column_key,
|
|
175
|
+
numeric_column_keys = chart.numeric_column_keys,
|
|
176
|
+
groupby_date_granularity = chart.groupby_date_granularity,
|
|
177
|
+
groupby_geolocation_granularity = chart.groupby_geolocation_granularity,
|
|
178
|
+
summary_method = chart.summary_method,
|
|
179
|
+
summary_columns_option = chart.summary_columns_option;
|
|
180
|
+
var table = this.getTableById(table_id);
|
|
181
|
+
var groupbyColumn = TableUtils.getTableColumnByKey(table, groupby_column_key);
|
|
182
|
+
if (!groupbyColumn) return '';
|
|
183
|
+
var _this$column2SqlColum = this.column2SqlColumn(groupbyColumn, {
|
|
184
|
+
dateGranularity: groupby_date_granularity,
|
|
185
|
+
geolocationGranularity: groupby_geolocation_granularity
|
|
186
|
+
}),
|
|
187
|
+
sqlGroupbyColumnName = _this$column2SqlColum.name,
|
|
188
|
+
sqlGroupbyColumnKey = _this$column2SqlColum.key;
|
|
189
|
+
var tableName = "`".concat(table.name, "`");
|
|
190
|
+
if (summary_type === SUMMARY_TYPE.COUNT) {
|
|
191
|
+
var _this$summaryMethodCo = this.summaryMethodColumn2SqlColumn('Count', groupbyColumn),
|
|
192
|
+
sqlSummaryColumnName = _this$summaryMethodCo.name,
|
|
193
|
+
sqlSummaryColumnKey = _this$summaryMethodCo.key;
|
|
194
|
+
var _sql = "SELECT ".concat(sqlGroupbyColumnName, ", ").concat(sqlSummaryColumnName, " FROM ").concat(tableName, " ").concat(condition, " GROUP BY ").concat(sqlGroupbyColumnName, " ORDER BY `").concat(groupbyColumn.name, "` LIMIT 0, 5000");
|
|
195
|
+
return {
|
|
196
|
+
sql: _sql,
|
|
197
|
+
sqlGroupbyColumnKey: sqlGroupbyColumnKey,
|
|
198
|
+
sqlSummaryColumnKey: sqlSummaryColumnKey
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
if (summary_columns_option) {
|
|
202
|
+
var _summarySQLColumnName2ColumnKey = {};
|
|
203
|
+
var _summaryTableColumnKey2Column = {};
|
|
204
|
+
var _summaryTableColumnKey2Method = {};
|
|
205
|
+
var summaryColumnOptions = [];
|
|
206
|
+
var _summaryMethod = summary_method;
|
|
207
|
+
var summaryColumn = TableUtils.getTableColumnByKey(table, summary_column_key);
|
|
208
|
+
if (summaryColumn && (isNumericColumn(summaryColumn) || isDateColumn(summaryColumn))) {
|
|
209
|
+
var _this$summaryMethodCo2 = this.summaryMethodColumn2SqlColumn(_summaryMethod, summaryColumn),
|
|
210
|
+
sqlSummaryMethodColumnName = _this$summaryMethodCo2.name,
|
|
211
|
+
sqlSummaryMethodColumnKey = _this$summaryMethodCo2.key;
|
|
212
|
+
var summaryColumnKey = summaryColumn.key;
|
|
213
|
+
_summarySQLColumnName2ColumnKey[sqlSummaryMethodColumnKey] = summaryColumnKey;
|
|
214
|
+
_summaryTableColumnKey2Column[summaryColumnKey] = summaryColumn;
|
|
215
|
+
_summaryTableColumnKey2Method[summaryColumnKey] = _summaryMethod;
|
|
216
|
+
summaryColumnOptions.push(sqlSummaryMethodColumnName);
|
|
217
|
+
}
|
|
218
|
+
summary_columns_option.forEach(function (option) {
|
|
219
|
+
var key = option.key,
|
|
220
|
+
method = option.method;
|
|
221
|
+
var summaryColumn = TableUtils.getTableColumnByKey(table, key);
|
|
222
|
+
var summaryMethod = method;
|
|
223
|
+
if (summaryColumn && (isNumericColumn(summaryColumn) || isDateColumn(summaryColumn))) {
|
|
224
|
+
var _this$summaryMethodCo3 = _this.summaryMethodColumn2SqlColumn(summaryMethod, summaryColumn),
|
|
225
|
+
_sqlSummaryMethodColumnName = _this$summaryMethodCo3.name,
|
|
226
|
+
_sqlSummaryMethodColumnKey = _this$summaryMethodCo3.key;
|
|
227
|
+
var _summaryColumnKey = summaryColumn.key;
|
|
228
|
+
_summarySQLColumnName2ColumnKey[_sqlSummaryMethodColumnKey] = _summaryColumnKey;
|
|
229
|
+
_summaryTableColumnKey2Column[_summaryColumnKey] = summaryColumn;
|
|
230
|
+
_summaryTableColumnKey2Method[_summaryColumnKey] = summaryMethod;
|
|
231
|
+
summaryColumnOptions.push(_sqlSummaryMethodColumnName);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
var _statisticSummaryColumnsString = summaryColumnOptions.join(', ');
|
|
235
|
+
var _sql2 = "SELECT ".concat(sqlGroupbyColumnName).concat(_statisticSummaryColumnsString ? ', ' + _statisticSummaryColumnsString : '', " FROM ").concat(tableName, " ").concat(condition, " GROUP BY ").concat(sqlGroupbyColumnName, " LIMIT 0, 5000");
|
|
236
|
+
return {
|
|
237
|
+
sql: _sql2,
|
|
238
|
+
sqlGroupbyColumnKey: sqlGroupbyColumnKey,
|
|
239
|
+
summarySQLColumnName2ColumnKey: _summarySQLColumnName2ColumnKey,
|
|
240
|
+
summaryTableColumnKey2Column: _summaryTableColumnKey2Column,
|
|
241
|
+
summaryTableColumnKey2Method: _summaryTableColumnKey2Method
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
var summarySQLColumnName2ColumnKey = {};
|
|
245
|
+
var summaryTableColumnKey2Column = {};
|
|
246
|
+
var summaryTableColumnKey2Method = {};
|
|
247
|
+
var summaryMethod = summary_method;
|
|
248
|
+
var statisticNumericColumnKeys = [summary_column_key].concat(_toConsumableArray(numeric_column_keys || []));
|
|
249
|
+
var validStatisticNumericColumnKeys = _toConsumableArray(new Set(statisticNumericColumnKeys));
|
|
250
|
+
var statisticSummaryColumnsString = validStatisticNumericColumnKeys.map(function (key) {
|
|
251
|
+
return TableUtils.getTableColumnByKey(table, key);
|
|
252
|
+
}).filter(function (column) {
|
|
253
|
+
return column && (isDateColumn(column) || isNumericColumn(column));
|
|
254
|
+
}).map(function (column) {
|
|
255
|
+
var _this$summaryMethodCo4 = _this.summaryMethodColumn2SqlColumn(summaryMethod, column),
|
|
256
|
+
sqlNumericColumn = _this$summaryMethodCo4.name,
|
|
257
|
+
sqlNumericColumnKey = _this$summaryMethodCo4.key;
|
|
258
|
+
var summaryColumnKey = column.key;
|
|
259
|
+
summarySQLColumnName2ColumnKey[sqlNumericColumnKey] = summaryColumnKey;
|
|
260
|
+
summaryTableColumnKey2Column[summaryColumnKey] = column;
|
|
261
|
+
summaryTableColumnKey2Method[summaryColumnKey] = summaryMethod;
|
|
262
|
+
return sqlNumericColumn;
|
|
263
|
+
}).join(', ');
|
|
264
|
+
var sql = "SELECT ".concat(sqlGroupbyColumnName).concat(statisticSummaryColumnsString ? ', ' + statisticSummaryColumnsString : '', " FROM ").concat(tableName, " ").concat(condition, " GROUP BY ").concat(sqlGroupbyColumnName, " LIMIT 0, 5000");
|
|
265
|
+
return {
|
|
266
|
+
sql: sql,
|
|
267
|
+
sqlGroupbyColumnKey: sqlGroupbyColumnKey,
|
|
268
|
+
summarySQLColumnName2ColumnKey: summarySQLColumnName2ColumnKey,
|
|
269
|
+
summaryTableColumnKey2Column: summaryTableColumnKey2Column,
|
|
270
|
+
summaryTableColumnKey2Method: summaryTableColumnKey2Method
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}, {
|
|
274
|
+
key: "twoDimensionStatisticTable2sql",
|
|
275
|
+
value: function twoDimensionStatisticTable2sql(chart, condition) {
|
|
276
|
+
var _this2 = this;
|
|
277
|
+
var table_id = chart.table_id,
|
|
278
|
+
groupby_column_key = chart.groupby_column_key,
|
|
279
|
+
column_groupby_column_key = chart.column_groupby_column_key,
|
|
280
|
+
summary_type = chart.summary_type,
|
|
281
|
+
summary_column_key = chart.summary_column_key,
|
|
282
|
+
groupby_date_granularity = chart.groupby_date_granularity,
|
|
283
|
+
groupby_geolocation_granularity = chart.groupby_geolocation_granularity,
|
|
284
|
+
column_groupby_date_granularity = chart.column_groupby_date_granularity,
|
|
285
|
+
column_groupby_geolocation_granularity = chart.column_groupby_geolocation_granularity,
|
|
286
|
+
summary_method = chart.summary_method,
|
|
287
|
+
column_groupby_multiple_numeric_column = chart.column_groupby_multiple_numeric_column,
|
|
288
|
+
summary_columns_option = chart.summary_columns_option;
|
|
289
|
+
var table = this.getTableById(table_id);
|
|
290
|
+
var tableName = "`".concat(table.name, "`");
|
|
291
|
+
var columnGroupbyColumn = TableUtils.getTableColumnByKey(table, column_groupby_column_key);
|
|
292
|
+
if (!columnGroupbyColumn) return this.oneDimensionStatisticTable2sql(chart, table, tableName, condition);
|
|
293
|
+
var groupbyColumn = TableUtils.getTableColumnByKey(table, groupby_column_key);
|
|
294
|
+
if (!groupbyColumn) return '';
|
|
295
|
+
var _this$column2SqlColum2 = this.column2SqlColumn(groupbyColumn, {
|
|
296
|
+
dateGranularity: groupby_date_granularity,
|
|
297
|
+
geolocationGranularity: groupby_geolocation_granularity
|
|
298
|
+
}),
|
|
299
|
+
sqlGroupbyColumnName = _this$column2SqlColum2.name,
|
|
300
|
+
sqlGroupbyColumnKey = _this$column2SqlColum2.key;
|
|
301
|
+
var _this$column2SqlColum3 = this.column2SqlColumn(columnGroupbyColumn, {
|
|
302
|
+
dateGranularity: column_groupby_date_granularity,
|
|
303
|
+
geolocationGranularity: column_groupby_geolocation_granularity
|
|
304
|
+
}),
|
|
305
|
+
sqlColumnGroupbyColumn = _this$column2SqlColum3.name,
|
|
306
|
+
sqlColumnGroupbyColumnKey = _this$column2SqlColum3.key;
|
|
307
|
+
var sqlSummaryColumnName;
|
|
308
|
+
var sqlSummaryColumnKey;
|
|
309
|
+
if (summary_type === SUMMARY_TYPE.COUNT) {
|
|
310
|
+
var _this$summaryMethodCo5 = this.summaryMethodColumn2SqlColumn('Count', groupbyColumn),
|
|
311
|
+
name = _this$summaryMethodCo5.name,
|
|
312
|
+
key = _this$summaryMethodCo5.key;
|
|
313
|
+
sqlSummaryColumnName = name;
|
|
314
|
+
sqlSummaryColumnKey = key;
|
|
315
|
+
} else {
|
|
316
|
+
var summaryMethod = summary_method;
|
|
317
|
+
var summaryColumn = TableUtils.getTableColumnByKey(table, summary_column_key) || {};
|
|
318
|
+
var _this$summaryMethodCo6 = this.summaryMethodColumn2SqlColumn(summaryMethod, summaryColumn),
|
|
319
|
+
_name = _this$summaryMethodCo6.name,
|
|
320
|
+
_key = _this$summaryMethodCo6.key;
|
|
321
|
+
sqlSummaryColumnName = _name;
|
|
322
|
+
sqlSummaryColumnKey = _key;
|
|
323
|
+
if (column_groupby_multiple_numeric_column && column_groupby_column_key) {
|
|
324
|
+
var sqlSummaryMultipleNumericColumnName = Array.isArray(summary_columns_option) ? summary_columns_option.forEach(function (item) {
|
|
325
|
+
var summaryColumn = TableUtils.getTableColumnByKey(table, item.key) || {};
|
|
326
|
+
var _this2$summaryMethodC = _this2.summaryMethodColumn2SqlColumn(item.method, summaryColumn),
|
|
327
|
+
name = _this2$summaryMethodC.name;
|
|
328
|
+
return name;
|
|
329
|
+
}) : [];
|
|
330
|
+
sqlSummaryColumnName = sqlSummaryMultipleNumericColumnName;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
var sql = "SELECT ".concat(sqlGroupbyColumnName, ", ").concat(sqlColumnGroupbyColumn, ", ").concat(sqlSummaryColumnName, " FROM ").concat(tableName, " ").concat(condition, " GROUP BY ").concat(sqlGroupbyColumnName, ", ").concat(sqlColumnGroupbyColumn, " ORDER BY `").concat(groupbyColumn.name, "` LIMIT 0, 5000");
|
|
334
|
+
return {
|
|
335
|
+
sql: sql,
|
|
336
|
+
sqlGroupbyColumnKey: sqlGroupbyColumnKey,
|
|
337
|
+
sqlColumnGroupbyColumnKey: sqlColumnGroupbyColumnKey,
|
|
338
|
+
sqlSummaryColumnKey: sqlSummaryColumnKey
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}, {
|
|
342
|
+
key: "oneDimensionTableSQLResult2JavaScript",
|
|
343
|
+
value: function oneDimensionTableSQLResult2JavaScript(chart, sqlRows, statisticSQLMap, columnMap) {
|
|
344
|
+
var _this3 = this;
|
|
345
|
+
var groupbyColumn = columnMap.groupbyColumn;
|
|
346
|
+
var summary_type = chart.summary_type,
|
|
347
|
+
groupby_geolocation_granularity = chart.groupby_geolocation_granularity,
|
|
348
|
+
groupby_date_granularity = chart.groupby_date_granularity;
|
|
349
|
+
var pivot_columns = [];
|
|
350
|
+
var pivot_rows = [];
|
|
351
|
+
var isCount = summary_type === SUMMARY_TYPE.COUNT;
|
|
352
|
+
if (isCount) {
|
|
353
|
+
var _sqlGroupbyColumnKey = statisticSQLMap.sqlGroupbyColumnKey,
|
|
354
|
+
sqlSummaryColumnKey = statisticSQLMap.sqlSummaryColumnKey;
|
|
355
|
+
var _allTotal = 0;
|
|
356
|
+
sqlRows.forEach(function (row) {
|
|
357
|
+
var total = row[sqlSummaryColumnKey] || 0;
|
|
358
|
+
_allTotal += total;
|
|
359
|
+
pivot_rows.push({
|
|
360
|
+
name: _this3.getLabel(groupbyColumn, _sqlGroupbyColumnKey, row, groupby_geolocation_granularity, groupby_date_granularity),
|
|
361
|
+
rows: [],
|
|
362
|
+
total: {
|
|
363
|
+
total: total
|
|
364
|
+
},
|
|
365
|
+
original_name: row[groupbyColumn.key]
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
return {
|
|
369
|
+
pivot_columns: pivot_columns,
|
|
370
|
+
pivot_rows: pivot_rows,
|
|
371
|
+
pivot_columns_total: {
|
|
372
|
+
total: _allTotal
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
var sqlGroupbyColumnKey = statisticSQLMap.sqlGroupbyColumnKey,
|
|
377
|
+
summarySQLColumnName2ColumnKey = statisticSQLMap.summarySQLColumnName2ColumnKey,
|
|
378
|
+
summaryTableColumnKey2Column = statisticSQLMap.summaryTableColumnKey2Column,
|
|
379
|
+
summaryTableColumnKey2Method = statisticSQLMap.summaryTableColumnKey2Method;
|
|
380
|
+
var summaryColumnKeys = Object.values(summarySQLColumnName2ColumnKey);
|
|
381
|
+
var sqlSummaryColumnKeys = Object.keys(summarySQLColumnName2ColumnKey);
|
|
382
|
+
var totalTemplate = {};
|
|
383
|
+
Object.values(summaryColumnKeys).forEach(function (key) {
|
|
384
|
+
var summaryMethod = summaryTableColumnKey2Method[key];
|
|
385
|
+
totalTemplate[key + summaryMethod] = _this3.initTotal(summaryMethod);
|
|
386
|
+
pivot_columns.push({
|
|
387
|
+
key: key,
|
|
388
|
+
method: summaryMethod
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
var allTotal = _objectSpread({}, totalTemplate);
|
|
392
|
+
sqlRows.forEach(function (row) {
|
|
393
|
+
var rowTotal = _objectSpread({}, totalTemplate);
|
|
394
|
+
sqlSummaryColumnKeys.forEach(function (key) {
|
|
395
|
+
var columnKey = summarySQLColumnName2ColumnKey[key];
|
|
396
|
+
var summaryColumn = summaryTableColumnKey2Column[columnKey];
|
|
397
|
+
var summaryMethod = summaryTableColumnKey2Method[columnKey];
|
|
398
|
+
var value = row[key] || _this3.initTotal(summaryMethod);
|
|
399
|
+
allTotal[columnKey + summaryMethod] = _this3.getSummaryValue({
|
|
400
|
+
summaryColumn: summaryColumn,
|
|
401
|
+
summaryMethod: summaryMethod
|
|
402
|
+
}, allTotal[columnKey + summaryMethod], value);
|
|
403
|
+
if (summaryColumn && isDateColumn(summaryColumn)) {
|
|
404
|
+
rowTotal[columnKey + summaryMethod] = value;
|
|
405
|
+
} else if (summaryColumn && isNumericColumn(summaryColumn)) {
|
|
406
|
+
rowTotal[columnKey + summaryMethod] = rowTotal[columnKey + summaryMethod] + value;
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
pivot_rows.push({
|
|
410
|
+
name: _this3.getLabel(groupbyColumn, sqlGroupbyColumnKey, row, groupby_geolocation_granularity, groupby_date_granularity),
|
|
411
|
+
rows: [row],
|
|
412
|
+
total: rowTotal,
|
|
413
|
+
original_name: row[groupbyColumn.key]
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
if (pivot_columns.length < 2) {
|
|
417
|
+
var pivot_column = pivot_columns[0];
|
|
418
|
+
var key = pivot_column.key,
|
|
419
|
+
method = pivot_column.method;
|
|
420
|
+
pivot_rows.forEach(function (row) {
|
|
421
|
+
row.total = _objectSpread(_objectSpread({}, row.total), {}, {
|
|
422
|
+
total: row.total[key + method]
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
allTotal = _objectSpread(_objectSpread({}, allTotal), {}, {
|
|
426
|
+
total: allTotal[key + method]
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
return {
|
|
430
|
+
pivot_columns: pivot_columns,
|
|
431
|
+
pivot_rows: pivot_rows,
|
|
432
|
+
pivot_columns_total: allTotal
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
}, {
|
|
436
|
+
key: "twoDimensionTableSQLResult2JavaScript",
|
|
437
|
+
value: function twoDimensionTableSQLResult2JavaScript(chart, sqlRows, statisticSQLMap, columnMap) {
|
|
438
|
+
var _this4 = this;
|
|
439
|
+
var _ref2 = columnMap || {},
|
|
440
|
+
groupbyColumn = _ref2.groupbyColumn,
|
|
441
|
+
columnGroupbyColumn = _ref2.columnGroupbyColumn,
|
|
442
|
+
summaryColumn = _ref2.summaryColumn;
|
|
443
|
+
var table_id = chart.table_id,
|
|
444
|
+
groupby_include_empty_cells = chart.groupby_include_empty_cells,
|
|
445
|
+
summary_method = chart.summary_method,
|
|
446
|
+
groupby_date_granularity = chart.groupby_date_granularity,
|
|
447
|
+
groupby_geolocation_granularity = chart.groupby_geolocation_granularity,
|
|
448
|
+
column_groupby_geolocation_granularity = chart.column_groupby_geolocation_granularity,
|
|
449
|
+
column_groupby_date_granularity = chart.column_groupby_date_granularity,
|
|
450
|
+
summary_columns_option = chart.summary_columns_option;
|
|
451
|
+
var sqlGroupbyColumnKey = statisticSQLMap.sqlGroupbyColumnKey,
|
|
452
|
+
sqlColumnGroupbyColumnKey = statisticSQLMap.sqlColumnGroupbyColumnKey,
|
|
453
|
+
sqlSummaryColumnKey = statisticSQLMap.sqlSummaryColumnKey;
|
|
454
|
+
if (!sqlColumnGroupbyColumnKey) return this.oneDimensionTableSQLResult2JavaScript(chart, sqlRows, statisticSQLMap, columnMap);
|
|
455
|
+
var summaryMethod = summary_method ? summary_method.toUpperCase() : '';
|
|
456
|
+
var pivot_columns = [];
|
|
457
|
+
var pivot_rows = [];
|
|
458
|
+
var pivot_columns_total = {};
|
|
459
|
+
var isRowGroupbyColumnDataAsAnArray = !!MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[columnGroupbyColumn.type];
|
|
460
|
+
sqlRows.forEach(function (row) {
|
|
461
|
+
var groupbyColumnCellValue = row[sqlGroupbyColumnKey];
|
|
462
|
+
var groupbyColumnCellValueKey = _this4.getLabel(groupbyColumn, sqlGroupbyColumnKey, row, groupby_geolocation_granularity, groupby_date_granularity);
|
|
463
|
+
var columnGroupbyColumnCellValue = row[sqlColumnGroupbyColumnKey];
|
|
464
|
+
var columnGroupbyColumnCellValueKey = _this4.getLabel(columnGroupbyColumn, sqlColumnGroupbyColumnKey, row, column_groupby_geolocation_granularity, column_groupby_date_granularity);
|
|
465
|
+
var count = row[sqlSummaryColumnKey];
|
|
466
|
+
if (_this4.isValidCellValue(columnGroupbyColumnCellValue, groupby_include_empty_cells)) {
|
|
467
|
+
_this4.updateTwoDimensionColumns(pivot_columns, columnGroupbyColumnCellValueKey, columnGroupbyColumnCellValue, {
|
|
468
|
+
isIncludeEmpty: groupby_include_empty_cells,
|
|
469
|
+
isCellValueAsAnArray: isRowGroupbyColumnDataAsAnArray
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
if (_this4.isValidCellValue(groupbyColumnCellValue, groupby_include_empty_cells)) {
|
|
473
|
+
var pivotRowIndex = pivot_rows.findIndex(function (r) {
|
|
474
|
+
var resName = r.name;
|
|
475
|
+
return resName === null && groupbyColumnCellValueKey === null || resName === undefined && groupbyColumnCellValueKey === undefined || resName === 0 && groupbyColumnCellValueKey === 0 || resName === groupbyColumnCellValueKey;
|
|
476
|
+
});
|
|
477
|
+
_this4.updateTwoDimensionRows(pivot_rows, pivot_columns, pivotRowIndex, groupbyColumnCellValueKey, count, row, isRowGroupbyColumnDataAsAnArray, columnGroupbyColumnCellValueKey, groupbyColumnCellValue, {
|
|
478
|
+
summaryMethod: summaryMethod,
|
|
479
|
+
summaryColumn: summaryColumn
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
var pivot_table_total = this.getAndUpdateTwoDimensionTotal(pivot_columns_total, pivot_columns, pivot_rows, {
|
|
484
|
+
summaryMethod: summaryMethod,
|
|
485
|
+
summaryColumn: summaryColumn
|
|
486
|
+
});
|
|
487
|
+
var selectedTable = this.getTableById(table_id);
|
|
488
|
+
var pivot_summary_multiple_columns = [];
|
|
489
|
+
Array.isArray(summary_columns_option) && summary_columns_option.forEach(function (columnOption) {
|
|
490
|
+
var key = columnOption.key,
|
|
491
|
+
method = columnOption.method;
|
|
492
|
+
var column = TableUtils.getTableColumnByKey(selectedTable, columnOption.key);
|
|
493
|
+
var _this4$summaryMethodC = _this4.summaryMethodColumn2SqlColumn(columnOption.method, column, true),
|
|
494
|
+
name = _this4$summaryMethodC.name;
|
|
495
|
+
if (column && isNumericColumn(column)) {
|
|
496
|
+
pivot_summary_multiple_columns.push({
|
|
497
|
+
key: key,
|
|
498
|
+
method: method,
|
|
499
|
+
type: column.type,
|
|
500
|
+
column_name: column.name,
|
|
501
|
+
sqlKey: name
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
return {
|
|
506
|
+
pivot_columns: pivot_columns,
|
|
507
|
+
pivot_rows: pivot_rows,
|
|
508
|
+
pivot_columns_total: pivot_columns_total,
|
|
509
|
+
pivot_table_total: pivot_table_total,
|
|
510
|
+
pivot_summary_multiple_columns: pivot_summary_multiple_columns,
|
|
511
|
+
isSqlQuery: true
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
}, {
|
|
515
|
+
key: "column2SqlColumn",
|
|
516
|
+
value: function column2SqlColumn(column) {
|
|
517
|
+
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
518
|
+
dateGranularity = _ref3.dateGranularity,
|
|
519
|
+
geolocationGranularity = _ref3.geolocationGranularity;
|
|
520
|
+
var name = column.name,
|
|
521
|
+
type = column.type,
|
|
522
|
+
key = column.key;
|
|
523
|
+
var validColumnName = "`".concat(name, "`");
|
|
524
|
+
switch (type) {
|
|
525
|
+
case CellType.DATE:
|
|
526
|
+
case CellType.MTIME:
|
|
527
|
+
case CellType.CTIME:
|
|
528
|
+
{
|
|
529
|
+
var validDateGranularity = dateGranularity && dateGranularity.toUpperCase();
|
|
530
|
+
if (validDateGranularity === 'DAY') {
|
|
531
|
+
var _sqlColumnName = "ISODATE(".concat(validColumnName, ")");
|
|
532
|
+
return {
|
|
533
|
+
name: _sqlColumnName,
|
|
534
|
+
key: _sqlColumnName
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
if (validDateGranularity === 'WEEK') {
|
|
538
|
+
var _sqlColumnName2 = "ISODATE(STARTOFWEEK(".concat(validColumnName, ", monday\"))");
|
|
539
|
+
return {
|
|
540
|
+
name: _sqlColumnName2,
|
|
541
|
+
key: _sqlColumnName2
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
if (validDateGranularity === 'MONTH') {
|
|
545
|
+
var _sqlColumnName3 = "ISOMONTH(".concat(validColumnName, ")");
|
|
546
|
+
return {
|
|
547
|
+
name: _sqlColumnName3,
|
|
548
|
+
key: _sqlColumnName3
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
if (validDateGranularity === 'QUARTER') {
|
|
552
|
+
var _sqlColumnName4 = "CONCATENATE(year(".concat(validColumnName, "), \"-Q\", quarter(").concat(validColumnName, "))");
|
|
553
|
+
return {
|
|
554
|
+
name: _sqlColumnName4,
|
|
555
|
+
key: _sqlColumnName4
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
if (validDateGranularity === 'YEAR') {
|
|
559
|
+
var _sqlColumnName5 = "YEAR(".concat(validColumnName, ")");
|
|
560
|
+
return {
|
|
561
|
+
name: _sqlColumnName5,
|
|
562
|
+
key: _sqlColumnName5
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
if (validDateGranularity === 'MAX' || validDateGranularity === 'MIN') {
|
|
566
|
+
var _sqlColumnName6 = "".concat(validDateGranularity, "(").concat(validColumnName, ")");
|
|
567
|
+
return {
|
|
568
|
+
name: _sqlColumnName6,
|
|
569
|
+
key: _sqlColumnName6
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
var sqlColumnName = "ISOMONTH(".concat(validColumnName, ")");
|
|
573
|
+
return {
|
|
574
|
+
name: sqlColumnName,
|
|
575
|
+
key: sqlColumnName
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
case CellType.GEOLOCATION:
|
|
579
|
+
{
|
|
580
|
+
var _sqlColumnName7;
|
|
581
|
+
if (geolocationGranularity === 'province') {
|
|
582
|
+
_sqlColumnName7 = "PROVINCE(".concat(validColumnName, ")");
|
|
583
|
+
}
|
|
584
|
+
if (geolocationGranularity === 'city') {
|
|
585
|
+
_sqlColumnName7 = "CITY(".concat(validColumnName, ")");
|
|
586
|
+
}
|
|
587
|
+
if (geolocationGranularity === 'district') {
|
|
588
|
+
_sqlColumnName7 = "DISTRICT(".concat(validColumnName, ")");
|
|
589
|
+
}
|
|
590
|
+
return {
|
|
591
|
+
name: _sqlColumnName7,
|
|
592
|
+
key: _sqlColumnName7
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
default:
|
|
596
|
+
{
|
|
597
|
+
return {
|
|
598
|
+
name: validColumnName,
|
|
599
|
+
key: key
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}, {
|
|
605
|
+
key: "summaryMethodColumn2SqlColumn",
|
|
606
|
+
value: function summaryMethodColumn2SqlColumn(summaryMethod, column, useSingleQuote) {
|
|
607
|
+
var columnName = column.name;
|
|
608
|
+
var isUseSingleQuote = useSingleQuote ? false : true;
|
|
609
|
+
return {
|
|
610
|
+
name: getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[summaryMethod], columnName, isUseSingleQuote),
|
|
611
|
+
key: getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[summaryMethod], columnName)
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
}, {
|
|
615
|
+
key: "getLabel",
|
|
616
|
+
value: function getLabel(groupColumn, groupName, statRow, groupby_date_granularity, groupby_geolocation_granularity) {
|
|
617
|
+
var isTimeColumn = TIME_COLUMN_LIST.includes(groupColumn.type);
|
|
618
|
+
var label;
|
|
619
|
+
if (isTimeColumn || groupColumn.type === CellType.GEOLOCATION) {
|
|
620
|
+
label = statRow[groupName];
|
|
621
|
+
} else {
|
|
622
|
+
var currentGroupLabel = statRow[groupColumn.key];
|
|
623
|
+
label = StatUtils.getGroupLabel(currentGroupLabel, {}, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
|
|
624
|
+
label = getFormattedLabel(groupColumn, label, this.value.collaborators);
|
|
625
|
+
}
|
|
626
|
+
return label;
|
|
627
|
+
}
|
|
628
|
+
}, {
|
|
629
|
+
key: "initTotal",
|
|
630
|
+
value: function initTotal(summaryMethod) {
|
|
631
|
+
if (summaryMethod === 'SUM' || summaryMethod === 'DISTINCT_VALUES') return 0;
|
|
632
|
+
return null;
|
|
633
|
+
}
|
|
634
|
+
}, {
|
|
635
|
+
key: "getSummaryValue",
|
|
636
|
+
value: function getSummaryValue(_ref4, currentValue, nextValue) {
|
|
637
|
+
var summaryMethod = _ref4.summaryMethod,
|
|
638
|
+
summaryColumn = _ref4.summaryColumn;
|
|
639
|
+
if (summaryColumn && isDateColumn(summaryColumn)) {
|
|
640
|
+
if (summaryMethod === 'Max') {
|
|
641
|
+
if (currentValue && nextValue) {
|
|
642
|
+
return dayjs(currentValue).isBefore(nextValue) ? nextValue : currentValue;
|
|
643
|
+
}
|
|
644
|
+
if (!currentValue && nextValue) {
|
|
645
|
+
return nextValue;
|
|
646
|
+
}
|
|
647
|
+
return currentValue;
|
|
648
|
+
}
|
|
649
|
+
if (summaryMethod === 'Min') {
|
|
650
|
+
if (currentValue && nextValue) {
|
|
651
|
+
return dayjs(currentValue).isBefore(nextValue) ? currentValue : nextValue;
|
|
652
|
+
}
|
|
653
|
+
if (!currentValue && nextValue) {
|
|
654
|
+
return nextValue;
|
|
655
|
+
}
|
|
656
|
+
return currentValue;
|
|
657
|
+
}
|
|
658
|
+
return currentValue;
|
|
659
|
+
}
|
|
660
|
+
if (summaryMethod === 'MAX' || summaryMethod === 'MIN') {
|
|
661
|
+
if (currentValue === null && nextValue === null) return null;
|
|
662
|
+
if (currentValue === null) return nextValue;
|
|
663
|
+
if (nextValue === null) return currentValue;
|
|
664
|
+
}
|
|
665
|
+
return (currentValue - 0 || 0) + (nextValue - 0 || 0);
|
|
666
|
+
}
|
|
667
|
+
}, {
|
|
668
|
+
key: "isValidCellValue",
|
|
669
|
+
value: function isValidCellValue(cellValue, includeEmpty) {
|
|
670
|
+
if (includeEmpty) return true;
|
|
671
|
+
return cellValue || cellValue === 0;
|
|
672
|
+
}
|
|
673
|
+
}, {
|
|
674
|
+
key: "updateTwoDimensionColumns",
|
|
675
|
+
value: function updateTwoDimensionColumns(pivot_columns, key, columnCellValue, _ref5) {
|
|
676
|
+
var isIncludeEmpty = _ref5.isIncludeEmpty,
|
|
677
|
+
isCellValueAsAnArray = _ref5.isCellValueAsAnArray;
|
|
678
|
+
if (isCellValueAsAnArray) {
|
|
679
|
+
if (key.length === 0 && isIncludeEmpty) {
|
|
680
|
+
var _pivotColumnIndex = pivot_columns.findIndex(function (r) {
|
|
681
|
+
return !r.key;
|
|
682
|
+
});
|
|
683
|
+
if (_pivotColumnIndex < 0) {
|
|
684
|
+
pivot_columns.unshift({
|
|
685
|
+
key: null
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
key.forEach(function (k) {
|
|
691
|
+
var pivotColumnIndex = pivot_columns.findIndex(function (r) {
|
|
692
|
+
return r.key === k;
|
|
693
|
+
});
|
|
694
|
+
if (pivotColumnIndex < 0) {
|
|
695
|
+
pivot_columns.push({
|
|
696
|
+
key: k,
|
|
697
|
+
original_name: k
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
var pivotColumnIndex = pivot_columns.findIndex(function (r) {
|
|
704
|
+
var resKey = r.key;
|
|
705
|
+
return resKey === null && key === null || resKey === undefined && key === undefined || resKey === 0 && key === 0 || resKey === key;
|
|
706
|
+
});
|
|
707
|
+
if (pivotColumnIndex < 0) {
|
|
708
|
+
pivot_columns.push({
|
|
709
|
+
key: key,
|
|
710
|
+
original_name: columnCellValue
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}, {
|
|
715
|
+
key: "updateTwoDimensionRows",
|
|
716
|
+
value: function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, count, row, isColumnDataAsAnArray, cellValue, format_cell_value, _ref6) {
|
|
717
|
+
var _this5 = this;
|
|
718
|
+
var summaryMethod = _ref6.summaryMethod,
|
|
719
|
+
summaryColumn = _ref6.summaryColumn;
|
|
720
|
+
if (index > -1) {
|
|
721
|
+
var updatedPivotRow = pivot_rows[index];
|
|
722
|
+
var cells = updatedPivotRow.cells,
|
|
723
|
+
total = updatedPivotRow.total;
|
|
724
|
+
pivot_columns.forEach(function (c) {
|
|
725
|
+
var key = c.key;
|
|
726
|
+
if (_this5.isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
727
|
+
if (cells[key]) {
|
|
728
|
+
cells[key].rows.push(row);
|
|
729
|
+
cells[key].total = _this5.getSummaryValue({
|
|
730
|
+
summaryMethod: summaryMethod,
|
|
731
|
+
summaryColumn: summaryColumn
|
|
732
|
+
}, cells[key].total, count);
|
|
733
|
+
} else {
|
|
734
|
+
cells[key] = {
|
|
735
|
+
rows: [row],
|
|
736
|
+
total: count
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
updatedPivotRow.cells = cells;
|
|
742
|
+
updatedPivotRow.total = this.getSummaryValue({
|
|
743
|
+
summaryMethod: summaryMethod,
|
|
744
|
+
summaryColumn: summaryColumn
|
|
745
|
+
}, total, count);
|
|
746
|
+
pivot_rows[index] = updatedPivotRow;
|
|
747
|
+
} else {
|
|
748
|
+
var _cells = {};
|
|
749
|
+
var _total = 0;
|
|
750
|
+
pivot_columns.forEach(function (c) {
|
|
751
|
+
var key = c.key;
|
|
752
|
+
if (_this5.isSameGroup(isColumnDataAsAnArray, cellValue, key)) {
|
|
753
|
+
_cells[key] = {
|
|
754
|
+
rows: [row],
|
|
755
|
+
total: count
|
|
756
|
+
};
|
|
757
|
+
_total = _this5.getSummaryValue({
|
|
758
|
+
summaryMethod: summaryMethod,
|
|
759
|
+
summaryColumn: summaryColumn
|
|
760
|
+
}, _total, count);
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
pivot_rows.push({
|
|
764
|
+
name: name,
|
|
765
|
+
cells: _cells,
|
|
766
|
+
total: _total,
|
|
767
|
+
original_name: format_cell_value
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}, {
|
|
772
|
+
key: "isSameGroup",
|
|
773
|
+
value: function isSameGroup(isColumnDataAsAnArray, source, target) {
|
|
774
|
+
if (isColumnDataAsAnArray) {
|
|
775
|
+
return source.length === 0 && !target || source.includes(target);
|
|
776
|
+
}
|
|
777
|
+
return source === null && target === null || source === undefined && target === undefined || source === target;
|
|
778
|
+
}
|
|
779
|
+
}, {
|
|
780
|
+
key: "getAndUpdateTwoDimensionTotal",
|
|
781
|
+
value: function getAndUpdateTwoDimensionTotal(pivot_columns_total, pivot_columns, pivot_rows, _ref7) {
|
|
782
|
+
var _this6 = this;
|
|
783
|
+
var summaryMethod = _ref7.summaryMethod,
|
|
784
|
+
summaryColumn = _ref7.summaryColumn;
|
|
785
|
+
var pivot_table_total = this.initTotal(summaryMethod);
|
|
786
|
+
pivot_rows.forEach(function (row) {
|
|
787
|
+
var cells = row.cells,
|
|
788
|
+
total = row.total;
|
|
789
|
+
pivot_table_total = _this6.getSummaryValue({
|
|
790
|
+
summaryMethod: summaryMethod,
|
|
791
|
+
summaryColumn: summaryColumn
|
|
792
|
+
}, pivot_table_total, total);
|
|
793
|
+
pivot_columns.forEach(function (column) {
|
|
794
|
+
var key = column.key;
|
|
795
|
+
var cell = cells[key];
|
|
796
|
+
if (cell) {
|
|
797
|
+
var pivot_column_total = pivot_columns_total && pivot_columns_total[key] ? pivot_columns_total[key] : 0;
|
|
798
|
+
pivot_columns_total[key] = _this6.getSummaryValue({
|
|
799
|
+
summaryMethod: summaryMethod,
|
|
800
|
+
summaryColumn: summaryColumn
|
|
801
|
+
}, pivot_column_total, cell.total);
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
});
|
|
805
|
+
return pivot_table_total;
|
|
806
|
+
}
|
|
807
|
+
}]);
|
|
808
|
+
return PivotTableCalculator;
|
|
809
|
+
}(BaseCalculator);
|
|
810
|
+
export default PivotTableCalculator;
|