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