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.
Files changed (219) hide show
  1. package/es/api/dtable-db-api.js +31 -37
  2. package/es/calculator/base-calculator.js +49 -99
  3. package/es/calculator/basic-chart-calculator.js +335 -559
  4. package/es/calculator/combination-calculator.js +231 -299
  5. package/es/calculator/compare-bar-calculator.js +184 -281
  6. package/es/calculator/completeness-calculator.js +203 -288
  7. package/es/calculator/copy-value.js +18 -18
  8. package/es/calculator/dashboard-calculator.js +68 -137
  9. package/es/calculator/heat-map-calculator.js +139 -220
  10. package/es/calculator/horizontal-bar-calculator.js +64 -93
  11. package/es/calculator/index.js +53 -69
  12. package/es/calculator/map-calculator.js +98 -174
  13. package/es/calculator/mirror-calculator.js +137 -216
  14. package/es/calculator/number-card-calculator.js +58 -126
  15. package/es/calculator/pivot-table-calculator.js +750 -792
  16. package/es/calculator/scatter-calculator.js +72 -140
  17. package/es/calculator/thread-manager.js +48 -67
  18. package/es/calculator/trend-calculator.js +107 -191
  19. package/es/calculator/workers/basic-chart-calculator-worker.js +194 -165
  20. package/es/calculator/workers/calculator.worker.js +22 -6
  21. package/es/calculator/workers/card-calculator-worker.js +16 -14
  22. package/es/calculator/workers/combination-calculator-worker.js +128 -135
  23. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +80 -96
  24. package/es/calculator/workers/completeness-calculator-worker.js +56 -49
  25. package/es/calculator/workers/dashboard-calculator-worker.js +24 -22
  26. package/es/calculator/workers/mirror-calculator-worker.js +52 -52
  27. package/es/calculator/workers/pivot-table-calculator-worker.js +247 -230
  28. package/es/calculator/workers/scatter-calculator-worker.js +34 -32
  29. package/es/calculator/workers/trend-calculator-worker.js +33 -29
  30. package/es/calculator/world-map-calculator.js +120 -197
  31. package/es/components/common-add-tool.js +7 -5
  32. package/es/components/dialog/chart-addition-edit-dialog.js +67 -77
  33. package/es/components/dialog/chart-addition-widgets/chart-selector.js +57 -67
  34. package/es/components/dialog/color-theme-dialog.js +34 -47
  35. package/es/components/dialog/delete-confirmation-dialog.js +7 -5
  36. package/es/components/dialog/enlarged-chart-dialog.js +68 -81
  37. package/es/components/dialog/new-table-dialog.js +62 -80
  38. package/es/components/dialog/new-view-dialog.js +50 -62
  39. package/es/components/dialog/rename-view-dialog.js +49 -58
  40. package/es/components/dialog/statistic-record-dialog/index.js +233 -231
  41. package/es/components/dialog/statistic-types-dialog/index.js +40 -49
  42. package/es/components/dialog/table-select-dialog.js +61 -70
  43. package/es/components/dropdown-menu/statistic-dropdown-menu.js +129 -142
  44. package/es/components/dtable-popover.js +62 -81
  45. package/es/components/dtable-search-input.js +89 -99
  46. package/es/components/dtable-select.js +55 -74
  47. package/es/components/icon.js +5 -3
  48. package/es/components/loading.js +1 -1
  49. package/es/components/modal-portal.js +15 -32
  50. package/es/components/popover/color-rules/color-rule.js +137 -141
  51. package/es/components/popover/color-rules/index.js +58 -66
  52. package/es/components/popover/color-rules/rule-filters/filter.js +124 -124
  53. package/es/components/popover/color-rules/rule-filters/index.js +50 -58
  54. package/es/components/popover/color-rules/rule-filters/number-input.js +42 -57
  55. package/es/components/popover/color-rules-popover.js +117 -121
  56. package/es/components/popover/color-selector-popover.js +60 -70
  57. package/es/components/seatable-radio/index.js +2 -2
  58. package/es/components/select/option-group.js +139 -157
  59. package/es/components/select/option.js +26 -40
  60. package/es/components/select/select.js +97 -112
  61. package/es/components/toast/alert.js +65 -80
  62. package/es/components/toast/index.js +1 -1
  63. package/es/components/toast/toast.js +76 -103
  64. package/es/components/toast/toastManager.js +57 -93
  65. package/es/components/toast/toaster.js +58 -56
  66. package/es/constants/color-rules.js +8 -5
  67. package/es/constants/dtable-select-style.js +44 -48
  68. package/es/constants/event-types.js +4 -4
  69. package/es/constants/index.js +328 -242
  70. package/es/constants/map.js +2 -2
  71. package/es/constants/model.js +20 -20
  72. package/es/constants/regions.js +1 -1
  73. package/es/constants/zIndexes.js +1 -1
  74. package/es/custom-g2.js +11 -11
  75. package/es/dashboard.js +343 -333
  76. package/es/desktop-dashboard.js +217 -224
  77. package/es/index.js +45 -58
  78. package/es/locale/index.js +3 -3
  79. package/es/locale/lang/de.js +1 -1
  80. package/es/locale/lang/en.js +7 -7
  81. package/es/locale/lang/fr.js +1 -1
  82. package/es/locale/lang/zh_CN.js +1 -1
  83. package/es/mobile-dashboard.js +76 -89
  84. package/es/model/bar-group.js +34 -44
  85. package/es/model/bar.js +26 -36
  86. package/es/model/base-model.js +11 -12
  87. package/es/model/basic-number-card.js +10 -20
  88. package/es/model/collaborators.js +10 -11
  89. package/es/model/combination.js +32 -42
  90. package/es/model/compare-bar.js +30 -40
  91. package/es/model/completeness-group.js +19 -29
  92. package/es/model/completeness.js +14 -24
  93. package/es/model/custom-bar.js +14 -24
  94. package/es/model/dashboard.js +9 -19
  95. package/es/model/generic-model.js +187 -197
  96. package/es/model/heat-map.js +16 -26
  97. package/es/model/horizontal-bar-group.js +32 -42
  98. package/es/model/horizontal-bar.js +26 -36
  99. package/es/model/index.js +31 -3
  100. package/es/model/map.js +20 -30
  101. package/es/model/mirror.js +15 -25
  102. package/es/model/pie.js +21 -31
  103. package/es/model/ring.js +23 -33
  104. package/es/model/scatter.js +11 -21
  105. package/es/model/statistic-dashboard.js +7 -8
  106. package/es/model/table.js +19 -29
  107. package/es/model/trend.js +15 -25
  108. package/es/model/world-map.js +17 -27
  109. package/es/service/chart-service.js +69 -65
  110. package/es/service/dashboard-service.js +421 -419
  111. package/es/service/map-json.js +112 -132
  112. package/es/stat-editor/chart-name-editor.js +44 -58
  113. package/es/stat-editor/index.js +59 -70
  114. package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +93 -98
  115. package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +246 -248
  116. package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +127 -126
  117. package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +5 -3
  118. package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +78 -90
  119. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +146 -150
  120. package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +88 -98
  121. package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +100 -118
  122. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +161 -148
  123. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +58 -66
  124. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +58 -60
  125. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +152 -148
  126. package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +101 -105
  127. package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +81 -91
  128. package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +110 -122
  129. package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +101 -113
  130. package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +130 -120
  131. package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +88 -102
  132. package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +88 -102
  133. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +200 -194
  134. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +98 -110
  135. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +106 -118
  136. package/es/stat-editor/stat-settings/basic-chart-settings/index.js +212 -223
  137. package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +109 -119
  138. package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +329 -319
  139. package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +82 -90
  140. package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +58 -65
  141. package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +126 -116
  142. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +201 -182
  143. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +79 -79
  144. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +196 -175
  145. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +35 -50
  146. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +180 -147
  147. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +31 -40
  148. package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +56 -67
  149. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +60 -69
  150. package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +165 -158
  151. package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +61 -74
  152. package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +199 -193
  153. package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +25 -38
  154. package/es/stat-editor/stat-settings/color-setting/color-picker.js +79 -86
  155. package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +138 -120
  156. package/es/stat-editor/stat-settings/map/map-level.js +31 -43
  157. package/es/stat-editor/stat-settings/map/map-province-city.js +82 -83
  158. package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +48 -50
  159. package/es/stat-editor/stat-settings/public-setting/base-settings.js +96 -96
  160. package/es/stat-editor/stat-settings/public-setting/calender.js +69 -75
  161. package/es/stat-editor/stat-settings/public-setting/column-settings.js +5 -3
  162. package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +36 -41
  163. package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +37 -41
  164. package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +25 -38
  165. package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +40 -52
  166. package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +90 -93
  167. package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +23 -36
  168. package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +39 -44
  169. package/es/stat-list/chart-preview.js +85 -98
  170. package/es/stat-list/index.js +170 -178
  171. package/es/stat-view/area-chart.js +282 -274
  172. package/es/stat-view/bar-chart.js +300 -292
  173. package/es/stat-view/base-chart.js +58 -52
  174. package/es/stat-view/basic-number-card.js +115 -168
  175. package/es/stat-view/combination-chart.js +298 -334
  176. package/es/stat-view/compare-chart.js +256 -254
  177. package/es/stat-view/completeness-chart.js +194 -206
  178. package/es/stat-view/custom-bar.js +221 -223
  179. package/es/stat-view/dashboard-chart.js +122 -180
  180. package/es/stat-view/heat-map.js +268 -294
  181. package/es/stat-view/horizontal-bar-chart.js +291 -281
  182. package/es/stat-view/index.js +136 -152
  183. package/es/stat-view/line-chart.js +267 -265
  184. package/es/stat-view/map.js +246 -246
  185. package/es/stat-view/mirror.js +141 -152
  186. package/es/stat-view/pie-chart.js +143 -156
  187. package/es/stat-view/pivot-table/index.js +113 -118
  188. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +104 -102
  189. package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +116 -118
  190. package/es/stat-view/pivot-table/pivot-table-display-name.js +96 -95
  191. package/es/stat-view/pivot-table/two-dimension-table.js +238 -229
  192. package/es/stat-view/ring-chart.js +189 -200
  193. package/es/stat-view/scatter-chart.js +162 -213
  194. package/es/stat-view/treemap-chart.js +136 -200
  195. package/es/stat-view/trend-chart.js +137 -183
  196. package/es/stat-view/world-map.js +233 -243
  197. package/es/tabs/index.js +164 -169
  198. package/es/tabs/tab.js +101 -116
  199. package/es/utils/basic-chart-utils.js +7 -9
  200. package/es/utils/cell-format.js +48 -51
  201. package/es/utils/cell-value.js +1 -1
  202. package/es/utils/collaborator.js +15 -14
  203. package/es/utils/color-utils.js +48 -37
  204. package/es/utils/column-utils.js +47 -33
  205. package/es/utils/column.js +1 -1
  206. package/es/utils/common-utils.js +111 -117
  207. package/es/utils/date-format.js +17 -17
  208. package/es/utils/export-table-utils.js +507 -396
  209. package/es/utils/index.js +6 -6
  210. package/es/utils/map.js +30 -34
  211. package/es/utils/model.js +3 -5
  212. package/es/utils/object.js +4 -4
  213. package/es/utils/pivot-table.js +20 -20
  214. package/es/utils/row-utils.js +41 -33
  215. package/es/utils/search.js +18 -20
  216. package/es/utils/sql-utils.js +132 -98
  217. package/es/utils/stat-utils.js +303 -320
  218. package/es/utils/trend-utils.js +57 -67
  219. package/package.json +2 -2
