dtable-statistic 4.2.1 → 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 _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
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 { filter2SqlCondition, TableUtils } from 'dtable-store';
|
|
11
3
|
import BaseCalculator from './base-calculator';
|
|
@@ -13,286 +5,197 @@ import { getSqlGroup, getSqlOrder } from '../utils/sql-utils';
|
|
|
13
5
|
import StatUtils from '../utils/stat-utils';
|
|
14
6
|
import { getSummaryColumnMethod, getSummaryResult } from '../utils/common-utils';
|
|
15
7
|
import { DTABLE_DB_SUMMARY_METHOD, SUMMARY_TYPE } from '../constants';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
userId: userId
|
|
8
|
+
class CompareBarCalculator 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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
23
|
+
isValidChart(chart) {
|
|
24
|
+
if (!this.validateBaseConfigs(chart)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const {
|
|
28
|
+
table_id,
|
|
29
|
+
x_axis_column_key,
|
|
30
|
+
summary_column_key,
|
|
31
|
+
y_axis_column_key,
|
|
32
|
+
x_axis_date_range_start,
|
|
33
|
+
x_axis_date_range_end,
|
|
34
|
+
x_axis_compared_date_range_start,
|
|
35
|
+
x_axis_compared_date_range_end
|
|
36
|
+
} = chart;
|
|
37
|
+
const table = this.getTableById(table_id);
|
|
38
|
+
if (!TableUtils.getTableColumnByKey(table, x_axis_column_key)) return false;
|
|
39
|
+
const summaryColumnKey = summary_column_key || y_axis_column_key;
|
|
40
|
+
if (summaryColumnKey && !TableUtils.getTableColumnByKey(table, summaryColumnKey)) return false;
|
|
41
|
+
if (!x_axis_date_range_start || !x_axis_date_range_end || !x_axis_compared_date_range_start || !x_axis_compared_date_range_end) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (x_axis_date_range_start > x_axis_date_range_end || x_axis_compared_date_range_start > x_axis_compared_date_range_end) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
async calculate(chart) {
|
|
50
|
+
if (!this.isValidChart(chart)) return [];
|
|
51
|
+
if (this.isCalcByQueryDB(chart)) {
|
|
52
|
+
return await this.queryDb(chart);
|
|
53
|
+
}
|
|
54
|
+
return await this.calculateWithWorker(chart);
|
|
55
|
+
}
|
|
56
|
+
async queryDb(chart) {
|
|
57
|
+
const {
|
|
58
|
+
table_id,
|
|
59
|
+
view_id,
|
|
60
|
+
x_axis_column_key,
|
|
61
|
+
x_axis_date_granularity,
|
|
62
|
+
y_axis_summary_type,
|
|
63
|
+
y_axis_summary_method,
|
|
64
|
+
y_axis_column_key,
|
|
65
|
+
x_axis_date_range_start,
|
|
66
|
+
x_axis_date_range_end,
|
|
67
|
+
x_axis_compared_date_range_start,
|
|
68
|
+
x_axis_compared_date_range_end,
|
|
69
|
+
display_increase
|
|
70
|
+
} = chart;
|
|
71
|
+
const selectedTable = this.getTableById(table_id);
|
|
72
|
+
const selectedView = this.getViewById(view_id, selectedTable);
|
|
73
|
+
const selectedColumn = TableUtils.getTableColumnByKey(selectedTable, x_axis_column_key);
|
|
74
|
+
const isAdvanced = y_axis_summary_type === SUMMARY_TYPE.ADVANCED;
|
|
75
|
+
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[y_axis_summary_method] : DTABLE_DB_SUMMARY_METHOD.Count;
|
|
76
|
+
let sqlString = '';
|
|
77
|
+
let groupName = getSqlGroup('day', selectedColumn);
|
|
78
|
+
const sqlOrder = getSqlOrder(null, groupName);
|
|
79
|
+
let summaryColumnName = "".concat(selectedColumn.name);
|
|
80
|
+
let selectedSummaryColumn = {};
|
|
81
|
+
if (isAdvanced) {
|
|
82
|
+
selectedSummaryColumn = TableUtils.getTableColumnByKey(selectedTable, y_axis_column_key);
|
|
83
|
+
if (!selectedSummaryColumn) return [];
|
|
84
|
+
summaryColumnName = "".concat(selectedSummaryColumn.name);
|
|
57
85
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
case "end":
|
|
87
|
-
return _context.stop();
|
|
86
|
+
const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
87
|
+
let sqlCondition = filter2SqlCondition(selectedTable, selectedView);
|
|
88
|
+
sqlCondition = this.getStatItemSqlCondition(chart, sqlCondition, "`".concat(selectedColumn.name, "`"));
|
|
89
|
+
sqlString = "select ".concat(groupName, ", ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, " ").concat(sqlOrder, " limit 5000");
|
|
90
|
+
const result = await this.sqlQuery(sqlString);
|
|
91
|
+
const groupName1 = "".concat(x_axis_date_range_start, " - ").concat(x_axis_date_range_end);
|
|
92
|
+
const groupName2 = "".concat(x_axis_compared_date_range_start, " - ").concat(x_axis_compared_date_range_end);
|
|
93
|
+
if (result.status === 200 && result.data.success) {
|
|
94
|
+
const dateRangeResult = new Map();
|
|
95
|
+
let dateComparedResult = new Map();
|
|
96
|
+
const valueKey = isAdvanced ? "".concat(method, "(").concat(summaryColumnName, ")") : "".concat(method, "(").concat(selectedColumn.name, ")");
|
|
97
|
+
result.data.results.forEach(item => {
|
|
98
|
+
const name = item[groupName];
|
|
99
|
+
const label = StatUtils.getGroupLabel(name, item, selectedColumn, x_axis_date_granularity, '', this.value);
|
|
100
|
+
const value = item[valueKey];
|
|
101
|
+
if (name >= x_axis_date_range_start && name <= x_axis_date_range_end) {
|
|
102
|
+
const currentValue = dateRangeResult.get(label);
|
|
103
|
+
if (!currentValue) {
|
|
104
|
+
if (isAdvanced) {
|
|
105
|
+
dateRangeResult.set(label, [value]);
|
|
106
|
+
} else {
|
|
107
|
+
dateRangeResult.set(label, value);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
if (isAdvanced) {
|
|
111
|
+
currentValue.push(value);
|
|
112
|
+
} else {
|
|
113
|
+
dateRangeResult.set(label, value + currentValue);
|
|
88
114
|
}
|
|
89
115
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}, {
|
|
98
|
-
key: "queryDb",
|
|
99
|
-
value: function () {
|
|
100
|
-
var _queryDb = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chart) {
|
|
101
|
-
var _this = this;
|
|
102
|
-
var table_id, view_id, x_axis_column_key, x_axis_date_granularity, y_axis_summary_type, y_axis_summary_method, y_axis_column_key, x_axis_date_range_start, x_axis_date_range_end, x_axis_compared_date_range_start, x_axis_compared_date_range_end, display_increase, selectedTable, selectedView, selectedColumn, isAdvanced, method, sqlString, groupName, sqlOrder, summaryColumnName, selectedSummaryColumn, summaryColumnMethod, sqlCondition, result, groupName1, groupName2, dateRangeResult, dateComparedResult, valueKey, comparedResult, rangeResult, data, _iterator, _step, item, value, formatted_value, index, _iterator2, _step2, _item, dateRangeItem, _value, _formatted_value, newItem, value1, increaseValue;
|
|
103
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
104
|
-
while (1) {
|
|
105
|
-
switch (_context2.prev = _context2.next) {
|
|
106
|
-
case 0:
|
|
107
|
-
table_id = chart.table_id, view_id = chart.view_id, x_axis_column_key = chart.x_axis_column_key, x_axis_date_granularity = chart.x_axis_date_granularity, y_axis_summary_type = chart.y_axis_summary_type, y_axis_summary_method = chart.y_axis_summary_method, y_axis_column_key = chart.y_axis_column_key, x_axis_date_range_start = chart.x_axis_date_range_start, x_axis_date_range_end = chart.x_axis_date_range_end, x_axis_compared_date_range_start = chart.x_axis_compared_date_range_start, x_axis_compared_date_range_end = chart.x_axis_compared_date_range_end, display_increase = chart.display_increase;
|
|
108
|
-
selectedTable = this.getTableById(table_id);
|
|
109
|
-
selectedView = this.getViewById(view_id, selectedTable);
|
|
110
|
-
selectedColumn = TableUtils.getTableColumnByKey(selectedTable, x_axis_column_key);
|
|
111
|
-
isAdvanced = y_axis_summary_type === SUMMARY_TYPE.ADVANCED;
|
|
112
|
-
method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[y_axis_summary_method] : DTABLE_DB_SUMMARY_METHOD.Count;
|
|
113
|
-
sqlString = '';
|
|
114
|
-
groupName = getSqlGroup('day', selectedColumn);
|
|
115
|
-
sqlOrder = getSqlOrder(null, groupName);
|
|
116
|
-
summaryColumnName = "".concat(selectedColumn.name);
|
|
117
|
-
selectedSummaryColumn = {};
|
|
118
|
-
if (!isAdvanced) {
|
|
119
|
-
_context2.next = 16;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
selectedSummaryColumn = TableUtils.getTableColumnByKey(selectedTable, y_axis_column_key);
|
|
123
|
-
if (selectedSummaryColumn) {
|
|
124
|
-
_context2.next = 15;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
return _context2.abrupt("return", []);
|
|
128
|
-
case 15:
|
|
129
|
-
summaryColumnName = "".concat(selectedSummaryColumn.name);
|
|
130
|
-
case 16:
|
|
131
|
-
summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
|
|
132
|
-
sqlCondition = filter2SqlCondition(selectedTable, selectedView);
|
|
133
|
-
sqlCondition = this.getStatItemSqlCondition(chart, sqlCondition, "`".concat(selectedColumn.name, "`"));
|
|
134
|
-
sqlString = "select ".concat(groupName, ", ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, " ").concat(sqlOrder, " limit 5000");
|
|
135
|
-
_context2.next = 22;
|
|
136
|
-
return this.sqlQuery(sqlString);
|
|
137
|
-
case 22:
|
|
138
|
-
result = _context2.sent;
|
|
139
|
-
groupName1 = "".concat(x_axis_date_range_start, " - ").concat(x_axis_date_range_end);
|
|
140
|
-
groupName2 = "".concat(x_axis_compared_date_range_start, " - ").concat(x_axis_compared_date_range_end);
|
|
141
|
-
if (!(result.status === 200 && result.data.success)) {
|
|
142
|
-
_context2.next = 63;
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
dateRangeResult = new Map();
|
|
146
|
-
dateComparedResult = new Map();
|
|
147
|
-
valueKey = isAdvanced ? "".concat(method, "(").concat(summaryColumnName, ")") : "".concat(method, "(").concat(selectedColumn.name, ")");
|
|
148
|
-
result.data.results.forEach(function (item) {
|
|
149
|
-
var name = item[groupName];
|
|
150
|
-
var label = StatUtils.getGroupLabel(name, item, selectedColumn, x_axis_date_granularity, '', _this.value);
|
|
151
|
-
var value = item[valueKey];
|
|
152
|
-
if (name >= x_axis_date_range_start && name <= x_axis_date_range_end) {
|
|
153
|
-
var currentValue = dateRangeResult.get(label);
|
|
154
|
-
if (!currentValue) {
|
|
155
|
-
if (isAdvanced) {
|
|
156
|
-
dateRangeResult.set(label, [value]);
|
|
157
|
-
} else {
|
|
158
|
-
dateRangeResult.set(label, value);
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
if (isAdvanced) {
|
|
162
|
-
currentValue.push(value);
|
|
163
|
-
} else {
|
|
164
|
-
dateRangeResult.set(label, value + currentValue);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
} else if (name >= x_axis_compared_date_range_start && name <= x_axis_compared_date_range_end) {
|
|
168
|
-
var _currentValue = dateComparedResult.get(label);
|
|
169
|
-
if (!_currentValue) {
|
|
170
|
-
if (isAdvanced) {
|
|
171
|
-
dateComparedResult.set(label, [value]);
|
|
172
|
-
} else {
|
|
173
|
-
dateComparedResult.set(label, value);
|
|
174
|
-
}
|
|
175
|
-
} else {
|
|
176
|
-
if (isAdvanced) {
|
|
177
|
-
dateComparedResult.push(value);
|
|
178
|
-
} else {
|
|
179
|
-
dateComparedResult.set(label, value + _currentValue);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
comparedResult = [];
|
|
185
|
-
rangeResult = [];
|
|
186
|
-
data = selectedSummaryColumn.data || {};
|
|
187
|
-
_iterator = _createForOfIteratorHelper(dateRangeResult);
|
|
188
|
-
try {
|
|
189
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
190
|
-
item = _step.value;
|
|
191
|
-
value = item[1];
|
|
192
|
-
formatted_value = value;
|
|
193
|
-
if (isAdvanced) {
|
|
194
|
-
value = getSummaryResult(item[1], y_axis_summary_method, data.precision);
|
|
195
|
-
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, y_axis_summary_method);
|
|
196
|
-
}
|
|
197
|
-
rangeResult.push({
|
|
198
|
-
name: item[0],
|
|
199
|
-
group_name: groupName1,
|
|
200
|
-
raw_name: item[0],
|
|
201
|
-
value: value,
|
|
202
|
-
formatted_value: formatted_value
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
} catch (err) {
|
|
206
|
-
_iterator.e(err);
|
|
207
|
-
} finally {
|
|
208
|
-
_iterator.f();
|
|
209
|
-
}
|
|
210
|
-
index = 0;
|
|
211
|
-
_iterator2 = _createForOfIteratorHelper(dateComparedResult);
|
|
212
|
-
_context2.prev = 37;
|
|
213
|
-
_iterator2.s();
|
|
214
|
-
case 39:
|
|
215
|
-
if ((_step2 = _iterator2.n()).done) {
|
|
216
|
-
_context2.next = 53;
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
_item = _step2.value;
|
|
220
|
-
dateRangeItem = rangeResult[index];
|
|
221
|
-
if (dateRangeItem) {
|
|
222
|
-
_context2.next = 44;
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
return _context2.abrupt("break", 53);
|
|
226
|
-
case 44:
|
|
227
|
-
_value = _item[1];
|
|
228
|
-
_formatted_value = _value;
|
|
229
|
-
if (isAdvanced) {
|
|
230
|
-
_value = getSummaryResult(_item[1], y_axis_summary_method, data.precision);
|
|
231
|
-
_formatted_value = StatUtils.getFormattedValue(_value, selectedSummaryColumn, y_axis_summary_method);
|
|
232
|
-
}
|
|
233
|
-
newItem = {
|
|
234
|
-
name: dateRangeItem.name,
|
|
235
|
-
group_name: groupName2,
|
|
236
|
-
raw_name: _item[0],
|
|
237
|
-
value: _value,
|
|
238
|
-
formatted_value: _formatted_value
|
|
239
|
-
};
|
|
240
|
-
if (display_increase) {
|
|
241
|
-
value1 = dateRangeItem.value;
|
|
242
|
-
increaseValue = Number(((value1 - _value) / _value).toFixed(2));
|
|
243
|
-
if (!_value) {
|
|
244
|
-
increaseValue = 1;
|
|
245
|
-
}
|
|
246
|
-
newItem.increase_value = increaseValue;
|
|
247
|
-
}
|
|
248
|
-
comparedResult.push(newItem);
|
|
249
|
-
index++;
|
|
250
|
-
case 51:
|
|
251
|
-
_context2.next = 39;
|
|
252
|
-
break;
|
|
253
|
-
case 53:
|
|
254
|
-
_context2.next = 58;
|
|
255
|
-
break;
|
|
256
|
-
case 55:
|
|
257
|
-
_context2.prev = 55;
|
|
258
|
-
_context2.t0 = _context2["catch"](37);
|
|
259
|
-
_iterator2.e(_context2.t0);
|
|
260
|
-
case 58:
|
|
261
|
-
_context2.prev = 58;
|
|
262
|
-
_iterator2.f();
|
|
263
|
-
return _context2.finish(58);
|
|
264
|
-
case 61:
|
|
265
|
-
if (comparedResult.length > rangeResult.length) {
|
|
266
|
-
comparedResult = comparedResult.slice(0, rangeResult.length);
|
|
267
|
-
}
|
|
268
|
-
return _context2.abrupt("return", [].concat(_toConsumableArray(comparedResult), rangeResult));
|
|
269
|
-
case 63:
|
|
270
|
-
return _context2.abrupt("return", []);
|
|
271
|
-
case 64:
|
|
272
|
-
case "end":
|
|
273
|
-
return _context2.stop();
|
|
116
|
+
} else if (name >= x_axis_compared_date_range_start && name <= x_axis_compared_date_range_end) {
|
|
117
|
+
const currentValue = dateComparedResult.get(label);
|
|
118
|
+
if (!currentValue) {
|
|
119
|
+
if (isAdvanced) {
|
|
120
|
+
dateComparedResult.set(label, [value]);
|
|
121
|
+
} else {
|
|
122
|
+
dateComparedResult.set(label, value);
|
|
274
123
|
}
|
|
124
|
+
} else {
|
|
125
|
+
if (isAdvanced) {
|
|
126
|
+
dateComparedResult.push(value);
|
|
127
|
+
} else {
|
|
128
|
+
dateComparedResult.set(label, value + currentValue);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
let comparedResult = [];
|
|
134
|
+
let rangeResult = [];
|
|
135
|
+
const data = selectedSummaryColumn.data || {};
|
|
136
|
+
for (let item of dateRangeResult) {
|
|
137
|
+
let value = item[1];
|
|
138
|
+
let formatted_value = value;
|
|
139
|
+
if (isAdvanced) {
|
|
140
|
+
value = getSummaryResult(item[1], y_axis_summary_method, data.precision);
|
|
141
|
+
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, y_axis_summary_method);
|
|
142
|
+
}
|
|
143
|
+
rangeResult.push({
|
|
144
|
+
name: item[0],
|
|
145
|
+
group_name: groupName1,
|
|
146
|
+
raw_name: item[0],
|
|
147
|
+
value,
|
|
148
|
+
formatted_value
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
let index = 0;
|
|
152
|
+
for (let item of dateComparedResult) {
|
|
153
|
+
let dateRangeItem = rangeResult[index];
|
|
154
|
+
if (!dateRangeItem) {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
let value = item[1];
|
|
158
|
+
let formatted_value = value;
|
|
159
|
+
if (isAdvanced) {
|
|
160
|
+
value = getSummaryResult(item[1], y_axis_summary_method, data.precision);
|
|
161
|
+
formatted_value = StatUtils.getFormattedValue(value, selectedSummaryColumn, y_axis_summary_method);
|
|
162
|
+
}
|
|
163
|
+
const newItem = {
|
|
164
|
+
name: dateRangeItem.name,
|
|
165
|
+
group_name: groupName2,
|
|
166
|
+
raw_name: item[0],
|
|
167
|
+
value,
|
|
168
|
+
formatted_value
|
|
169
|
+
};
|
|
170
|
+
if (display_increase) {
|
|
171
|
+
const value1 = dateRangeItem.value;
|
|
172
|
+
let increaseValue = Number(((value1 - value) / value).toFixed(2));
|
|
173
|
+
if (!value) {
|
|
174
|
+
increaseValue = 1;
|
|
275
175
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
176
|
+
newItem.increase_value = increaseValue;
|
|
177
|
+
}
|
|
178
|
+
comparedResult.push(newItem);
|
|
179
|
+
index++;
|
|
180
|
+
}
|
|
181
|
+
if (comparedResult.length > rangeResult.length) {
|
|
182
|
+
comparedResult = comparedResult.slice(0, rangeResult.length);
|
|
280
183
|
}
|
|
281
|
-
return
|
|
282
|
-
}()
|
|
283
|
-
}, {
|
|
284
|
-
key: "getStatItemSqlCondition",
|
|
285
|
-
value: function getStatItemSqlCondition(chart, sqlCondition, name) {
|
|
286
|
-
var x_axis_date_range_start = chart.x_axis_date_range_start,
|
|
287
|
-
x_axis_date_range_end = chart.x_axis_date_range_end,
|
|
288
|
-
x_axis_compared_date_range_start = chart.x_axis_compared_date_range_start,
|
|
289
|
-
x_axis_compared_date_range_end = chart.x_axis_compared_date_range_end;
|
|
290
|
-
var newSqlCondition = sqlCondition.length === 0 ? 'where ' : sqlCondition + ' AND';
|
|
291
|
-
var formattedXAxisDateRangeEnd = dayjs(x_axis_date_range_end).add(1, 'days').format('YYYY-MM-DD');
|
|
292
|
-
var formattedXAxisComparedDateRangeEnd = dayjs(x_axis_compared_date_range_end).add(1, 'days').format('YYYY-MM-DD');
|
|
293
|
-
return newSqlCondition + " ((".concat(name, " >= '").concat(x_axis_date_range_start, "' AND ").concat(name, " < '").concat(formattedXAxisDateRangeEnd, "') Or (").concat(name, " >= '").concat(x_axis_compared_date_range_start, "' AND ").concat(name, " < '").concat(formattedXAxisComparedDateRangeEnd, "'))");
|
|
184
|
+
return [...comparedResult, ...rangeResult];
|
|
294
185
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
getStatItemSqlCondition(chart, sqlCondition, name) {
|
|
189
|
+
const {
|
|
190
|
+
x_axis_date_range_start,
|
|
191
|
+
x_axis_date_range_end,
|
|
192
|
+
x_axis_compared_date_range_start,
|
|
193
|
+
x_axis_compared_date_range_end
|
|
194
|
+
} = chart;
|
|
195
|
+
const newSqlCondition = sqlCondition.length === 0 ? 'where ' : sqlCondition + ' AND';
|
|
196
|
+
const formattedXAxisDateRangeEnd = dayjs(x_axis_date_range_end).add(1, 'days').format('YYYY-MM-DD');
|
|
197
|
+
const formattedXAxisComparedDateRangeEnd = dayjs(x_axis_compared_date_range_end).add(1, 'days').format('YYYY-MM-DD');
|
|
198
|
+
return newSqlCondition + " ((".concat(name, " >= '").concat(x_axis_date_range_start, "' AND ").concat(name, " < '").concat(formattedXAxisDateRangeEnd, "') Or (").concat(name, " >= '").concat(x_axis_compared_date_range_start, "' AND ").concat(name, " < '").concat(formattedXAxisComparedDateRangeEnd, "'))");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
298
201
|
export default CompareBarCalculator;
|