dtable-statistic 4.2.2 → 4.3.1
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,9 +1,3 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
6
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
7
1
|
import { CellType, filter2SqlCondition, TableUtils } from 'dtable-store';
|
|
8
2
|
import BaseCalculator from './base-calculator';
|
|
9
3
|
import { DTABLE_DB_SUMMARY_METHOD, STAT_TYPE, SUMMARY_TYPE, TIME_COLUMN_LIST, Y_AXIS_TYPE_PREFIX } from '../constants';
|
|
@@ -12,569 +6,351 @@ import { formatNumericValue, getSummaryColumnMethod } from '../utils/common-util
|
|
|
12
6
|
import StatUtils from '../utils/stat-utils';
|
|
13
7
|
import { getColorFromSingleSelectColumn } from '../utils/column-utils';
|
|
14
8
|
import { getFormattedLabel } from '../utils/row-utils';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
userId: userId
|
|
9
|
+
class BasicChartCalculator extends BaseCalculator {
|
|
10
|
+
constructor(_ref) {
|
|
11
|
+
let {
|
|
12
|
+
value,
|
|
13
|
+
statisticThreadManager,
|
|
14
|
+
username,
|
|
15
|
+
userId
|
|
16
|
+
} = _ref;
|
|
17
|
+
super({
|
|
18
|
+
value,
|
|
19
|
+
statisticThreadManager,
|
|
20
|
+
username,
|
|
21
|
+
userId
|
|
29
22
|
});
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!this.validateBaseConfigs(chart)) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
if (chart.type === STAT_TYPE.CUSTOM_BAR) {
|
|
38
|
-
return this.isValidCustomBar(chart);
|
|
39
|
-
}
|
|
40
|
-
var table_id = chart.table_id,
|
|
41
|
-
groupby_column_key = chart.groupby_column_key,
|
|
42
|
-
x_axis_column_key = chart.x_axis_column_key,
|
|
43
|
-
summary_column_key = chart.summary_column_key,
|
|
44
|
-
y_axis_column_key = chart.y_axis_column_key;
|
|
45
|
-
var table = this.getTableById(table_id);
|
|
46
|
-
var groupbyColumnKey = groupby_column_key || x_axis_column_key;
|
|
47
|
-
if (!groupbyColumnKey || !TableUtils.getTableColumnByKey(table, groupbyColumnKey)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
var summaryColumnKey = summary_column_key || y_axis_column_key;
|
|
51
|
-
if (summaryColumnKey && !TableUtils.getTableColumnByKey(table, summaryColumnKey)) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
24
|
+
isValidChart(chart) {
|
|
25
|
+
if (!this.validateBaseConfigs(chart)) {
|
|
26
|
+
return false;
|
|
55
27
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
value: function isValidCustomBar(chart) {
|
|
59
|
-
var table_id = chart.table_id,
|
|
60
|
-
x_axis_column_key = chart.x_axis_column_key,
|
|
61
|
-
y_axises = chart.y_axises;
|
|
62
|
-
var table = this.getTableById(table_id);
|
|
63
|
-
if (!table.columns.find(function (column) {
|
|
64
|
-
return column.key === x_axis_column_key;
|
|
65
|
-
}) || !Array.isArray(y_axises) || y_axises.length === 0 || y_axises.every(function (yAxis) {
|
|
66
|
-
return !Array.isArray(yAxis.column_groupby_numeric_columns) || yAxis.column_groupby_numeric_columns.length === 0;
|
|
67
|
-
})) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
28
|
+
if (chart.type === STAT_TYPE.CUSTOM_BAR) {
|
|
29
|
+
return this.isValidCustomBar(chart);
|
|
71
30
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
31
|
+
const {
|
|
32
|
+
table_id,
|
|
33
|
+
groupby_column_key,
|
|
34
|
+
x_axis_column_key,
|
|
35
|
+
summary_column_key,
|
|
36
|
+
y_axis_column_key
|
|
37
|
+
} = chart;
|
|
38
|
+
const table = this.getTableById(table_id);
|
|
39
|
+
const groupbyColumnKey = groupby_column_key || x_axis_column_key;
|
|
40
|
+
if (!groupbyColumnKey || !TableUtils.getTableColumnByKey(table, groupbyColumnKey)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const summaryColumnKey = summary_column_key || y_axis_column_key;
|
|
44
|
+
if (summaryColumnKey && !TableUtils.getTableColumnByKey(table, summaryColumnKey)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
isValidCustomBar(chart) {
|
|
50
|
+
const {
|
|
51
|
+
table_id,
|
|
52
|
+
x_axis_column_key,
|
|
53
|
+
y_axises
|
|
54
|
+
} = chart;
|
|
55
|
+
const table = this.getTableById(table_id);
|
|
56
|
+
if (!table.columns.find(column => column.key === x_axis_column_key) || !Array.isArray(y_axises) || y_axises.length === 0 || y_axises.every(yAxis => !Array.isArray(yAxis.column_groupby_numeric_columns) || yAxis.column_groupby_numeric_columns.length === 0)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
async calculate(chart) {
|
|
62
|
+
if (!this.isValidChart(chart)) return [];
|
|
63
|
+
if (this.isCalcByQueryDB(chart)) {
|
|
64
|
+
return await this.queryDb(chart);
|
|
65
|
+
}
|
|
66
|
+
return await this.calculateWithWorker(chart);
|
|
67
|
+
}
|
|
68
|
+
async queryDb(chart) {
|
|
69
|
+
if (chart.type === STAT_TYPE.CUSTOM_BAR) {
|
|
70
|
+
return this.queryDbFromCustomBar(chart);
|
|
71
|
+
}
|
|
72
|
+
const {
|
|
73
|
+
table_id,
|
|
74
|
+
view_id,
|
|
75
|
+
column_groupby_multiple_numeric_column
|
|
76
|
+
} = chart;
|
|
77
|
+
let groupby_column_key, summary_type, summary_method, summary_column_key, groupby_date_granularity, include_empty, groupby_geolocation_granularity;
|
|
78
|
+
const column_groupby_column_key = chart.column_groupby_column_key;
|
|
79
|
+
const sortType = chart.sort_type;
|
|
80
|
+
if (chart.type === STAT_TYPE.PIE || chart.type === STAT_TYPE.RING || chart.type === STAT_TYPE.TREEMAP) {
|
|
81
|
+
groupby_column_key = chart.groupby_column_key;
|
|
82
|
+
summary_type = chart.summary_type;
|
|
83
|
+
summary_method = chart.summary_method;
|
|
84
|
+
summary_column_key = chart.summary_column_key;
|
|
85
|
+
groupby_date_granularity = chart.groupby_date_granularity;
|
|
86
|
+
include_empty = chart.groupby_include_empty_cells;
|
|
87
|
+
groupby_geolocation_granularity = chart.groupby_geolocation_granularity;
|
|
88
|
+
} else {
|
|
89
|
+
groupby_column_key = chart.x_axis_column_key;
|
|
90
|
+
summary_type = chart.y_axis_summary_type;
|
|
91
|
+
summary_method = chart.y_axis_summary_method;
|
|
92
|
+
summary_column_key = chart.y_axis_column_key;
|
|
93
|
+
groupby_date_granularity = chart.x_axis_date_granularity;
|
|
94
|
+
groupby_geolocation_granularity = chart.x_axis_geolocation_granularity;
|
|
95
|
+
include_empty = chart.x_axis_include_empty;
|
|
96
|
+
}
|
|
97
|
+
const yAxisType = null;
|
|
98
|
+
const selectedTable = this.getTableById(table_id);
|
|
99
|
+
const selectedView = this.getViewById(view_id, selectedTable);
|
|
100
|
+
if (!selectedView) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const groupbyColumn = TableUtils.getTableColumnByKey(selectedTable, groupby_column_key);
|
|
104
|
+
const sqlCondition = filter2SqlCondition(selectedTable, selectedView);
|
|
105
|
+
let groupbyName = "`".concat(groupbyColumn.name, "`");
|
|
106
|
+
const isTimeColumn = TIME_COLUMN_LIST.includes(groupbyColumn.type);
|
|
107
|
+
if (isTimeColumn) {
|
|
108
|
+
groupbyName = getSqlGroup(groupby_date_granularity, groupbyColumn);
|
|
109
|
+
} else if (groupbyColumn.type === CellType.GEOLOCATION) {
|
|
110
|
+
groupbyName = getSqlGroup(groupby_geolocation_granularity, groupbyColumn);
|
|
111
|
+
}
|
|
112
|
+
let results;
|
|
113
|
+
if (!column_groupby_column_key && !column_groupby_multiple_numeric_column) {
|
|
114
|
+
results = await this.getNoneGroupbyResults(groupbyName, groupbyColumn, groupby_date_granularity, groupby_geolocation_granularity, include_empty, summary_type, summary_column_key, summary_method, sortType, sqlCondition, selectedTable, yAxisType);
|
|
115
|
+
} else if (column_groupby_multiple_numeric_column) {
|
|
116
|
+
const {
|
|
117
|
+
column_groupby_numeric_columns
|
|
118
|
+
} = chart;
|
|
119
|
+
const summaryColumn = TableUtils.getTableColumnByKey(selectedTable, summary_column_key);
|
|
120
|
+
if (!summaryColumn) return [];
|
|
121
|
+
results = await this.getGroupbyMultipleNumericColumnsResults(groupbyName, groupbyColumn, groupby_date_granularity, groupby_geolocation_granularity, include_empty, summary_type, summaryColumn, summary_method, column_groupby_numeric_columns, sqlCondition, selectedTable, yAxisType);
|
|
122
|
+
} else {
|
|
123
|
+
const {
|
|
124
|
+
column_groupby_date_granularity,
|
|
125
|
+
column_groupby_geolocation_granularity
|
|
126
|
+
} = chart;
|
|
127
|
+
results = await this.getGroupbyOneColumnResults(groupbyName, groupbyColumn, groupby_date_granularity, groupby_geolocation_granularity, include_empty, summary_type, summary_column_key, summary_method, column_groupby_column_key, column_groupby_date_granularity, column_groupby_geolocation_granularity, sqlCondition, selectedTable, yAxisType);
|
|
128
|
+
}
|
|
129
|
+
sortType && StatUtils.sortStatisticData(results, sortType);
|
|
130
|
+
return results;
|
|
131
|
+
}
|
|
132
|
+
async queryDbFromCustomBar(chart) {
|
|
133
|
+
const {
|
|
134
|
+
table_id,
|
|
135
|
+
view_id,
|
|
136
|
+
x_axis_column_key,
|
|
137
|
+
x_axis_date_granularity,
|
|
138
|
+
x_axis_geolocation_granularity,
|
|
139
|
+
x_axis_include_empty,
|
|
140
|
+
y_axises,
|
|
141
|
+
sort_type
|
|
142
|
+
} = chart;
|
|
143
|
+
const selectedTable = this.getTableById(table_id);
|
|
144
|
+
const selectedView = this.getViewById(view_id, selectedTable);
|
|
145
|
+
if (!selectedView || !x_axis_column_key || !Array.isArray(y_axises) || y_axises.length === 0) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
const groupbyColumn = TableUtils.getTableColumnByKey(selectedTable, x_axis_column_key);
|
|
149
|
+
if (!groupbyColumn) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
const sqlCondition = filter2SqlCondition(selectedTable, selectedView);
|
|
153
|
+
const isTimeColumn = TIME_COLUMN_LIST.includes(groupbyColumn.type);
|
|
154
|
+
let groupbyName = "`".concat(groupbyColumn.name, "`");
|
|
155
|
+
if (isTimeColumn) {
|
|
156
|
+
groupbyName = getSqlGroup(x_axis_date_granularity, groupbyColumn);
|
|
157
|
+
} else if (groupbyColumn.type === CellType.GEOLOCATION) {
|
|
158
|
+
groupbyName = getSqlGroup(x_axis_geolocation_granularity, groupbyColumn);
|
|
159
|
+
}
|
|
160
|
+
const summaryType = SUMMARY_TYPE.ADVANCED;
|
|
161
|
+
const yAxisSummaryColumn = null;
|
|
162
|
+
const yAxisSummaryMethod = null;
|
|
163
|
+
let results = [];
|
|
164
|
+
for (let i = 0, len = y_axises.length; i < len; i++) {
|
|
165
|
+
const stack = y_axises[i];
|
|
166
|
+
const {
|
|
167
|
+
type: yAxisType,
|
|
168
|
+
column_groupby_numeric_columns
|
|
169
|
+
} = stack;
|
|
170
|
+
if (yAxisType === STAT_TYPE.BAR_STACK) {
|
|
171
|
+
// just support summary numeric columns.
|
|
172
|
+
if (!Array.isArray(column_groupby_numeric_columns) || column_groupby_numeric_columns.length === 0) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const yAxisType = "".concat(Y_AXIS_TYPE_PREFIX).concat(i);
|
|
176
|
+
const currentResults = await this.getGroupbyMultipleNumericColumnsResults(groupbyName, groupbyColumn, x_axis_date_granularity, x_axis_geolocation_granularity, x_axis_include_empty, summaryType, yAxisSummaryColumn, yAxisSummaryMethod, column_groupby_numeric_columns, sqlCondition, selectedTable, yAxisType);
|
|
177
|
+
results = results.concat(currentResults);
|
|
211
178
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
groupbyName = "`".concat(groupbyColumn.name, "`");
|
|
242
|
-
if (isTimeColumn) {
|
|
243
|
-
groupbyName = getSqlGroup(x_axis_date_granularity, groupbyColumn);
|
|
244
|
-
} else if (groupbyColumn.type === CellType.GEOLOCATION) {
|
|
245
|
-
groupbyName = getSqlGroup(x_axis_geolocation_granularity, groupbyColumn);
|
|
246
|
-
}
|
|
247
|
-
summaryType = SUMMARY_TYPE.ADVANCED;
|
|
248
|
-
yAxisSummaryColumn = null;
|
|
249
|
-
yAxisSummaryMethod = null;
|
|
250
|
-
results = [];
|
|
251
|
-
i = 0, len = y_axises.length;
|
|
252
|
-
case 17:
|
|
253
|
-
if (!(i < len)) {
|
|
254
|
-
_context3.next = 31;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
stack = y_axises[i];
|
|
258
|
-
yAxisType = stack.type, column_groupby_numeric_columns = stack.column_groupby_numeric_columns;
|
|
259
|
-
if (!(yAxisType === STAT_TYPE.BAR_STACK)) {
|
|
260
|
-
_context3.next = 28;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
if (!(!Array.isArray(column_groupby_numeric_columns) || column_groupby_numeric_columns.length === 0)) {
|
|
264
|
-
_context3.next = 23;
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
return _context3.abrupt("continue", 28);
|
|
268
|
-
case 23:
|
|
269
|
-
_yAxisType = "".concat(Y_AXIS_TYPE_PREFIX).concat(i);
|
|
270
|
-
_context3.next = 26;
|
|
271
|
-
return this.getGroupbyMultipleNumericColumnsResults(groupbyName, groupbyColumn, x_axis_date_granularity, x_axis_geolocation_granularity, x_axis_include_empty, summaryType, yAxisSummaryColumn, yAxisSummaryMethod, column_groupby_numeric_columns, sqlCondition, selectedTable, _yAxisType);
|
|
272
|
-
case 26:
|
|
273
|
-
currentResults = _context3.sent;
|
|
274
|
-
results = results.concat(currentResults);
|
|
275
|
-
case 28:
|
|
276
|
-
i++;
|
|
277
|
-
_context3.next = 17;
|
|
278
|
-
break;
|
|
279
|
-
case 31:
|
|
280
|
-
sort_type && StatUtils.sortStatisticData(results, sort_type);
|
|
281
|
-
return _context3.abrupt("return", results);
|
|
282
|
-
case 33:
|
|
283
|
-
case "end":
|
|
284
|
-
return _context3.stop();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}, _callee3, this);
|
|
288
|
-
}));
|
|
289
|
-
function queryDbFromCustomBar(_x3) {
|
|
290
|
-
return _queryDbFromCustomBar.apply(this, arguments);
|
|
179
|
+
}
|
|
180
|
+
sort_type && StatUtils.sortStatisticData(results, sort_type);
|
|
181
|
+
return results;
|
|
182
|
+
}
|
|
183
|
+
async getNoneGroupbyResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumnKey, summaryMethod, sortType, sqlCondition, table, yAxisType) {
|
|
184
|
+
const isAdvanced = summaryType === SUMMARY_TYPE.ADVANCED;
|
|
185
|
+
let selectedSummaryColumn;
|
|
186
|
+
let summaryColumnName = "`".concat(groupbyColumn.name, "`");
|
|
187
|
+
if (isAdvanced) {
|
|
188
|
+
selectedSummaryColumn = TableUtils.getTableColumnByKey(table, summaryColumnKey);
|
|
189
|
+
if (!selectedSummaryColumn) return [];
|
|
190
|
+
summaryColumnName = selectedSummaryColumn.name;
|
|
191
|
+
}
|
|
192
|
+
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
193
|
+
const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
194
|
+
const sqlOrder = getSqlOrder(sortType, groupbyName);
|
|
195
|
+
const sqlString = "select ".concat(groupbyName, ", ").concat(summaryColumnMethod, " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " ").concat(sqlOrder, " limit 5000");
|
|
196
|
+
const queryResult = await this.sqlQuery(sqlString);
|
|
197
|
+
if (queryResult.status !== 200 || !queryResult.data.success) {
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
const data = queryResult.data;
|
|
201
|
+
if (!data.results) return [];
|
|
202
|
+
let newResult = [];
|
|
203
|
+
const valueKey = isAdvanced ? "".concat(summaryColumnMethod) : "".concat(method, "(").concat(groupbyColumn.name, ")");
|
|
204
|
+
data.results.forEach(item => {
|
|
205
|
+
let label = this.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
206
|
+
if (!includeEmpty && this.isEmptyLabel(label)) {
|
|
207
|
+
return;
|
|
291
208
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
var _getNoneGroupbyResults = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumnKey, summaryMethod, sortType, sqlCondition, table, yAxisType) {
|
|
298
|
-
var _this = this;
|
|
299
|
-
var isAdvanced, selectedSummaryColumn, summaryColumnName, method, summaryColumnMethod, sqlOrder, sqlString, queryResult, data, newResult, valueKey;
|
|
300
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
301
|
-
while (1) {
|
|
302
|
-
switch (_context4.prev = _context4.next) {
|
|
303
|
-
case 0:
|
|
304
|
-
isAdvanced = summaryType === SUMMARY_TYPE.ADVANCED;
|
|
305
|
-
summaryColumnName = "`".concat(groupbyColumn.name, "`");
|
|
306
|
-
if (!isAdvanced) {
|
|
307
|
-
_context4.next = 7;
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
selectedSummaryColumn = TableUtils.getTableColumnByKey(table, summaryColumnKey);
|
|
311
|
-
if (selectedSummaryColumn) {
|
|
312
|
-
_context4.next = 6;
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
return _context4.abrupt("return", []);
|
|
316
|
-
case 6:
|
|
317
|
-
summaryColumnName = selectedSummaryColumn.name;
|
|
318
|
-
case 7:
|
|
319
|
-
method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
320
|
-
summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
321
|
-
sqlOrder = getSqlOrder(sortType, groupbyName);
|
|
322
|
-
sqlString = "select ".concat(groupbyName, ", ").concat(summaryColumnMethod, " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " ").concat(sqlOrder, " limit 5000");
|
|
323
|
-
_context4.next = 13;
|
|
324
|
-
return this.sqlQuery(sqlString);
|
|
325
|
-
case 13:
|
|
326
|
-
queryResult = _context4.sent;
|
|
327
|
-
if (!(queryResult.status !== 200 || !queryResult.data.success)) {
|
|
328
|
-
_context4.next = 16;
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
return _context4.abrupt("return", []);
|
|
332
|
-
case 16:
|
|
333
|
-
data = queryResult.data;
|
|
334
|
-
if (data.results) {
|
|
335
|
-
_context4.next = 19;
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
return _context4.abrupt("return", []);
|
|
339
|
-
case 19:
|
|
340
|
-
newResult = [];
|
|
341
|
-
valueKey = isAdvanced ? "".concat(summaryColumnMethod) : "".concat(method, "(").concat(groupbyColumn.name, ")");
|
|
342
|
-
data.results.forEach(function (item) {
|
|
343
|
-
var label = _this.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
344
|
-
if (!includeEmpty && _this.isEmptyLabel(label)) {
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
var value = item[valueKey] || 0;
|
|
348
|
-
var formatted_value = value;
|
|
349
|
-
if (isAdvanced) {
|
|
350
|
-
value = formatNumericValue(value, selectedSummaryColumn);
|
|
351
|
-
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, summaryMethod);
|
|
352
|
-
}
|
|
353
|
-
newResult.push({
|
|
354
|
-
name: label,
|
|
355
|
-
value: value,
|
|
356
|
-
formatted_value: formatted_value,
|
|
357
|
-
original_name: item[groupbyColumn.key],
|
|
358
|
-
y_axis_type: yAxisType
|
|
359
|
-
});
|
|
360
|
-
});
|
|
361
|
-
return _context4.abrupt("return", newResult);
|
|
362
|
-
case 23:
|
|
363
|
-
case "end":
|
|
364
|
-
return _context4.stop();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}, _callee4, this);
|
|
368
|
-
}));
|
|
369
|
-
function getNoneGroupbyResults(_x4, _x5, _x6, _x7, _x8, _x9, _x10, _x11, _x12, _x13, _x14, _x15) {
|
|
370
|
-
return _getNoneGroupbyResults.apply(this, arguments);
|
|
209
|
+
let value = item[valueKey] || 0;
|
|
210
|
+
let formatted_value = value;
|
|
211
|
+
if (isAdvanced) {
|
|
212
|
+
value = formatNumericValue(value, selectedSummaryColumn);
|
|
213
|
+
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, summaryMethod);
|
|
371
214
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (!(queryResult.status !== 200 || !queryResult.data.success)) {
|
|
414
|
-
_context5.next = 18;
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
return _context5.abrupt("return", []);
|
|
418
|
-
case 18:
|
|
419
|
-
data = queryResult.data;
|
|
420
|
-
if (data.results) {
|
|
421
|
-
_context5.next = 21;
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
424
|
-
return _context5.abrupt("return", []);
|
|
425
|
-
case 21:
|
|
426
|
-
newResult = [];
|
|
427
|
-
valueKey = isAdvanced ? "".concat(summaryColumnMethod) : "".concat(method, "(").concat(groupbyColumn.name, ")");
|
|
428
|
-
data.results.forEach(function (item) {
|
|
429
|
-
var label = _this2.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
430
|
-
if (!includeEmpty && _this2.isEmptyLabel(label)) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
var value = item[valueKey] || 0;
|
|
434
|
-
var formatted_value = value;
|
|
435
|
-
if (isAdvanced) {
|
|
436
|
-
value = formatNumericValue(value, selectedSummaryColumn);
|
|
437
|
-
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, summaryMethod);
|
|
438
|
-
}
|
|
439
|
-
var color;
|
|
440
|
-
if (columnGroupbyColumn.type === CellType.SINGLE_SELECT) {
|
|
441
|
-
var tempValue = StatUtils.getGroupLabel(item[columnGroupbyColumn.key], item, columnGroupbyColumn, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, _this2.value);
|
|
442
|
-
color = getColorFromSingleSelectColumn(columnGroupbyColumn, tempValue);
|
|
443
|
-
}
|
|
444
|
-
var groupLabel = _this2.getLabel(columnGroupbyColumn, columnGroupbyColumnName, item, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity);
|
|
445
|
-
newResult.push({
|
|
446
|
-
value: value,
|
|
447
|
-
formatted_value: formatted_value,
|
|
448
|
-
color: color,
|
|
449
|
-
name: label,
|
|
450
|
-
group_name: groupLabel,
|
|
451
|
-
group_original_name: item[columnGroupbyColumn.key],
|
|
452
|
-
original_name: item[groupbyColumn.key],
|
|
453
|
-
y_axis_type: yAxisType
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
return _context5.abrupt("return", newResult);
|
|
457
|
-
case 25:
|
|
458
|
-
case "end":
|
|
459
|
-
return _context5.stop();
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}, _callee5, this);
|
|
463
|
-
}));
|
|
464
|
-
function getGroupbyOneColumnResults(_x16, _x17, _x18, _x19, _x20, _x21, _x22, _x23, _x24, _x25, _x26, _x27, _x28, _x29) {
|
|
465
|
-
return _getGroupbyOneColumnResults.apply(this, arguments);
|
|
215
|
+
newResult.push({
|
|
216
|
+
name: label,
|
|
217
|
+
value,
|
|
218
|
+
formatted_value,
|
|
219
|
+
original_name: item[groupbyColumn.key],
|
|
220
|
+
y_axis_type: yAxisType
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
return newResult;
|
|
224
|
+
}
|
|
225
|
+
async getGroupbyOneColumnResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumnKey, summaryMethod, columnGroupbyColumnKey, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, sqlCondition, table, yAxisType) {
|
|
226
|
+
const isAdvanced = summaryType === SUMMARY_TYPE.ADVANCED;
|
|
227
|
+
let selectedSummaryColumn;
|
|
228
|
+
let summaryColumnName = "`".concat(groupbyColumn.name, "`");
|
|
229
|
+
if (isAdvanced) {
|
|
230
|
+
selectedSummaryColumn = TableUtils.getTableColumnByKey(table, summaryColumnKey);
|
|
231
|
+
if (!selectedSummaryColumn) return [];
|
|
232
|
+
summaryColumnName = selectedSummaryColumn.name;
|
|
233
|
+
}
|
|
234
|
+
const columnGroupbyColumn = TableUtils.getTableColumnByKey(table, columnGroupbyColumnKey);
|
|
235
|
+
let columnGroupbyColumnName = "`".concat(columnGroupbyColumn.name, "`");
|
|
236
|
+
if (TIME_COLUMN_LIST.includes(columnGroupbyColumn.type)) {
|
|
237
|
+
columnGroupbyColumnName = getSqlGroup(columnGroupbyDateGranularity, columnGroupbyColumn);
|
|
238
|
+
} else if (columnGroupbyColumn.type === CellType.GEOLOCATION) {
|
|
239
|
+
columnGroupbyColumnName = getSqlGroup(columnGroupbyGeolocationGranularity, columnGroupbyColumn);
|
|
240
|
+
}
|
|
241
|
+
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
242
|
+
const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
243
|
+
const sqlString = "select ".concat(groupbyName, ", ").concat(columnGroupbyColumnName, ", ").concat(summaryColumnMethod, " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, ", ").concat(columnGroupbyColumnName, " order by ").concat(groupbyName, " limit 5000");
|
|
244
|
+
const queryResult = await this.sqlQuery(sqlString);
|
|
245
|
+
if (queryResult.status !== 200 || !queryResult.data.success) {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
const data = queryResult.data;
|
|
249
|
+
if (!data.results) return [];
|
|
250
|
+
const newResult = [];
|
|
251
|
+
const valueKey = isAdvanced ? "".concat(summaryColumnMethod) : "".concat(method, "(").concat(groupbyColumn.name, ")");
|
|
252
|
+
data.results.forEach(item => {
|
|
253
|
+
const label = this.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
254
|
+
if (!includeEmpty && this.isEmptyLabel(label)) {
|
|
255
|
+
return;
|
|
466
256
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
var _getGroupbyMultipleNumericColumnsResults = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumn, summaryMethod, columnGroupbyNumericColumns, sqlCondition, table, yAxisType) {
|
|
473
|
-
var _this3 = this;
|
|
474
|
-
var isAdvanced, numericColumns, groupColumnNames, groupMethods, originalMethods, summaryColumnName, method, summaryColumnMethod, sqlString, result, data, newResult;
|
|
475
|
-
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
476
|
-
while (1) {
|
|
477
|
-
switch (_context6.prev = _context6.next) {
|
|
478
|
-
case 0:
|
|
479
|
-
isAdvanced = summaryType === SUMMARY_TYPE.ADVANCED;
|
|
480
|
-
numericColumns = [];
|
|
481
|
-
groupColumnNames = [];
|
|
482
|
-
groupMethods = [];
|
|
483
|
-
originalMethods = [];
|
|
484
|
-
if (summaryColumn) {
|
|
485
|
-
summaryColumnName = isAdvanced ? summaryColumn.name : "`".concat(groupbyColumn.name, "`");
|
|
486
|
-
method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
487
|
-
summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
488
|
-
numericColumns.push(summaryColumn);
|
|
489
|
-
groupColumnNames.push(summaryColumnName);
|
|
490
|
-
groupMethods.push(summaryColumnMethod);
|
|
491
|
-
originalMethods.push(summaryMethod);
|
|
492
|
-
}
|
|
493
|
-
columnGroupbyNumericColumns.forEach(function (item) {
|
|
494
|
-
var numericColumn = TableUtils.getTableColumnByKey(table, item.column_key);
|
|
495
|
-
var groupColumnName = numericColumn.name;
|
|
496
|
-
numericColumns.push(numericColumn);
|
|
497
|
-
groupColumnNames.push(groupColumnName);
|
|
498
|
-
groupMethods.push(getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[item.summary_method], groupColumnName));
|
|
499
|
-
originalMethods.push(item.summary_method);
|
|
500
|
-
});
|
|
501
|
-
sqlString = "select ".concat(groupbyName, ", ").concat(groupMethods.join(','), " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " order by ").concat(groupbyName, " limit 5000");
|
|
502
|
-
_context6.next = 10;
|
|
503
|
-
return this.sqlQuery(sqlString);
|
|
504
|
-
case 10:
|
|
505
|
-
result = _context6.sent;
|
|
506
|
-
if (!(result.status !== 200 || !result.data.success)) {
|
|
507
|
-
_context6.next = 13;
|
|
508
|
-
break;
|
|
509
|
-
}
|
|
510
|
-
return _context6.abrupt("return", []);
|
|
511
|
-
case 13:
|
|
512
|
-
data = result.data;
|
|
513
|
-
if (data.results) {
|
|
514
|
-
_context6.next = 16;
|
|
515
|
-
break;
|
|
516
|
-
}
|
|
517
|
-
return _context6.abrupt("return", []);
|
|
518
|
-
case 16:
|
|
519
|
-
newResult = [];
|
|
520
|
-
data.results.forEach(function (item) {
|
|
521
|
-
var label = _this3.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
522
|
-
var isEmpty = _this3.isEmptyLabel(label);
|
|
523
|
-
var groupItems = [];
|
|
524
|
-
groupMethods.forEach(function (_, index) {
|
|
525
|
-
if (!includeEmpty && isEmpty) {
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
var value = item[groupMethods[index]] || 0;
|
|
529
|
-
var formatted_value = value;
|
|
530
|
-
if (isAdvanced) {
|
|
531
|
-
value = formatNumericValue(value, numericColumns[index]);
|
|
532
|
-
formatted_value = StatUtils.getFormattedValue(value, numericColumns[index], originalMethods[index]);
|
|
533
|
-
}
|
|
534
|
-
groupItems.push({
|
|
535
|
-
name: label,
|
|
536
|
-
value: value,
|
|
537
|
-
formatted_value: formatted_value,
|
|
538
|
-
group_name: groupColumnNames[index],
|
|
539
|
-
original_name: item[groupbyColumn.key],
|
|
540
|
-
y_axis_type: yAxisType
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
newResult = newResult.concat(groupItems);
|
|
544
|
-
});
|
|
545
|
-
return _context6.abrupt("return", newResult);
|
|
546
|
-
case 19:
|
|
547
|
-
case "end":
|
|
548
|
-
return _context6.stop();
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}, _callee6, this);
|
|
552
|
-
}));
|
|
553
|
-
function getGroupbyMultipleNumericColumnsResults(_x30, _x31, _x32, _x33, _x34, _x35, _x36, _x37, _x38, _x39, _x40, _x41) {
|
|
554
|
-
return _getGroupbyMultipleNumericColumnsResults.apply(this, arguments);
|
|
257
|
+
let value = item[valueKey] || 0;
|
|
258
|
+
let formatted_value = value;
|
|
259
|
+
if (isAdvanced) {
|
|
260
|
+
value = formatNumericValue(value, selectedSummaryColumn);
|
|
261
|
+
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, summaryMethod);
|
|
555
262
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
value: function getLabel(groupColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity) {
|
|
561
|
-
var isTimeColumn = TIME_COLUMN_LIST.includes(groupColumn.type);
|
|
562
|
-
var label;
|
|
563
|
-
if (isTimeColumn || groupColumn.type === CellType.GEOLOCATION) {
|
|
564
|
-
label = item[groupName];
|
|
565
|
-
} else {
|
|
566
|
-
var currentGroupLabel = item[groupColumn.key];
|
|
567
|
-
label = StatUtils.getGroupLabel(currentGroupLabel, item, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
|
|
568
|
-
label = getFormattedLabel(groupColumn, label, this.value.collaborators);
|
|
263
|
+
let color;
|
|
264
|
+
if (columnGroupbyColumn.type === CellType.SINGLE_SELECT) {
|
|
265
|
+
const tempValue = StatUtils.getGroupLabel(item[columnGroupbyColumn.key], item, columnGroupbyColumn, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity, this.value);
|
|
266
|
+
color = getColorFromSingleSelectColumn(columnGroupbyColumn, tempValue);
|
|
569
267
|
}
|
|
570
|
-
|
|
268
|
+
const groupLabel = this.getLabel(columnGroupbyColumn, columnGroupbyColumnName, item, columnGroupbyDateGranularity, columnGroupbyGeolocationGranularity);
|
|
269
|
+
newResult.push({
|
|
270
|
+
value,
|
|
271
|
+
formatted_value,
|
|
272
|
+
color,
|
|
273
|
+
name: label,
|
|
274
|
+
group_name: groupLabel,
|
|
275
|
+
group_original_name: item[columnGroupbyColumn.key],
|
|
276
|
+
original_name: item[groupbyColumn.key],
|
|
277
|
+
y_axis_type: yAxisType
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
return newResult;
|
|
281
|
+
}
|
|
282
|
+
async getGroupbyMultipleNumericColumnsResults(groupbyName, groupbyColumn, groupbyDateGranularity, groupbyGeolocationGranularity, includeEmpty, summaryType, summaryColumn, summaryMethod, columnGroupbyNumericColumns, sqlCondition, table, yAxisType) {
|
|
283
|
+
const isAdvanced = summaryType === SUMMARY_TYPE.ADVANCED;
|
|
284
|
+
let numericColumns = [];
|
|
285
|
+
let groupColumnNames = [];
|
|
286
|
+
let groupMethods = [];
|
|
287
|
+
let originalMethods = [];
|
|
288
|
+
if (summaryColumn) {
|
|
289
|
+
const summaryColumnName = isAdvanced ? summaryColumn.name : "`".concat(groupbyColumn.name, "`");
|
|
290
|
+
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summaryMethod] : 'COUNT';
|
|
291
|
+
const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
292
|
+
numericColumns.push(summaryColumn);
|
|
293
|
+
groupColumnNames.push(summaryColumnName);
|
|
294
|
+
groupMethods.push(summaryColumnMethod);
|
|
295
|
+
originalMethods.push(summaryMethod);
|
|
571
296
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
297
|
+
columnGroupbyNumericColumns.forEach(item => {
|
|
298
|
+
const numericColumn = TableUtils.getTableColumnByKey(table, item.column_key);
|
|
299
|
+
const groupColumnName = numericColumn.name;
|
|
300
|
+
numericColumns.push(numericColumn);
|
|
301
|
+
groupColumnNames.push(groupColumnName);
|
|
302
|
+
groupMethods.push(getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[item.summary_method], groupColumnName));
|
|
303
|
+
originalMethods.push(item.summary_method);
|
|
304
|
+
});
|
|
305
|
+
const sqlString = "select ".concat(groupbyName, ", ").concat(groupMethods.join(','), " from `").concat(table.name, "` ").concat(sqlCondition, " group by ").concat(groupbyName, " order by ").concat(groupbyName, " limit 5000");
|
|
306
|
+
const result = await this.sqlQuery(sqlString);
|
|
307
|
+
if (result.status !== 200 || !result.data.success) {
|
|
308
|
+
return [];
|
|
576
309
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
310
|
+
const data = result.data;
|
|
311
|
+
if (!data.results) return [];
|
|
312
|
+
let newResult = [];
|
|
313
|
+
data.results.forEach(item => {
|
|
314
|
+
const label = this.getLabel(groupbyColumn, groupbyName, item, groupbyDateGranularity, groupbyGeolocationGranularity);
|
|
315
|
+
const isEmpty = this.isEmptyLabel(label);
|
|
316
|
+
const groupItems = [];
|
|
317
|
+
groupMethods.forEach((_, index) => {
|
|
318
|
+
if (!includeEmpty && isEmpty) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
let value = item[groupMethods[index]] || 0;
|
|
322
|
+
let formatted_value = value;
|
|
323
|
+
if (isAdvanced) {
|
|
324
|
+
value = formatNumericValue(value, numericColumns[index]);
|
|
325
|
+
formatted_value = StatUtils.getFormattedValue(value, numericColumns[index], originalMethods[index]);
|
|
326
|
+
}
|
|
327
|
+
groupItems.push({
|
|
328
|
+
name: label,
|
|
329
|
+
value,
|
|
330
|
+
formatted_value,
|
|
331
|
+
group_name: groupColumnNames[index],
|
|
332
|
+
original_name: item[groupbyColumn.key],
|
|
333
|
+
y_axis_type: yAxisType
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
newResult = newResult.concat(groupItems);
|
|
337
|
+
});
|
|
338
|
+
return newResult;
|
|
339
|
+
}
|
|
340
|
+
getLabel(groupColumn, groupName, item, groupby_date_granularity, groupby_geolocation_granularity) {
|
|
341
|
+
const isTimeColumn = TIME_COLUMN_LIST.includes(groupColumn.type);
|
|
342
|
+
let label;
|
|
343
|
+
if (isTimeColumn || groupColumn.type === CellType.GEOLOCATION) {
|
|
344
|
+
label = item[groupName];
|
|
345
|
+
} else {
|
|
346
|
+
const currentGroupLabel = item[groupColumn.key];
|
|
347
|
+
label = StatUtils.getGroupLabel(currentGroupLabel, item, groupColumn, groupby_date_granularity, groupby_geolocation_granularity, this.value);
|
|
348
|
+
label = getFormattedLabel(groupColumn, label, this.value.collaborators);
|
|
349
|
+
}
|
|
350
|
+
return label;
|
|
351
|
+
}
|
|
352
|
+
isEmptyLabel(label) {
|
|
353
|
+
return !label;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
580
356
|
export default BasicChartCalculator;
|