@@ -1,146 +1,77 @@
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 { filter2SqlCondition, TableUtils } from 'dtable-store';
8
2
  import { DTABLE_DB_SUMMARY_METHOD } from '../constants';
9
3
  import { getSummaryColumnMethod } from '../utils/common-utils';
10
4
  import BaseCalculator from './base-calculator';
11
- var DashboardCalculator = /*#__PURE__*/function (_BaseCalculator) {
12
- _inherits(DashboardCalculator, _BaseCalculator);
13
- var _super = _createSuper(DashboardCalculator);
14
- function DashboardCalculator(_ref) {
15
- var value = _ref.value,
16
- statisticThreadManager = _ref.statisticThreadManager,
17
- username = _ref.username,
18
- userId = _ref.userId;
19
- _classCallCheck(this, DashboardCalculator);
20
- return _super.call(this, {
21
- value: value,
22
- statisticThreadManager: statisticThreadManager,
23
- username: username,
24
- userId: userId
5
+ class DashboardCalculator extends BaseCalculator {
6
+ constructor(_ref) {
7
+ let {
8
+ value,
9
+ statisticThreadManager,
10
+ username,
11
+ userId
12
+ } = _ref;
13
+ super({
14
+ value,
15
+ statisticThreadManager,
16
+ username,
17
+ userId
25
18
  });
26
19
  }
27
- _createClass(DashboardCalculator, [{
28
- key: "isValidChart",
29
- value: function isValidChart(chart) {
30
- if (!this.validateBaseConfigs(chart)) {
31
- return false;
32
- }
33
- var table_id = chart.table_id,
34
- target_value_column = chart.target_value_column,
35
- total_value_column = chart.total_value_column;
36
- var table = this.getTableById(table_id);
37
- var selectedColumn1 = TableUtils.getTableColumnByKey(table, target_value_column);
38
- var selectedColumn2 = TableUtils.getTableColumnByKey(table, total_value_column);
39
- if (!selectedColumn1 || !selectedColumn2) {
40
- return false;
41
- }
42
- return true;
20
+ isValidChart(chart) {
21
+ if (!this.validateBaseConfigs(chart)) {
22
+ return false;
43
23
  }
44
- }, {
45
- key: "calculate",
46
- value: function () {
47
- var _calculate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(chart) {
48
- return _regeneratorRuntime.wrap(function _callee$(_context) {
49
- while (1) {
50
- switch (_context.prev = _context.next) {
51
- case 0:
52
- if (this.isValidChart(chart)) {
53
- _context.next = 2;
54
- break;
55
- }
56
- return _context.abrupt("return", 0);
57
- case 2:
58
- if (!this.isCalcByQueryDB(chart)) {
59
- _context.next = 6;
60
- break;
61
- }
62
- _context.next = 5;
63
- return this.queryDb(chart);
64
- case 5:
65
- return _context.abrupt("return", _context.sent);
66
- case 6:
67
- _context.next = 8;
68
- return this.calculateWithWorker(chart);
69
- case 8:
70
- return _context.abrupt("return", _context.sent);
71
- case 9:
72
- case "end":
73
- return _context.stop();
74
- }
75
- }
76
- }, _callee, this);
77
- }));
78
- function calculate(_x) {
79
- return _calculate.apply(this, arguments);
80
- }
81
- return calculate;
82
- }()
83
- }, {
84
- key: "queryDb",
85
- value: function () {
86
- var _queryDb = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chart) {
87
- var table_id, view_id, target_value_column, target_value_column_summary_method, total_value_column, total_value_column_summary_method, selectedTable, selectedView, selectedColumn1, selectedColumn2, sqlCondition, key1, key2, sqlString, result, data, result1, result2;
88
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
89
- while (1) {
90
- switch (_context2.prev = _context2.next) {
91
- case 0:
92
- table_id = chart.table_id, view_id = chart.view_id, target_value_column = chart.target_value_column, target_value_column_summary_method = chart.target_value_column_summary_method, total_value_column = chart.total_value_column, total_value_column_summary_method = chart.total_value_column_summary_method;
93
- selectedTable = this.getTableById(table_id);
94
- selectedView = this.getViewById(view_id, selectedTable);
95
- selectedColumn1 = TableUtils.getTableColumnByKey(selectedTable, target_value_column);
96
- selectedColumn2 = TableUtils.getTableColumnByKey(selectedTable, total_value_column);
97
- sqlCondition = filter2SqlCondition(selectedTable, selectedView);
98
- key1 = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[target_value_column_summary_method], selectedColumn1.name);
99
- key2 = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[total_value_column_summary_method], selectedColumn2.name);
100
- sqlString = "select ".concat(key1, ", ").concat(key2, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " limit 5000");
101
- _context2.next = 11;
102
- return this.sqlQuery(sqlString);
103
- case 11:
104
- result = _context2.sent;
105
- if (!(result.status === 200 && result.data.success)) {
106
- _context2.next = 22;
107
- break;
108
- }
109
- data = result.data.results;
110
- if (data) {
111
- _context2.next = 16;
112
- break;
113
- }
114
- return _context2.abrupt("return", 0);
115
- case 16:
116
- if (!(data.length > 0)) {
117
- _context2.next = 22;
118
- break;
119
- }
120
- result1 = data[0][key1];
121
- result2 = data[0][key2];
122
- if (!(result2 === 0)) {
123
- _context2.next = 21;
124
- break;
125
- }
126
- return _context2.abrupt("return", 0);
127
- case 21:
128
- return _context2.abrupt("return", result1 / result2);
129
- case 22:
130
- return _context2.abrupt("return", 0);
131
- case 23:
132
- case "end":
133
- return _context2.stop();
134
- }
135
- }
136
- }, _callee2, this);
137
- }));
138
- function queryDb(_x2) {
139
- return _queryDb.apply(this, arguments);
24
+ const {
25
+ table_id,
26
+ target_value_column,
27
+ total_value_column
28
+ } = chart;
29
+ const table = this.getTableById(table_id);
30
+ const selectedColumn1 = TableUtils.getTableColumnByKey(table, target_value_column);
31
+ const selectedColumn2 = TableUtils.getTableColumnByKey(table, total_value_column);
32
+ if (!selectedColumn1 || !selectedColumn2) {
33
+ return false;
34
+ }
35
+ return true;
36
+ }
37
+ async calculate(chart) {
38
+ if (!this.isValidChart(chart)) return 0;
39
+ if (this.isCalcByQueryDB(chart)) {
40
+ return await this.queryDb(chart);
41
+ }
42
+ return await this.calculateWithWorker(chart);
43
+ }
44
+ async queryDb(chart) {
45
+ const {
46
+ table_id,
47
+ view_id,
48
+ target_value_column,
49
+ target_value_column_summary_method,
50
+ total_value_column,
51
+ total_value_column_summary_method
52
+ } = chart;
53
+ const selectedTable = this.getTableById(table_id);
54
+ const selectedView = this.getViewById(view_id, selectedTable);
55
+ const selectedColumn1 = TableUtils.getTableColumnByKey(selectedTable, target_value_column);
56
+ const selectedColumn2 = TableUtils.getTableColumnByKey(selectedTable, total_value_column);
57
+ const sqlCondition = filter2SqlCondition(selectedTable, selectedView);
58
+ const key1 = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[target_value_column_summary_method], selectedColumn1.name);
59
+ const key2 = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[total_value_column_summary_method], selectedColumn2.name);
60
+ const sqlString = "select ".concat(key1, ", ").concat(key2, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " limit 5000");
61
+ const result = await this.sqlQuery(sqlString);
62
+ if (result.status === 200 && result.data.success) {
63
+ const data = result.data.results;
64
+ if (!data) return 0;
65
+ if (data.length > 0) {
66
+ const result1 = data[0][key1];
67
+ const result2 = data[0][key2];
68
+ if (result2 === 0) {
69
+ return 0;
70
+ }
71
+ return result1 / result2;
140
72
  }
141
- return queryDb;
142
- }()
143
- }]);
144
- return DashboardCalculator;
145
- }(BaseCalculator);
73
+ }
74
+ return 0;
75
+ }
76
+ }
146
77
  export default DashboardCalculator;
