dtable-statistic 4.4.23 → 4.4.24-alpha.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.
Files changed (196) hide show
  1. package/es/assets/css/dashboard.css +1 -0
  2. package/es/assets/css/dialog.css +30 -0
  3. package/es/components/dialog/chart-edit-dialog.js +92 -0
  4. package/es/components/dialog/enlarged-chart-dialog.js +8 -13
  5. package/es/components/dialog/statistic-record-dialog/index.js +22 -30
  6. package/es/components/dropdown-menu/statistic-dropdown-menu.js +2 -2
  7. package/es/components/index.js +1 -15
  8. package/es/constants/index.js +1 -2
  9. package/es/dashboard.js +5 -31
  10. package/es/desktop-dashboard.js +51 -32
  11. package/es/mobile-dashboard.js +8 -16
  12. package/es/model/conver-statItem.js +124 -0
  13. package/es/service/chart-service.js +8 -15
  14. package/es/service/dashboard-service.js +25 -29
  15. package/es/stat-list/chart-preview.js +19 -20
  16. package/es/stat-list/index.js +13 -19
  17. package/es/stat-view/index.js +46 -156
  18. package/es/utils/common-utils.js +2 -352
  19. package/es/utils/export-table-utils.js +0 -69
  20. package/es/utils/index.js +0 -89
  21. package/package.json +5 -7
  22. package/es/assets/css/color-picker.css +0 -53
  23. package/es/assets/css/color-rules-popover.css +0 -144
  24. package/es/assets/css/slider.css +0 -77
  25. package/es/assets/css/statistic-chart.module.css +0 -11
  26. package/es/assets/css/statistic-custom-title.module.css +0 -3
  27. package/es/assets/css/statistic-custom.module.css +0 -4
  28. package/es/assets/css/statistic-numeric-column-item.module.css +0 -43
  29. package/es/assets/css/statistic-time-picker.module.css +0 -21
  30. package/es/calculator/base-calculator.js +0 -80
  31. package/es/calculator/basic-chart-calculator.js +0 -349
  32. package/es/calculator/combination-calculator.js +0 -246
  33. package/es/calculator/compare-bar-calculator.js +0 -197
  34. package/es/calculator/completeness-calculator.js +0 -215
  35. package/es/calculator/copy-value.js +0 -53
  36. package/es/calculator/dashboard-calculator.js +0 -70
  37. package/es/calculator/heat-map-calculator.js +0 -148
  38. package/es/calculator/horizontal-bar-calculator.js +0 -67
  39. package/es/calculator/index.js +0 -81
  40. package/es/calculator/map-calculator.js +0 -103
  41. package/es/calculator/mirror-calculator.js +0 -146
  42. package/es/calculator/number-card-calculator.js +0 -60
  43. package/es/calculator/pivot-table-calculator.js +0 -821
  44. package/es/calculator/scatter-calculator.js +0 -75
  45. package/es/calculator/thread-manager.js +0 -57
  46. package/es/calculator/trend-calculator.js +0 -113
  47. package/es/calculator/workers/basic-chart-calculator-worker.js +0 -495
  48. package/es/calculator/workers/calculator.worker.js +0 -44
  49. package/es/calculator/workers/card-calculator-worker.js +0 -40
  50. package/es/calculator/workers/combination-calculator-worker.js +0 -276
  51. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +0 -150
  52. package/es/calculator/workers/completeness-calculator-worker.js +0 -208
  53. package/es/calculator/workers/dashboard-calculator-worker.js +0 -68
  54. package/es/calculator/workers/mirror-calculator-worker.js +0 -152
  55. package/es/calculator/workers/pivot-table-calculator-worker.js +0 -718
  56. package/es/calculator/workers/scatter-calculator-worker.js +0 -80
  57. package/es/calculator/workers/trend-calculator-worker.js +0 -108
  58. package/es/calculator/world-map-calculator.js +0 -124
  59. package/es/components/common-add-tool.js +0 -28
  60. package/es/components/dialog/chart-addition-edit-dialog.js +0 -90
  61. package/es/components/dialog/chart-addition-widgets/chart-selector.js +0 -259
  62. package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +0 -83
  63. package/es/components/dialog/statistic-types-dialog/index.css +0 -14
  64. package/es/components/dialog/statistic-types-dialog/index.js +0 -62
  65. package/es/components/popover/color-rules/color-rule.js +0 -183
  66. package/es/components/popover/color-rules/index.js +0 -87
  67. package/es/components/popover/color-rules/rule-filters/filter.js +0 -221
  68. package/es/components/popover/color-rules/rule-filters/index.css +0 -210
  69. package/es/components/popover/color-rules/rule-filters/index.js +0 -97
  70. package/es/components/popover/color-rules/rule-filters/number-input.js +0 -78
  71. package/es/components/popover/color-rules-popover.js +0 -217
  72. package/es/components/popover/color-selector-popover.js +0 -82
  73. package/es/components/seatable-radio/index.css +0 -51
  74. package/es/components/seatable-radio/index.js +0 -35
  75. package/es/custom-g2.js +0 -644
  76. package/es/model/bar-group.js +0 -58
  77. package/es/model/bar.js +0 -47
  78. package/es/model/base-model.js +0 -18
  79. package/es/model/basic-number-card.js +0 -25
  80. package/es/model/combination.js +0 -48
  81. package/es/model/compare-bar.js +0 -56
  82. package/es/model/completeness-group.js +0 -31
  83. package/es/model/completeness.js +0 -25
  84. package/es/model/custom-bar.js +0 -25
  85. package/es/model/dashboard.js +0 -20
  86. package/es/model/generic-model.js +0 -222
  87. package/es/model/heat-map.js +0 -33
  88. package/es/model/horizontal-bar-group.js +0 -55
  89. package/es/model/horizontal-bar.js +0 -47
  90. package/es/model/index.js +0 -187
  91. package/es/model/map.js +0 -38
  92. package/es/model/mirror.js +0 -33
  93. package/es/model/pie.js +0 -38
  94. package/es/model/ring.js +0 -40
  95. package/es/model/scatter.js +0 -22
  96. package/es/model/table.js +0 -32
  97. package/es/model/trend.js +0 -32
  98. package/es/model/world-map.js +0 -34
  99. package/es/stat-editor/chart-name-editor.js +0 -68
  100. package/es/stat-editor/index.js +0 -75
  101. package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +0 -153
  102. package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +0 -422
  103. package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +0 -203
  104. package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +0 -23
  105. package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +0 -104
  106. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +0 -334
  107. package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +0 -119
  108. package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +0 -132
  109. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +0 -240
  110. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +0 -89
  111. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +0 -138
  112. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +0 -331
  113. package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +0 -143
  114. package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +0 -109
  115. package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +0 -153
  116. package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +0 -144
  117. package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +0 -214
  118. package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +0 -121
  119. package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +0 -172
  120. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +0 -366
  121. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +0 -142
  122. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +0 -150
  123. package/es/stat-editor/stat-settings/basic-chart-settings/index.js +0 -473
  124. package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +0 -182
  125. package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +0 -564
  126. package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +0 -112
  127. package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +0 -87
  128. package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +0 -187
  129. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +0 -300
  130. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +0 -113
  131. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +0 -289
  132. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +0 -58
  133. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +0 -359
  134. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +0 -48
  135. package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +0 -121
  136. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +0 -143
  137. package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +0 -269
  138. package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +0 -104
  139. package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +0 -366
  140. package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +0 -55
  141. package/es/stat-editor/stat-settings/color-setting/color-picker.js +0 -130
  142. package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +0 -374
  143. package/es/stat-editor/stat-settings/map/map-level.js +0 -72
  144. package/es/stat-editor/stat-settings/map/map-province-city.js +0 -151
  145. package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +0 -108
  146. package/es/stat-editor/stat-settings/public-setting/base-settings.js +0 -154
  147. package/es/stat-editor/stat-settings/public-setting/calender.js +0 -125
  148. package/es/stat-editor/stat-settings/public-setting/column-settings.js +0 -24
  149. package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +0 -62
  150. package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +0 -61
  151. package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +0 -35
  152. package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +0 -60
  153. package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +0 -123
  154. package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +0 -33
  155. package/es/stat-editor/stat-settings/public-setting/type-settings/index.css +0 -29
  156. package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +0 -82
  157. package/es/stat-view/area-chart.js +0 -551
  158. package/es/stat-view/bar-chart.js +0 -582
  159. package/es/stat-view/base-chart.js +0 -132
  160. package/es/stat-view/basic-number-card.js +0 -201
  161. package/es/stat-view/combination-chart.js +0 -546
  162. package/es/stat-view/compare-chart.js +0 -483
  163. package/es/stat-view/completeness-chart.js +0 -390
  164. package/es/stat-view/custom-bar.js +0 -418
  165. package/es/stat-view/dashboard-chart.js +0 -266
  166. package/es/stat-view/heat-map.js +0 -463
  167. package/es/stat-view/horizontal-bar-chart.js +0 -562
  168. package/es/stat-view/line-chart.js +0 -518
  169. package/es/stat-view/map.js +0 -448
  170. package/es/stat-view/mirror.js +0 -275
  171. package/es/stat-view/pie-chart.js +0 -290
  172. package/es/stat-view/pivot-table/index.js +0 -196
  173. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +0 -156
  174. package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +0 -176
  175. package/es/stat-view/pivot-table/pivot-table-display-name.js +0 -215
  176. package/es/stat-view/pivot-table/statistic-pivot-table.module.css +0 -132
  177. package/es/stat-view/pivot-table/two-dimension-table.js +0 -384
  178. package/es/stat-view/ring-chart.js +0 -392
  179. package/es/stat-view/scatter-chart.js +0 -306
  180. package/es/stat-view/treemap-chart.js +0 -253
  181. package/es/stat-view/trend-chart.js +0 -249
  182. package/es/stat-view/world-map.js +0 -431
  183. package/es/utils/basic-chart-utils.js +0 -29
  184. package/es/utils/cell-format.js +0 -115
  185. package/es/utils/collaborator.js +0 -50
  186. package/es/utils/color-utils.js +0 -134
  187. package/es/utils/column-utils.js +0 -110
  188. package/es/utils/column.js +0 -20
  189. package/es/utils/date-format.js +0 -71
  190. package/es/utils/map.js +0 -114
  191. package/es/utils/model.js +0 -19
  192. package/es/utils/row-utils.js +0 -134
  193. package/es/utils/search.js +0 -73
  194. package/es/utils/sql-utils.js +0 -359
  195. package/es/utils/stat-utils.js +0 -351
  196. package/es/utils/trend-utils.js +0 -135
@@ -1,197 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _dayjs = _interopRequireDefault(require("dayjs"));
9
- var _dtableUtils = require("dtable-utils");
10
- var _baseCalculator = _interopRequireDefault(require("./base-calculator"));
11
- var _sqlUtils = require("../utils/sql-utils");
12
- var _statUtils = _interopRequireDefault(require("../utils/stat-utils"));
13
- var _commonUtils = require("../utils/common-utils");
14
- var _constants = require("../constants");
15
- class CompareBarCalculator extends _baseCalculator.default {
16
- isValidChart(chart) {
17
- if (!this.validateBaseConfigs(chart)) {
18
- return false;
19
- }
20
- const {
21
- table_id,
22
- x_axis_column_key,
23
- summary_column_key,
24
- y_axis_column_key,
25
- x_axis_date_range_start,
26
- x_axis_date_range_end,
27
- x_axis_compared_date_range_start,
28
- x_axis_compared_date_range_end
29
- } = chart;
30
- const table = this.getTableById(table_id);
31
- if (!(0, _dtableUtils.getTableColumnByKey)(table, x_axis_column_key)) return false;
32
- const summaryColumnKey = summary_column_key || y_axis_column_key;
33
- if (summaryColumnKey && !(0, _dtableUtils.getTableColumnByKey)(table, summaryColumnKey)) return false;
34
- if (!x_axis_date_range_start || !x_axis_date_range_end || !x_axis_compared_date_range_start || !x_axis_compared_date_range_end) {
35
- return false;
36
- }
37
- if (x_axis_date_range_start > x_axis_date_range_end || x_axis_compared_date_range_start > x_axis_compared_date_range_end) {
38
- return false;
39
- }
40
- return true;
41
- }
42
- async calculate(chart) {
43
- if (!this.isValidChart(chart)) return [];
44
- if (this.isCalcByQueryDB(chart)) {
45
- return await this.queryDb(chart);
46
- }
47
- return await this.calculateWithWorker(chart);
48
- }
49
- async queryDb(chart) {
50
- const {
51
- table_id,
52
- view_id,
53
- x_axis_column_key,
54
- x_axis_date_granularity,
55
- y_axis_summary_type,
56
- y_axis_summary_method,
57
- y_axis_column_key,
58
- x_axis_date_range_start,
59
- x_axis_date_range_end,
60
- x_axis_compared_date_range_start,
61
- x_axis_compared_date_range_end,
62
- display_increase
63
- } = chart;
64
- const selectedTable = this.getTableById(table_id);
65
- const selectedView = this.getViewById(view_id, selectedTable);
66
- const selectedColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, x_axis_column_key);
67
- const isAdvanced = y_axis_summary_type === _constants.SUMMARY_TYPE.ADVANCED;
68
- const method = isAdvanced ? _constants.DTABLE_DB_SUMMARY_METHOD[y_axis_summary_method] : _constants.DTABLE_DB_SUMMARY_METHOD.Count;
69
- let sqlString = '';
70
- let groupName = (0, _sqlUtils.getSqlGroup)('day', selectedColumn);
71
- const sqlOrder = (0, _sqlUtils.getSqlOrder)(null, groupName);
72
- let summaryColumnName = "".concat(selectedColumn.name);
73
- let selectedSummaryColumn = {};
74
- if (isAdvanced) {
75
- selectedSummaryColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, y_axis_column_key);
76
- if (!selectedSummaryColumn) return [];
77
- summaryColumnName = "".concat(selectedSummaryColumn.name);
78
- }
79
- const summaryColumnMethod = (0, _commonUtils.getSummaryColumnMethod)(method, summaryColumnName);
80
- let sqlCondition = this.filter2SqlCondition(selectedTable, selectedView);
81
- sqlCondition = this.getStatItemSqlCondition(chart, sqlCondition, "`".concat(selectedColumn.name, "`"));
82
- sqlString = "select ".concat(groupName, ", ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, " ").concat(sqlOrder, " limit 5000");
83
- const result = await this.sqlQuery(sqlString);
84
- const groupName1 = "".concat(x_axis_date_range_start, " - ").concat(x_axis_date_range_end);
85
- const groupName2 = "".concat(x_axis_compared_date_range_start, " - ").concat(x_axis_compared_date_range_end);
86
- if (result.status === 200 && result.data.success) {
87
- const dateRangeResult = new Map();
88
- let dateComparedResult = new Map();
89
- const valueKey = isAdvanced ? "".concat(method, "(").concat(summaryColumnName, ")") : "".concat(method, "(").concat(selectedColumn.name, ")");
90
- result.data.results.forEach(item => {
91
- const name = item[groupName];
92
- const label = _statUtils.default.getGroupLabel(name, item, selectedColumn, x_axis_date_granularity, '', this.value);
93
- const value = item[valueKey];
94
- if (name >= x_axis_date_range_start && name <= x_axis_date_range_end) {
95
- const currentValue = dateRangeResult.get(label);
96
- if (!currentValue) {
97
- if (isAdvanced) {
98
- dateRangeResult.set(label, [value]);
99
- } else {
100
- dateRangeResult.set(label, value);
101
- }
102
- } else {
103
- if (isAdvanced) {
104
- currentValue.push(value);
105
- } else {
106
- dateRangeResult.set(label, value + currentValue);
107
- }
108
- }
109
- } else if (name >= x_axis_compared_date_range_start && name <= x_axis_compared_date_range_end) {
110
- const currentValue = dateComparedResult.get(label);
111
- if (!currentValue) {
112
- if (isAdvanced) {
113
- dateComparedResult.set(label, [value]);
114
- } else {
115
- dateComparedResult.set(label, value);
116
- }
117
- } else {
118
- if (isAdvanced) {
119
- dateComparedResult.push(value);
120
- } else {
121
- dateComparedResult.set(label, value + currentValue);
122
- }
123
- }
124
- }
125
- });
126
- let comparedResult = [];
127
- let rangeResult = [];
128
- const data = selectedSummaryColumn.data || {};
129
-
130
- // eslint-disable-next-line
131
- for (let item of dateRangeResult) {
132
- let value = item[1];
133
- let formatted_value = value;
134
- if (isAdvanced) {
135
- value = (0, _commonUtils.getSummaryResult)(item[1], y_axis_summary_method, data.precision);
136
- formatted_value = _statUtils.default.getFormattedValue(value, selectedSummaryColumn, y_axis_summary_method);
137
- }
138
- rangeResult.push({
139
- name: item[0],
140
- group_name: groupName1,
141
- raw_name: item[0],
142
- value,
143
- formatted_value
144
- });
145
- }
146
- let index = 0;
147
- // eslint-disable-next-line
148
- for (let item of dateComparedResult) {
149
- let dateRangeItem = rangeResult[index];
150
- if (!dateRangeItem) {
151
- break;
152
- }
153
- let value = item[1];
154
- let formatted_value = value;
155
- if (isAdvanced) {
156
- value = (0, _commonUtils.getSummaryResult)(item[1], y_axis_summary_method, data.precision);
157
- formatted_value = _statUtils.default.getFormattedValue(value, selectedSummaryColumn, y_axis_summary_method);
158
- }
159
- const newItem = {
160
- name: dateRangeItem.name,
161
- group_name: groupName2,
162
- raw_name: item[0],
163
- value,
164
- formatted_value
165
- };
166
- if (display_increase) {
167
- const value1 = dateRangeItem.value;
168
- let increaseValue = Number(((value1 - value) / value).toFixed(2));
169
- if (!value) {
170
- increaseValue = 1;
171
- }
172
- newItem.increase_value = increaseValue;
173
- }
174
- comparedResult.push(newItem);
175
- index++;
176
- }
177
- if (comparedResult.length > rangeResult.length) {
178
- comparedResult = comparedResult.slice(0, rangeResult.length);
179
- }
180
- return [...comparedResult, ...rangeResult];
181
- }
182
- return [];
183
- }
184
- getStatItemSqlCondition(chart, sqlCondition, name) {
185
- const {
186
- x_axis_date_range_start,
187
- x_axis_date_range_end,
188
- x_axis_compared_date_range_start,
189
- x_axis_compared_date_range_end
190
- } = chart;
191
- const newSqlCondition = sqlCondition.length === 0 ? 'where ' : sqlCondition + ' AND';
192
- const formattedXAxisDateRangeEnd = (0, _dayjs.default)(x_axis_date_range_end).add(1, 'days').format('YYYY-MM-DD');
193
- const formattedXAxisComparedDateRangeEnd = (0, _dayjs.default)(x_axis_compared_date_range_end).add(1, 'days').format('YYYY-MM-DD');
194
- 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, "'))");
195
- }
196
- }
197
- var _default = exports.default = CompareBarCalculator;
@@ -1,215 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _dtableUtils = require("dtable-utils");
9
- var _baseCalculator = _interopRequireDefault(require("./base-calculator"));
10
- var _sqlUtils = require("../utils/sql-utils");
11
- var _constants = require("../constants");
12
- var _commonUtils = require("../utils/common-utils");
13
- var _statUtils = _interopRequireDefault(require("../utils/stat-utils"));
14
- var _rowUtils = require("../utils/row-utils");
15
- class CompletenessCalculator extends _baseCalculator.default {
16
- isValidChart(chart) {
17
- if (!this.validateBaseConfigs(chart)) {
18
- return false;
19
- }
20
- const {
21
- type,
22
- table_id,
23
- name_column,
24
- completed_column,
25
- target_column,
26
- group_column
27
- } = chart;
28
- const table = this.getTableById(table_id);
29
- if (!(0, _dtableUtils.getTableColumnByKey)(table, name_column)) {
30
- return false;
31
- }
32
- if (!(0, _dtableUtils.getTableColumnByKey)(table, completed_column)) {
33
- return false;
34
- }
35
- if (!(0, _dtableUtils.getTableColumnByKey)(table, target_column)) {
36
- return false;
37
- }
38
- if (type === _constants.STAT_TYPE.GROUP_COMPLETENESS_CHART && (!group_column || !(0, _dtableUtils.getTableColumnByKey)(table, group_column))) {
39
- return false;
40
- }
41
- return true;
42
- }
43
- async calculate(chart) {
44
- if (!this.isValidChart(chart)) return [];
45
- if (this.isCalcByQueryDB(chart)) {
46
- return await this.queryDb(chart);
47
- }
48
- return await this.calculateWithWorker(chart);
49
- }
50
- async queryDb(chart) {
51
- const {
52
- table_id,
53
- view_id,
54
- name_column,
55
- completed_column,
56
- target_column,
57
- group_column,
58
- date_granularity
59
- } = chart;
60
- const selectedTable = this.getTableById(table_id);
61
- const selectedView = this.getViewById(view_id, selectedTable);
62
- if (!selectedView) {
63
- return [];
64
- }
65
- const selectedColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, name_column);
66
- const groupName = "`".concat(selectedColumn.name, "`");
67
- const sqlCondition = this.filter2SqlCondition(selectedTable, selectedView);
68
- const completedColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, completed_column);
69
- const targetColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, target_column);
70
- const groupColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, group_column);
71
- const sqlOrder = (0, _sqlUtils.getSqlOrder)(null, groupName);
72
- const isColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(selectedColumn);
73
- const memo = new Map();
74
- const resultList = [];
75
- if (!groupColumn) {
76
- const completedColumnName = "`".concat(completedColumn.name, "`"),
77
- targetColumnName = "`".concat(targetColumn.name, "`");
78
- const sqlString = "select ".concat(groupName, ", ").concat(completedColumnName, ", ").concat(targetColumnName, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, ", ").concat(completedColumnName, ", ").concat(targetColumnName, " ").concat(sqlOrder, " desc limit 5000");
79
- const result = await this.sqlQuery(sqlString);
80
- if (!result.status === 200 || !result.data.success) return [];
81
- const data = result.data;
82
- if (!data.results) return [];
83
- data.results.forEach(item => {
84
- const name = item[selectedColumn.key];
85
- let label;
86
- if (name || Number.isFinite(name)) {
87
- label = _statUtils.default.getGroupLabel(name, item, selectedColumn, '', '', this.value);
88
- if (isColumnDataAsAnArray) {
89
- label = label[0];
90
- }
91
- label = (0, _rowUtils.getFormattedLabel)(selectedColumn, label, this.value.collaborators);
92
- if (!memo.get(label)) {
93
- const completedValue = item[completedColumn.key] || 0;
94
- const targetValue = item[targetColumn.key] || 0;
95
- if (completedValue >= targetValue) {
96
- resultList.push({
97
- name: label,
98
- original_name: name,
99
- value: completedValue,
100
- type: 'completed',
101
- current_value: completedValue,
102
- target_value: targetValue
103
- });
104
- } else {
105
- resultList.push({
106
- name: label,
107
- original_name: name,
108
- value: completedValue,
109
- type: 'completed',
110
- current_value: completedValue,
111
- target_value: targetValue
112
- }, {
113
- name: label,
114
- original_name: name,
115
- value: targetValue - completedValue,
116
- type: 'uncompleted',
117
- current_value: completedValue,
118
- target_value: targetValue
119
- });
120
- }
121
- memo.set(label, 1);
122
- }
123
- }
124
- });
125
- } else {
126
- const isTimeGroupColumn = _constants.TIME_COLUMN_LIST.includes(groupColumn.type);
127
- const isGroupColumnDataAsAnArray = (0, _commonUtils.isArrayCellValue)(groupColumn);
128
- const completedColumnName = "`".concat(completedColumn.name, "`");
129
- const targetColumnName = "`".concat(targetColumn.name, "`");
130
- let groupColumnName = "`".concat(groupColumn.name, "`");
131
- if (isTimeGroupColumn) {
132
- groupColumnName = (0, _sqlUtils.getSqlGroup)(date_granularity, groupColumn);
133
- }
134
- const sqlString = "select ".concat(groupName, ", ").concat(completedColumnName, ", ").concat(targetColumnName, ", ").concat(groupColumnName, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(groupName, ", ").concat(completedColumnName, ", ").concat(targetColumnName, ", ").concat(groupColumnName, " ").concat(sqlOrder, " desc limit 5000");
135
- const result = await this.sqlQuery(sqlString);
136
- let colorMap = {};
137
- if (!result.status === 200 || !result.data.success) return [];
138
- const data = result.data;
139
- if (!data.results) return [];
140
- let colorIndex = 0;
141
- data.results.forEach(item => {
142
- const name = item[selectedColumn.key];
143
- let label;
144
- let groupLabel;
145
-
146
- // get and format name
147
- if (name || Number.isFinite(name)) {
148
- label = _statUtils.default.getGroupLabel(name, item, selectedColumn, '', '', this.value);
149
- if (isColumnDataAsAnArray) {
150
- label = label[0];
151
- }
152
- label = (0, _rowUtils.getFormattedLabel)(selectedColumn, label, this.value.collaborators);
153
- }
154
-
155
- // get and format group name
156
- if (!isTimeGroupColumn) {
157
- groupLabel = item[groupColumn.key];
158
- groupLabel = _statUtils.default.getGroupLabel(groupLabel, item, groupColumn, '', '', this.value);
159
- if (groupLabel && isGroupColumnDataAsAnArray) {
160
- groupLabel = groupLabel[0];
161
- }
162
- groupLabel = (0, _rowUtils.getFormattedLabel)(groupColumn, groupLabel, this.value.collaborators);
163
- } else {
164
- groupLabel = item[groupColumnName] + '';
165
- }
166
-
167
- // get group color
168
- let color = colorMap[groupLabel];
169
- if (!color) {
170
- color = _constants.PIE_CHART_COLORS[colorIndex % 12];
171
- colorMap[groupLabel] = color;
172
- colorIndex++;
173
- }
174
- const cache = memo.get(label);
175
- if (!cache || !cache[groupLabel]) {
176
- const completedValue = item[completedColumn.key] || 0;
177
- const targetValue = item[targetColumn.key] || 0;
178
- if (label && groupLabel) {
179
- resultList.push({
180
- name: label,
181
- original_name: name,
182
- group_label: groupLabel,
183
- value: completedValue,
184
- type: 'completed',
185
- current_value: completedValue,
186
- target_value: targetValue
187
- });
188
- if (completedValue < targetValue) {
189
- resultList.push({
190
- name: label,
191
- original_name: name,
192
- group_label: groupLabel,
193
- value: targetValue - completedValue,
194
- type: 'uncompleted',
195
- current_value: completedValue,
196
- target_value: targetValue
197
- });
198
- }
199
- if (cache) {
200
- cache[groupLabel] = 1;
201
- memo.set(label, cache);
202
- } else {
203
- memo.set(label, {
204
- [groupLabel]: 1
205
- });
206
- }
207
- }
208
- }
209
- });
210
- resultList.colorMap = colorMap;
211
- }
212
- return resultList;
213
- }
214
- }
215
- var _default = exports.default = CompletenessCalculator;
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- const IGNORE_KEYS = ['description', 'format_version', 'plugin_settings', 'plugins', 'statistics', 'version', 'scripts', 'settings'];
8
- const TABLE_IGNORE_KEYS = ['summary_configs', 'is_header_locked'];
9
- const copyValue = value => {
10
- const newValue = {};
11
- Object.keys(value).forEach(key => {
12
- if (key !== 'tables' && !IGNORE_KEYS.includes(key)) {
13
- newValue[key] = value[key];
14
- }
15
- });
16
- const tables = value.tables;
17
- const newTables = [];
18
- tables.forEach(table => {
19
- const newTable = {};
20
- Object.keys(table).forEach(key => {
21
- if (key === 'columns') {
22
- const columns = table.columns;
23
- const newColumns = [];
24
- columns.forEach(column => {
25
- const newColumn = Object.assign({}, column, {
26
- editor: null,
27
- formatter: null
28
- });
29
- newColumns.push(newColumn);
30
- });
31
- newTable.columns = newColumns;
32
- } else if (key === 'views') {
33
- const views = table['views'];
34
- const newViews = [];
35
- views.forEach(view => {
36
- const newView = Object.assign({}, view, {
37
- colorbys: null,
38
- archived_columns: null,
39
- archived_rows: null
40
- });
41
- newViews.push(newView);
42
- });
43
- newTable[key] = newViews;
44
- } else if (!TABLE_IGNORE_KEYS.includes(key)) {
45
- newTable[key] = table[key];
46
- }
47
- });
48
- newTables.push(newTable);
49
- });
50
- newValue.tables = newTables;
51
- return newValue;
52
- };
53
- var _default = exports.default = copyValue;
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _dtableUtils = require("dtable-utils");
9
- var _constants = require("../constants");
10
- var _commonUtils = require("../utils/common-utils");
11
- var _baseCalculator = _interopRequireDefault(require("./base-calculator"));
12
- class DashboardCalculator extends _baseCalculator.default {
13
- isValidChart(chart) {
14
- if (!this.validateBaseConfigs(chart)) {
15
- return false;
16
- }
17
- const {
18
- table_id,
19
- target_value_column,
20
- total_value_column
21
- } = chart;
22
- const table = this.getTableById(table_id);
23
- const selectedColumn1 = (0, _dtableUtils.getTableColumnByKey)(table, target_value_column);
24
- const selectedColumn2 = (0, _dtableUtils.getTableColumnByKey)(table, total_value_column);
25
- if (!selectedColumn1 || !selectedColumn2) {
26
- return false;
27
- }
28
- return true;
29
- }
30
- async calculate(chart) {
31
- if (!this.isValidChart(chart)) return 0;
32
- if (this.isCalcByQueryDB(chart)) {
33
- return await this.queryDb(chart);
34
- }
35
- return await this.calculateWithWorker(chart);
36
- }
37
- async queryDb(chart) {
38
- const {
39
- table_id,
40
- view_id,
41
- target_value_column,
42
- target_value_column_summary_method,
43
- total_value_column,
44
- total_value_column_summary_method
45
- } = chart;
46
- const selectedTable = this.getTableById(table_id);
47
- const selectedView = this.getViewById(view_id, selectedTable);
48
- const selectedColumn1 = (0, _dtableUtils.getTableColumnByKey)(selectedTable, target_value_column);
49
- const selectedColumn2 = (0, _dtableUtils.getTableColumnByKey)(selectedTable, total_value_column);
50
- const sqlCondition = this.filter2SqlCondition(selectedTable, selectedView);
51
- const key1 = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[target_value_column_summary_method], selectedColumn1.name);
52
- const key2 = (0, _commonUtils.getSummaryColumnMethod)(_constants.DTABLE_DB_SUMMARY_METHOD[total_value_column_summary_method], selectedColumn2.name);
53
- const sqlString = "select ".concat(key1, ", ").concat(key2, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " limit 5000");
54
- const result = await this.sqlQuery(sqlString);
55
- if (result.status === 200 && result.data.success) {
56
- const data = result.data.results;
57
- if (!data) return 0;
58
- if (data.length > 0) {
59
- const result1 = data[0][key1];
60
- const result2 = data[0][key2];
61
- if (result2 === 0) {
62
- return 0;
63
- }
64
- return result1 / result2;
65
- }
66
- }
67
- return 0;
68
- }
69
- }
70
- var _default = exports.default = DashboardCalculator;
@@ -1,148 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _dayjs = _interopRequireDefault(require("dayjs"));
9
- var _dtableUtils = require("dtable-utils");
10
- var _baseCalculator = _interopRequireDefault(require("./base-calculator"));
11
- var _commonUtils = require("../utils/common-utils");
12
- var _constants = require("../constants");
13
- class HeatMapCalculator extends _baseCalculator.default {
14
- isValidChart(chart) {
15
- if (!this.validateBaseConfigs(chart)) {
16
- return false;
17
- }
18
- const {
19
- table_id,
20
- time_column,
21
- summary_column
22
- } = chart;
23
- const table = this.getTableById(table_id);
24
- if (!(0, _dtableUtils.getTableColumnByKey)(table, time_column)) {
25
- return false;
26
- }
27
- if (summary_column && !(0, _dtableUtils.getTableColumnByKey)(table, summary_column)) {
28
- return false;
29
- }
30
- return true;
31
- }
32
- async calculate(chart) {
33
- if (!this.isValidChart(chart)) return {
34
- data: [],
35
- years: []
36
- };
37
- const result = this.isCalcByQueryDB(chart) ? await this.queryDb(chart) : await this.calculateWithWorker(this.convertChart(chart));
38
- let data = [];
39
- let years = [];
40
- result.forEach(item => {
41
- if (!item.name) {
42
- data.push(item);
43
- return;
44
- }
45
- const year = (0, _dayjs.default)(item.name).year();
46
- data.push({
47
- ...item,
48
- year
49
- });
50
- if (years.indexOf(year) < 0) {
51
- years.push(year);
52
- }
53
- });
54
- this.sortDataByYear(data);
55
- return {
56
- data,
57
- years
58
- };
59
- }
60
- async queryDb(chart) {
61
- const {
62
- table_id,
63
- view_id,
64
- time_column,
65
- summary_type,
66
- summary_method,
67
- summary_column
68
- } = chart;
69
- const selectedTable = this.getTableById(table_id);
70
- const selectedView = this.getViewById(view_id, selectedTable);
71
- const selectedColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, time_column);
72
- const columnName = selectedColumn.name;
73
- const isAdvanced = summary_type === 'advanced';
74
- const method = isAdvanced ? _constants.DTABLE_DB_SUMMARY_METHOD[summary_method] : 'COUNT';
75
- const sqlCondition = this.filter2SqlCondition(selectedTable, selectedView);
76
- let summaryColumnName = '';
77
- let summaryColumn;
78
- let sqlString = '';
79
- if (isAdvanced) {
80
- summaryColumn = (0, _dtableUtils.getTableColumnByKey)(selectedTable, summary_column);
81
- if (!summaryColumn) {
82
- return [];
83
- }
84
- summaryColumnName = summaryColumn.name;
85
- const summaryColumnMethod = (0, _commonUtils.getSummaryColumnMethod)(method, summaryColumnName);
86
- sqlString = "select `".concat(columnName, "`, ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by `").concat(columnName, "` limit 5000");
87
- } else {
88
- sqlString = "select `".concat(columnName, "`, ").concat(method, "(").concat(columnName, ") from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by `").concat(columnName, "` limit 5000");
89
- }
90
- const result = await this.sqlQuery(sqlString);
91
- if (result.status === 200 && result.data.success) {
92
- const data = result.data;
93
- if (!data.results) return [];
94
- const newResult = [];
95
- const summaryColumnMethod = (0, _commonUtils.getSummaryColumnMethod)(method, summaryColumnName);
96
- const valueKey = isAdvanced ? "".concat(summaryColumnMethod) : "".concat(method, "(").concat(columnName, ")");
97
- data.results.forEach(item => {
98
- const currentValue = item[time_column];
99
- if (currentValue) {
100
- let value = item[valueKey];
101
- if (isAdvanced) {
102
- value = (0, _commonUtils.formatNumericValue)(value, summaryColumn);
103
- }
104
- const name = typeof currentValue === 'string' ? currentValue : currentValue.country_region;
105
- newResult.push({
106
- name: (0, _dayjs.default)(name).format('YYYY-MM-DD'),
107
- value
108
- });
109
- }
110
- });
111
- return newResult;
112
- }
113
- return [];
114
- }
115
- convertChart(chart) {
116
- const {
117
- _id,
118
- table_id,
119
- view_id,
120
- time_column,
121
- summary_type,
122
- summary_column,
123
- summary_method
124
- } = chart;
125
- return {
126
- _id,
127
- table_id,
128
- view_id,
129
- x_axis_column_key: time_column,
130
- y_axis_summary_type: summary_type,
131
- y_axis_summary_method: summary_method,
132
- y_axis_column_key: summary_column,
133
- x_axis_date_granularity: 'day'
134
- };
135
- }
136
- sortDataByYear(data) {
137
- data.sort((current, next) => {
138
- if (current.year > next.year) {
139
- return -1;
140
- } else if (current.year < next.year) {
141
- return 1;
142
- } else {
143
- return 0;
144
- }
145
- });
146
- }
147
- }
148
- var _default = exports.default = HeatMapCalculator;