@@ -1,236 +1,155 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
- import _createClass from "@babel/runtime/helpers/esm/createClass";
6
- import _inherits from "@babel/runtime/helpers/esm/inherits";
7
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
8
1
  import dayjs from 'dayjs';
9
2
  import { filter2SqlCondition, TableUtils } from 'dtable-store';
10
3
  import BaseCalculator from './base-calculator';
11
4
  import { formatNumericValue, getSummaryColumnMethod } from '../utils/common-utils';
12
5
  import { DTABLE_DB_SUMMARY_METHOD } from '../constants';
13
- var HeatMapCalculator = /*#__PURE__*/function (_BaseCalculator) {
14
- _inherits(HeatMapCalculator, _BaseCalculator);
15
- var _super = _createSuper(HeatMapCalculator);
16
- function HeatMapCalculator(_ref) {
17
- var value = _ref.value,
18
- statisticThreadManager = _ref.statisticThreadManager,
19
- username = _ref.username,
20
- userId = _ref.userId;
21
- _classCallCheck(this, HeatMapCalculator);
22
- return _super.call(this, {
23
- value: value,
24
- statisticThreadManager: statisticThreadManager,
25
- username: username,
26
- userId: userId
6
+ class HeatMapCalculator extends BaseCalculator {
7
+ constructor(_ref) {
8
+ let {
9
+ value,
10
+ statisticThreadManager,
11
+ username,
12
+ userId
13
+ } = _ref;
14
+ super({
15
+ value,
16
+ statisticThreadManager,
17
+ username,
18
+ userId
27
19
  });
28
20
  }
29
- _createClass(HeatMapCalculator, [{
30
- key: "isValidChart",
31
- value: function isValidChart(chart) {
32
- if (!this.validateBaseConfigs(chart)) {
33
- return false;
21
+ isValidChart(chart) {
22
+ if (!this.validateBaseConfigs(chart)) {
23
+ return false;
24
+ }
25
+ const {
26
+ table_id,
27
+ time_column,
28
+ summary_column
29
+ } = chart;
30
+ const table = this.getTableById(table_id);
31
+ if (!TableUtils.getTableColumnByKey(table, time_column)) {
32
+ return false;
33
+ }
34
+ if (summary_column && !TableUtils.getTableColumnByKey(table, summary_column)) {
35
+ return false;
36
+ }
37
+ return true;
38
+ }
39
+ async calculate(chart) {
40
+ if (!this.isValidChart(chart)) return {
41
+ data: [],
42
+ years: []
43
+ };
44
+ const result = this.isCalcByQueryDB(chart) ? await this.queryDb(chart) : await this.calculateWithWorker(this.convertChart(chart));
45
+ let data = [];
46
+ let years = [];
47
+ result.forEach(item => {
48
+ if (!item.name) {
49
+ data.push(item);
50
+ return;
34
51
  }
35
- var table_id = chart.table_id,
36
- time_column = chart.time_column,
37
- summary_column = chart.summary_column;
38
- var table = this.getTableById(table_id);
39
- if (!TableUtils.getTableColumnByKey(table, time_column)) {
40
- return false;
52
+ const year = dayjs(item.name).year();
53
+ data.push({
54
+ ...item,
55
+ year
56
+ });
57
+ if (years.indexOf(year) < 0) {
58
+ years.push(year);
41
59
  }
42
- if (summary_column && !TableUtils.getTableColumnByKey(table, summary_column)) {
43
- return false;
60
+ });
61
+ this.sortDataByYear(data);
62
+ return {
63
+ data,
64
+ years
65
+ };
66
+ }
67
+ async queryDb(chart) {
68
+ const {
69
+ table_id,
70
+ view_id,
71
+ time_column,
72
+ summary_type,
73
+ summary_method,
74
+ summary_column
75
+ } = chart;
76
+ const selectedTable = this.getTableById(table_id);
77
+ const selectedView = this.getViewById(view_id, selectedTable);
78
+ const selectedColumn = TableUtils.getTableColumnByKey(selectedTable, time_column);
79
+ const columnName = selectedColumn.name;
80
+ const isAdvanced = summary_type === 'advanced';
81
+ const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summary_method] : 'COUNT';
82
+ const sqlCondition = filter2SqlCondition(selectedTable, selectedView);
83
+ let summaryColumnName = '';
84
+ let summaryColumn;
85
+ let sqlString = '';
86
+ if (isAdvanced) {
87
+ summaryColumn = TableUtils.getTableColumnByKey(selectedTable, summary_column);
88
+ if (!summaryColumn) {
89
+ return [];
44
90
  }
45
- return true;
91
+ summaryColumnName = summaryColumn.name;
92
+ const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
93
+ sqlString = "select `".concat(columnName, "`, ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by `").concat(columnName, "` limit 5000");
94
+ } else {
95
+ sqlString = "select `".concat(columnName, "`, ").concat(method, "(").concat(columnName, ") from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by `").concat(columnName, "` limit 5000");
46
96
  }
47
- }, {
48
- key: "calculate",
49
- value: function () {
50
- var _calculate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(chart) {
51
- var result, data, years;
52
- return _regeneratorRuntime.wrap(function _callee$(_context) {
53
- while (1) {
54
- switch (_context.prev = _context.next) {
55
- case 0:
56
- if (this.isValidChart(chart)) {
57
- _context.next = 2;
58
- break;
59
- }
60
- return _context.abrupt("return", {
61
- data: [],
62
- years: []
63
- });
64
- case 2:
65
- if (!this.isCalcByQueryDB(chart)) {
66
- _context.next = 8;
67
- break;
68
- }
69
- _context.next = 5;
70
- return this.queryDb(chart);
71
- case 5:
72
- _context.t0 = _context.sent;
73
- _context.next = 11;
74
- break;
75
- case 8:
76
- _context.next = 10;
77
- return this.calculateWithWorker(this.convertChart(chart));
78
- case 10:
79
- _context.t0 = _context.sent;
80
- case 11:
81
- result = _context.t0;
82
- data = [];
83
- years = [];
84
- result.forEach(function (item) {
85
- if (!item.name) {
86
- data.push(item);
87
- return;
88
- }
89
- var year = dayjs(item.name).year();
90
- data.push(_objectSpread(_objectSpread({}, item), {}, {
91
- year: year
92
- }));
93
- if (years.indexOf(year) < 0) {
94
- years.push(year);
95
- }
96
- });
97
- this.sortDataByYear(data);
98
- return _context.abrupt("return", {
99
- data: data,
100
- years: years
101
- });
102
- case 17:
103
- case "end":
104
- return _context.stop();
105
- }
106
- }
107
- }, _callee, this);
108
- }));
109
- function calculate(_x) {
110
- return _calculate.apply(this, arguments);
111
- }
112
- return calculate;
113
- }()
114
- }, {
115
- key: "queryDb",
116
- value: function () {
117
- var _queryDb = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chart) {
118
- var table_id, view_id, time_column, summary_type, summary_method, summary_column, selectedTable, selectedView, selectedColumn, columnName, isAdvanced, method, sqlCondition, summaryColumnName, summaryColumn, sqlString, summaryColumnMethod, result, data, newResult, _summaryColumnMethod, valueKey;
119
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
120
- while (1) {
121
- switch (_context2.prev = _context2.next) {
122
- case 0:
123
- table_id = chart.table_id, view_id = chart.view_id, time_column = chart.time_column, summary_type = chart.summary_type, summary_method = chart.summary_method, summary_column = chart.summary_column;
124
- selectedTable = this.getTableById(table_id);
125
- selectedView = this.getViewById(view_id, selectedTable);
126
- selectedColumn = TableUtils.getTableColumnByKey(selectedTable, time_column);
127
- columnName = selectedColumn.name;
128
- isAdvanced = summary_type === 'advanced';
129
- method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[summary_method] : 'COUNT';
130
- sqlCondition = filter2SqlCondition(selectedTable, selectedView);
131
- summaryColumnName = '';
132
- sqlString = '';
133
- if (!isAdvanced) {
134
- _context2.next = 19;
135
- break;
136
- }
137
- summaryColumn = TableUtils.getTableColumnByKey(selectedTable, summary_column);
138
- if (summaryColumn) {
139
- _context2.next = 14;
140
- break;
141
- }
142
- return _context2.abrupt("return", []);
143
- case 14:
144
- summaryColumnName = summaryColumn.name;
145
- summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
146
- sqlString = "select `".concat(columnName, "`, ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by `").concat(columnName, "` limit 5000");
147
- _context2.next = 20;
148
- break;
149
- case 19:
150
- sqlString = "select `".concat(columnName, "`, ").concat(method, "(").concat(columnName, ") from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by `").concat(columnName, "` limit 5000");
151
- case 20:
152
- _context2.next = 22;
153
- return this.sqlQuery(sqlString);
154
- case 22:
155
- result = _context2.sent;
156
- if (!(result.status === 200 && result.data.success)) {
157
- _context2.next = 32;
158
- break;
159
- }
160
- data = result.data;
161
- if (data.results) {
162
- _context2.next = 27;
163
- break;
164
- }
165
- return _context2.abrupt("return", []);
166
- case 27:
167
- newResult = [];
168
- _summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
169
- valueKey = isAdvanced ? "".concat(_summaryColumnMethod) : "".concat(method, "(").concat(columnName, ")");
170
- data.results.forEach(function (item) {
171
- var currentValue = item[time_column];
172
- if (currentValue) {
173
- var value = item[valueKey];
174
- if (isAdvanced) {
175
- value = formatNumericValue(value, summaryColumn);
176
- }
177
- var name = typeof currentValue === 'string' ? currentValue : currentValue.country_region;
178
- newResult.push({
179
- name: dayjs(name).format('YYYY-MM-DD'),
180
- value: value
181
- });
182
- }
183
- });
184
- return _context2.abrupt("return", newResult);
185
- case 32:
186
- return _context2.abrupt("return", []);
187
- case 33:
188
- case "end":
189
- return _context2.stop();
190
- }
97
+ const result = await this.sqlQuery(sqlString);
98
+ if (result.status === 200 && result.data.success) {
99
+ const data = result.data;
100
+ if (!data.results) return [];
101
+ const newResult = [];
102
+ const summaryColumnMethod = getSummaryColumnMethod(method, summaryColumnName);
103
+ const valueKey = isAdvanced ? "".concat(summaryColumnMethod) : "".concat(method, "(").concat(columnName, ")");
104
+ data.results.forEach(item => {
105
+ const currentValue = item[time_column];
106
+ if (currentValue) {
107
+ let value = item[valueKey];
108
+ if (isAdvanced) {
109
+ value = formatNumericValue(value, summaryColumn);
191
110
  }
192
- }, _callee2, this);
193
- }));
194
- function queryDb(_x2) {
195
- return _queryDb.apply(this, arguments);
196
- }
197
- return queryDb;
198
- }()
199
- }, {
200
- key: "convertChart",
201
- value: function convertChart(chart) {
202
- var _id = chart._id,
203
- table_id = chart.table_id,
204
- view_id = chart.view_id,
205
- time_column = chart.time_column,
206
- summary_type = chart.summary_type,
207
- summary_column = chart.summary_column,
208
- summary_method = chart.summary_method;
209
- return {
210
- _id: _id,
211
- table_id: table_id,
212
- view_id: view_id,
213
- x_axis_column_key: time_column,
214
- y_axis_summary_type: summary_type,
215
- y_axis_summary_method: summary_method,
216
- y_axis_column_key: summary_column,
217
- x_axis_date_granularity: 'day'
218
- };
219
- }
220
- }, {
221
- key: "sortDataByYear",
222
- value: function sortDataByYear(data) {
223
- data.sort(function (current, next) {
224
- if (current.year > next.year) {
225
- return -1;
226
- } else if (current.year < next.year) {
227
- return 1;
228
- } else {
229
- return 0;
111
+ const name = typeof currentValue === 'string' ? currentValue : currentValue.country_region;
112
+ newResult.push({
113
+ name: dayjs(name).format('YYYY-MM-DD'),
114
+ value
115
+ });
230
116
  }
231
117
  });
118
+ return newResult;
232
119
  }
233
- }]);
234
- return HeatMapCalculator;
235
- }(BaseCalculator);
120
+ return [];
121
+ }
122
+ convertChart(chart) {
123
+ const {
124
+ _id,
125
+ table_id,
126
+ view_id,
127
+ time_column,
128
+ summary_type,
129
+ summary_column,
130
+ summary_method
131
+ } = chart;
132
+ return {
133
+ _id,
134
+ table_id,
135
+ view_id,
136
+ x_axis_column_key: time_column,
137
+ y_axis_summary_type: summary_type,
138
+ y_axis_summary_method: summary_method,
139
+ y_axis_column_key: summary_column,
140
+ x_axis_date_granularity: 'day'
141
+ };
142
+ }
143
+ sortDataByYear(data) {
144
+ data.sort((current, next) => {
145
+ if (current.year > next.year) {
146
+ return -1;
147
+ } else if (current.year < next.year) {
148
+ return 1;
149
+ } else {
150
+ return 0;
151
+ }
152
+ });
153
+ }
154
+ }
236
155
  export default HeatMapCalculator;