dtable-statistic 4.0.2-test-2

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 (210) hide show
  1. package/README.md +3 -0
  2. package/es/api/dtable-db-api.js +43 -0
  3. package/es/assets/css/color-picker.css +53 -0
  4. package/es/assets/css/color-rules-popover.css +144 -0
  5. package/es/assets/css/color-theme-dialog.css +40 -0
  6. package/es/assets/css/dashboard.css +562 -0
  7. package/es/assets/css/dialog.css +415 -0
  8. package/es/assets/css/mobile-dashboard.module.css +91 -0
  9. package/es/assets/css/slider.css +77 -0
  10. package/es/assets/css/statistic-chart.module.css +11 -0
  11. package/es/assets/css/statistic-custom-title.module.css +3 -0
  12. package/es/assets/css/statistic-custom.module.css +4 -0
  13. package/es/assets/css/statistic-numeric-column-item.module.css +43 -0
  14. package/es/assets/css/statistic-time-picker.module.css +21 -0
  15. package/es/assets/css/theme.css +61 -0
  16. package/es/assets/images/icon.png +0 -0
  17. package/es/calculator/base-calculator.js +111 -0
  18. package/es/calculator/basic-chart-calculator.js +571 -0
  19. package/es/calculator/combination-calculator.js +296 -0
  20. package/es/calculator/compare-bar-calculator.js +291 -0
  21. package/es/calculator/completeness-calculator.js +307 -0
  22. package/es/calculator/copy-value.js +47 -0
  23. package/es/calculator/dashboard-calculator.js +146 -0
  24. package/es/calculator/heat-map-calculator.js +225 -0
  25. package/es/calculator/horizontal-bar-calculator.js +100 -0
  26. package/es/calculator/index.js +88 -0
  27. package/es/calculator/map-calculator.js +169 -0
  28. package/es/calculator/mirror-calculator.js +217 -0
  29. package/es/calculator/number-card-calculator.js +135 -0
  30. package/es/calculator/pivot-table-calculator.js +810 -0
  31. package/es/calculator/scatter-calculator.js +150 -0
  32. package/es/calculator/thread-manager.js +70 -0
  33. package/es/calculator/trend-calculator.js +204 -0
  34. package/es/calculator/workers/basic-chart-calculator-worker.js +410 -0
  35. package/es/calculator/workers/calculator.worker.js +22 -0
  36. package/es/calculator/workers/card-calculator-worker.js +28 -0
  37. package/es/calculator/workers/combination-calculator-worker.js +257 -0
  38. package/es/calculator/workers/compare-bar-chart-calculator-worker.js +149 -0
  39. package/es/calculator/workers/completeness-calculator-worker.js +153 -0
  40. package/es/calculator/workers/dashboard-calculator-worker.js +56 -0
  41. package/es/calculator/workers/mirror-calculator-worker.js +132 -0
  42. package/es/calculator/workers/pivot-table-calculator-worker.js +615 -0
  43. package/es/calculator/workers/scatter-calculator-worker.js +67 -0
  44. package/es/calculator/workers/trend-calculator-worker.js +93 -0
  45. package/es/calculator/world-map-calculator.js +193 -0
  46. package/es/components/common-add-tool.js +19 -0
  47. package/es/components/dialog/chart-addition-edit-dialog.js +89 -0
  48. package/es/components/dialog/chart-addition-widgets/chart-selector.js +261 -0
  49. package/es/components/dialog/chart-addition-widgets/statistic-chart-selector.module.css +74 -0
  50. package/es/components/dialog/color-theme-dialog.js +71 -0
  51. package/es/components/dialog/enlarged-chart-dialog.js +73 -0
  52. package/es/components/dialog/new-table-dialog.js +113 -0
  53. package/es/components/dialog/new-view-dialog.js +87 -0
  54. package/es/components/dialog/rename-view-dialog.js +87 -0
  55. package/es/components/dialog/statistic-record-dialog/index.css +114 -0
  56. package/es/components/dialog/statistic-record-dialog/index.js +174 -0
  57. package/es/components/dialog/table-select-dialog.js +93 -0
  58. package/es/components/dropdown-menu/statistic-dropdown-menu.js +94 -0
  59. package/es/components/dtable-popover.js +109 -0
  60. package/es/components/dtable-search-input.js +137 -0
  61. package/es/components/dtable-select.js +104 -0
  62. package/es/components/index.js +11 -0
  63. package/es/components/loading.js +8 -0
  64. package/es/components/modal-portal.js +36 -0
  65. package/es/components/popover/color-rules/color-rule.js +179 -0
  66. package/es/components/popover/color-rules/index.js +87 -0
  67. package/es/components/popover/color-rules/rule-filters/filter.js +214 -0
  68. package/es/components/popover/color-rules/rule-filters/index.css +214 -0
  69. package/es/components/popover/color-rules/rule-filters/index.js +97 -0
  70. package/es/components/popover/color-rules/rule-filters/number-input.js +85 -0
  71. package/es/components/popover/color-rules-popover.js +213 -0
  72. package/es/components/popover/color-selector-popover.js +85 -0
  73. package/es/components/seatable-radio/index.css +51 -0
  74. package/es/components/seatable-radio/index.js +28 -0
  75. package/es/components/select/index.js +2 -0
  76. package/es/components/select/option-group.css +104 -0
  77. package/es/components/select/option-group.js +225 -0
  78. package/es/components/select/option.js +51 -0
  79. package/es/components/select/select.css +211 -0
  80. package/es/components/select/select.js +157 -0
  81. package/es/components/toast/alert.js +130 -0
  82. package/es/components/toast/index.js +3 -0
  83. package/es/components/toast/toast.js +164 -0
  84. package/es/components/toast/toastManager.js +150 -0
  85. package/es/components/toast/toaster.js +64 -0
  86. package/es/constants/color-rules.js +8 -0
  87. package/es/constants/dtable-select-style.js +61 -0
  88. package/es/constants/event-types.js +1 -0
  89. package/es/constants/index.js +501 -0
  90. package/es/constants/key-codes.js +102 -0
  91. package/es/constants/zIndexes.js +1 -0
  92. package/es/custom-g2.js +614 -0
  93. package/es/dashboard.js +408 -0
  94. package/es/desktop-dashboard.js +299 -0
  95. package/es/index.js +33 -0
  96. package/es/locale/index.js +17 -0
  97. package/es/locale/lang/de.js +237 -0
  98. package/es/locale/lang/en.js +237 -0
  99. package/es/locale/lang/fr.js +237 -0
  100. package/es/locale/lang/zh_CN.js +237 -0
  101. package/es/mobile-dashboard.js +103 -0
  102. package/es/model/collaborators.js +11 -0
  103. package/es/model/stat-item.js +340 -0
  104. package/es/model/statistic-dashboard.js +8 -0
  105. package/es/service/chart-service.js +192 -0
  106. package/es/service/dashboard-service.js +415 -0
  107. package/es/stat-editor/chart-name-editor.js +75 -0
  108. package/es/stat-editor/index.js +74 -0
  109. package/es/stat-editor/stat-settings/advance-chart-settings/basic-number-card-settings.js +149 -0
  110. package/es/stat-editor/stat-settings/advance-chart-settings/combination-settings.js +415 -0
  111. package/es/stat-editor/stat-settings/advance-chart-settings/dashboard-chart-settings.js +193 -0
  112. package/es/stat-editor/stat-settings/advance-chart-settings/geo-granularity-settings.js +13 -0
  113. package/es/stat-editor/stat-settings/advance-chart-settings/heat-map-settings.js +107 -0
  114. package/es/stat-editor/stat-settings/advance-chart-settings/index.js +332 -0
  115. package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +170 -0
  116. package/es/stat-editor/stat-settings/advance-chart-settings/mirror-settings.js +141 -0
  117. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/combination-style-setting.js +219 -0
  118. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/heat-map-settings.js +89 -0
  119. package/es/stat-editor/stat-settings/advance-chart-settings/style-setting/map-setting.js +132 -0
  120. package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +319 -0
  121. package/es/stat-editor/stat-settings/advance-chart-settings/trend-chart-settings.js +138 -0
  122. package/es/stat-editor/stat-settings/advance-chart-settings/world-map-settings.js +135 -0
  123. package/es/stat-editor/stat-settings/basic-chart-settings/advance-bar-chart-settings.js +156 -0
  124. package/es/stat-editor/stat-settings/basic-chart-settings/bar-settings.js +147 -0
  125. package/es/stat-editor/stat-settings/basic-chart-settings/completeness-chart-settings.js +195 -0
  126. package/es/stat-editor/stat-settings/basic-chart-settings/custom-bar-settings.js +126 -0
  127. package/es/stat-editor/stat-settings/basic-chart-settings/groupby-settings.js +169 -0
  128. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-axis-group-settings.js +352 -0
  129. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-bar-settings.js +145 -0
  130. package/es/stat-editor/stat-settings/basic-chart-settings/horizontal-group-chart-settings.js +153 -0
  131. package/es/stat-editor/stat-settings/basic-chart-settings/index.js +466 -0
  132. package/es/stat-editor/stat-settings/basic-chart-settings/pie-settings.js +183 -0
  133. package/es/stat-editor/stat-settings/basic-chart-settings/pivot-table-settings.js +542 -0
  134. package/es/stat-editor/stat-settings/basic-chart-settings/scatter-settings.js +111 -0
  135. package/es/stat-editor/stat-settings/basic-chart-settings/stack-item-settings.js +86 -0
  136. package/es/stat-editor/stat-settings/basic-chart-settings/stacks-settings.js +169 -0
  137. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/bar-chart-style-setting.js +273 -0
  138. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/completeness-style.js +105 -0
  139. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +243 -0
  140. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/label-font-size-editor.js +65 -0
  141. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/pie-chart-style-settings.js +318 -0
  142. package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/time-compare-style.js +49 -0
  143. package/es/stat-editor/stat-settings/basic-chart-settings/summary-method-setting.js +124 -0
  144. package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +150 -0
  145. package/es/stat-editor/stat-settings/basic-chart-settings/time-comparison-settings.js +267 -0
  146. package/es/stat-editor/stat-settings/basic-chart-settings/timer-picker.js +109 -0
  147. package/es/stat-editor/stat-settings/basic-chart-settings/y-axis-group-settings.js +351 -0
  148. package/es/stat-editor/stat-settings/color-setting/color-group-selector.js +60 -0
  149. package/es/stat-editor/stat-settings/color-setting/color-picker.js +129 -0
  150. package/es/stat-editor/stat-settings/color-setting/color-use-type-selector.js +348 -0
  151. package/es/stat-editor/stat-settings/public-setting/axis-label-position-setting.js +102 -0
  152. package/es/stat-editor/stat-settings/public-setting/base-settings.js +124 -0
  153. package/es/stat-editor/stat-settings/public-setting/calender.js +124 -0
  154. package/es/stat-editor/stat-settings/public-setting/column-settings.js +15 -0
  155. package/es/stat-editor/stat-settings/public-setting/custom-title-setting.js +60 -0
  156. package/es/stat-editor/stat-settings/public-setting/data-sort-setting.js +57 -0
  157. package/es/stat-editor/stat-settings/public-setting/ind-toggle-setting.js +41 -0
  158. package/es/stat-editor/stat-settings/public-setting/min-max-setting.js +64 -0
  159. package/es/stat-editor/stat-settings/public-setting/numeric-summary-item.js +118 -0
  160. package/es/stat-editor/stat-settings/public-setting/toggle-setting.js +39 -0
  161. package/es/stat-list/chart-preview.js +139 -0
  162. package/es/stat-list/index.js +275 -0
  163. package/es/stat-view/area-chart.js +521 -0
  164. package/es/stat-view/bar-chart.js +568 -0
  165. package/es/stat-view/base-chart.js +44 -0
  166. package/es/stat-view/basic-number-card.js +255 -0
  167. package/es/stat-view/combination-chart.js +558 -0
  168. package/es/stat-view/compare-chart.js +485 -0
  169. package/es/stat-view/completeness-chart.js +389 -0
  170. package/es/stat-view/custom-bar.js +433 -0
  171. package/es/stat-view/dashboard-chart.js +317 -0
  172. package/es/stat-view/heat-map.js +501 -0
  173. package/es/stat-view/horizontal-bar-chart.js +569 -0
  174. package/es/stat-view/index.js +183 -0
  175. package/es/stat-view/line-chart.js +505 -0
  176. package/es/stat-view/map.js +428 -0
  177. package/es/stat-view/mirror.js +285 -0
  178. package/es/stat-view/pie-chart.js +326 -0
  179. package/es/stat-view/pivot-table/index.js +206 -0
  180. package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +133 -0
  181. package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +164 -0
  182. package/es/stat-view/pivot-table/statistic-pivot-table.module.css +132 -0
  183. package/es/stat-view/pivot-table/two-dimension-table.js +344 -0
  184. package/es/stat-view/ring-chart.js +416 -0
  185. package/es/stat-view/scatter-chart.js +367 -0
  186. package/es/stat-view/treemap-chart.js +318 -0
  187. package/es/stat-view/trend-chart.js +299 -0
  188. package/es/stat-view/world-map.js +443 -0
  189. package/es/tabs/index.js +252 -0
  190. package/es/tabs/statistic-tabs.module.css +154 -0
  191. package/es/tabs/tab.js +167 -0
  192. package/es/utils/basic-chart-utils.js +24 -0
  193. package/es/utils/cell-format.js +110 -0
  194. package/es/utils/cell-value.js +27 -0
  195. package/es/utils/collaborator.js +31 -0
  196. package/es/utils/color-utils.js +112 -0
  197. package/es/utils/column-utils.js +18 -0
  198. package/es/utils/column.js +13 -0
  199. package/es/utils/common-utils.js +303 -0
  200. package/es/utils/date-format.js +65 -0
  201. package/es/utils/export-table-utils.js +632 -0
  202. package/es/utils/index.js +26 -0
  203. package/es/utils/object.js +26 -0
  204. package/es/utils/row-utils.js +115 -0
  205. package/es/utils/search.js +67 -0
  206. package/es/utils/sql-utils.js +293 -0
  207. package/es/utils/stat-utils.js +353 -0
  208. package/es/utils/trend-utils.js +136 -0
  209. package/index.js +1 -0
  210. package/package.json +188 -0
@@ -0,0 +1,150 @@
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
+ import { filter2SqlCondition, TableUtils } from 'dtable-store';
8
+ import BaseCalculator from './base-calculator';
9
+ import { getFormattedLabel } from '../utils/row-utils';
10
+ import StatUtils from '../utils/stat-utils';
11
+ import { DATE_GRANULARITY } from '../constants';
12
+ var ScatterCalculator = /*#__PURE__*/function (_BaseCalculator) {
13
+ _inherits(ScatterCalculator, _BaseCalculator);
14
+ var _super = _createSuper(ScatterCalculator);
15
+ function ScatterCalculator(_ref) {
16
+ var value = _ref.value,
17
+ statisticThreadManager = _ref.statisticThreadManager,
18
+ username = _ref.username,
19
+ userId = _ref.userId;
20
+ _classCallCheck(this, ScatterCalculator);
21
+ return _super.call(this, {
22
+ value: value,
23
+ statisticThreadManager: statisticThreadManager,
24
+ username: username,
25
+ userId: userId
26
+ });
27
+ }
28
+ _createClass(ScatterCalculator, [{
29
+ key: "isValidChart",
30
+ value: function isValidChart(chart) {
31
+ if (!this.validateBaseConfigs(chart)) {
32
+ return false;
33
+ }
34
+ var table_id = chart.table_id,
35
+ x_axis_column = chart.x_axis_column,
36
+ y_axis_column = chart.y_axis_column,
37
+ group_column = chart.group_column;
38
+ var table = this.getTableById(table_id);
39
+ if (!TableUtils.getTableColumnByKey(table, x_axis_column) || !TableUtils.getTableColumnByKey(table, y_axis_column) || !TableUtils.getTableColumnByKey(table, group_column)) {
40
+ return false;
41
+ }
42
+ return true;
43
+ }
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", []);
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 _this = this;
88
+ var table_id, view_id, x_axis_column, y_axis_column, group_column, selectedTable, selectedView, selectedXAxisColumn, selectedYAxisColumn, selectedGroupColumn, sqlCondition, sqlString, result, data;
89
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
90
+ while (1) {
91
+ switch (_context2.prev = _context2.next) {
92
+ case 0:
93
+ table_id = chart.table_id, view_id = chart.view_id, x_axis_column = chart.x_axis_column, y_axis_column = chart.y_axis_column, group_column = chart.group_column;
94
+ selectedTable = this.getTableById(table_id);
95
+ selectedView = this.getViewById(view_id, selectedTable);
96
+ selectedXAxisColumn = TableUtils.getTableColumnByKey(selectedTable, x_axis_column);
97
+ selectedYAxisColumn = TableUtils.getTableColumnByKey(selectedTable, y_axis_column);
98
+ selectedGroupColumn = TableUtils.getTableColumnByKey(selectedTable, group_column);
99
+ sqlCondition = filter2SqlCondition(selectedTable, selectedView);
100
+ sqlString = "select `".concat(selectedXAxisColumn.name, "`, `").concat(selectedYAxisColumn.name, "`, `").concat(selectedGroupColumn.name, "` from `").concat(selectedTable.name, "` ").concat(sqlCondition, " limit 5000");
101
+ _context2.next = 10;
102
+ return this.sqlQuery(sqlString);
103
+ case 10:
104
+ result = _context2.sent;
105
+ if (!(result.status === 200 && result.data.success)) {
106
+ _context2.next = 16;
107
+ break;
108
+ }
109
+ data = result.data.results;
110
+ if (data) {
111
+ _context2.next = 15;
112
+ break;
113
+ }
114
+ return _context2.abrupt("return", []);
115
+ case 15:
116
+ return _context2.abrupt("return", data.map(function (item) {
117
+ var name = _this.getColumnValue(item, selectedGroupColumn);
118
+ return {
119
+ x_axis: item[x_axis_column],
120
+ y_axis: item[y_axis_column],
121
+ group_by: name,
122
+ name: name,
123
+ original_name: item[selectedGroupColumn.key]
124
+ };
125
+ }));
126
+ case 16:
127
+ return _context2.abrupt("return", []);
128
+ case 17:
129
+ case "end":
130
+ return _context2.stop();
131
+ }
132
+ }
133
+ }, _callee2, this);
134
+ }));
135
+ function queryDb(_x2) {
136
+ return _queryDb.apply(this, arguments);
137
+ }
138
+ return queryDb;
139
+ }()
140
+ }, {
141
+ key: "getColumnValue",
142
+ value: function getColumnValue(data, column) {
143
+ var tempValue = data[column.key];
144
+ var value = StatUtils.getGroupLabel(tempValue, {}, column, DATE_GRANULARITY.DAY, '', this.value);
145
+ return getFormattedLabel(column, value, this.value.collaborators);
146
+ }
147
+ }]);
148
+ return ScatterCalculator;
149
+ }(BaseCalculator);
150
+ export default ScatterCalculator;
@@ -0,0 +1,70 @@
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
+ var ThreadManager = function ThreadManager(threadCount) {
5
+ var _this = this;
6
+ _classCallCheck(this, ThreadManager);
7
+ this.applyThread = /*#__PURE__*/function () {
8
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(id, workerConstructor) {
9
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
10
+ while (1) {
11
+ switch (_context.prev = _context.next) {
12
+ case 0:
13
+ return _context.abrupt("return", new Promise(function (resolve, reject) {
14
+ if (_this.threadList.length < _this.threadCount) {
15
+ var worker = new workerConstructor();
16
+ worker.id = id;
17
+ _this.threadList.push(worker);
18
+ resolve(worker);
19
+ } else {
20
+ _this.queue.push({
21
+ id: id,
22
+ emitter: resolve,
23
+ workerConstructor: workerConstructor
24
+ });
25
+ }
26
+ }));
27
+ case 1:
28
+ case "end":
29
+ return _context.stop();
30
+ }
31
+ }
32
+ }, _callee);
33
+ }));
34
+ return function (_x, _x2) {
35
+ return _ref.apply(this, arguments);
36
+ };
37
+ }();
38
+ this.removeThread = function (id) {
39
+ var index = _this.threadList.findIndex(function (worker) {
40
+ return worker.id === id;
41
+ });
42
+ if (index > -1) {
43
+ _this.threadList[index] && _this.threadList[index].terminate();
44
+ _this.threadList.splice(index, 1);
45
+ }
46
+ if (_this.queue.length > 0) {
47
+ var _this$queue$shift = _this.queue.shift(),
48
+ _id = _this$queue$shift.id,
49
+ emitter = _this$queue$shift.emitter,
50
+ workerConstructor = _this$queue$shift.workerConstructor;
51
+ var worker = new workerConstructor();
52
+ worker.id = _id;
53
+ _this.threadList.push(worker);
54
+ emitter(worker);
55
+ }
56
+ };
57
+ this.clearQueue = function () {
58
+ _this.queue = [];
59
+ };
60
+ this.terminateWorkers = function () {
61
+ _this.threadList.forEach(function (item) {
62
+ item && item.terminate();
63
+ });
64
+ _this.threadList = [];
65
+ };
66
+ this.threadCount = threadCount;
67
+ this.threadList = [];
68
+ this.queue = [];
69
+ };
70
+ export default ThreadManager;
@@ -0,0 +1,204 @@
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
+ import { filter2SqlCondition, TableUtils } from 'dtable-store';
8
+ import BaseCalculator from './base-calculator';
9
+ import { getSummaryColumnMethod } from '../utils/common-utils';
10
+ import { getSqlGroup } from '../utils/sql-utils';
11
+ import { getCompareDate, summaryDurationResult } from '../utils/trend-utils';
12
+ import { DTABLE_DB_SUMMARY_METHOD, SUMMARY_TYPE } from '../constants';
13
+ var TrendCalculator = /*#__PURE__*/function (_BaseCalculator) {
14
+ _inherits(TrendCalculator, _BaseCalculator);
15
+ var _super = _createSuper(TrendCalculator);
16
+ function TrendCalculator(_ref) {
17
+ var value = _ref.value,
18
+ statisticThreadManager = _ref.statisticThreadManager,
19
+ username = _ref.username,
20
+ userId = _ref.userId;
21
+ _classCallCheck(this, TrendCalculator);
22
+ return _super.call(this, {
23
+ value: value,
24
+ statisticThreadManager: statisticThreadManager,
25
+ username: username,
26
+ userId: userId
27
+ });
28
+ }
29
+ _createClass(TrendCalculator, [{
30
+ key: "isValidChart",
31
+ value: function isValidChart(chart) {
32
+ if (!this.validateBaseConfigs(chart)) {
33
+ return false;
34
+ }
35
+ var table_id = chart.table_id,
36
+ date_column = chart.date_column,
37
+ summary_column = chart.summary_column,
38
+ summary_type = chart.summary_type;
39
+ var table = this.getTableById(table_id);
40
+ if (!TableUtils.getTableColumnByKey(table, date_column)) return false;
41
+ if (summary_type === SUMMARY_TYPE.ADVANCED && !TableUtils.getTableColumnByKey(table, summary_column)) {
42
+ return false;
43
+ }
44
+ return true;
45
+ }
46
+ }, {
47
+ key: "calculate",
48
+ value: function () {
49
+ var _calculate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(chart) {
50
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
51
+ while (1) {
52
+ switch (_context.prev = _context.next) {
53
+ case 0:
54
+ if (this.isValidChart(chart)) {
55
+ _context.next = 2;
56
+ break;
57
+ }
58
+ return _context.abrupt("return", {});
59
+ case 2:
60
+ if (!this.isCalcByQueryDB(chart)) {
61
+ _context.next = 6;
62
+ break;
63
+ }
64
+ _context.next = 5;
65
+ return this.queryDb(chart);
66
+ case 5:
67
+ return _context.abrupt("return", _context.sent);
68
+ case 6:
69
+ _context.next = 8;
70
+ return this.calculateWithWorker(chart);
71
+ case 8:
72
+ return _context.abrupt("return", _context.sent);
73
+ case 9:
74
+ case "end":
75
+ return _context.stop();
76
+ }
77
+ }
78
+ }, _callee, this);
79
+ }));
80
+ function calculate(_x) {
81
+ return _calculate.apply(this, arguments);
82
+ }
83
+ return calculate;
84
+ }()
85
+ }, {
86
+ key: "queryDb",
87
+ value: function () {
88
+ var _queryDb = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chart) {
89
+ var table_id, view_id, date_column, date_granularity, summary_column, summary_type, summary_method, selectedTable, selectedView, selectedColumn, sqlCondition, numericColumn, columnName, dateGroupBy, sqlString, summaryColumnMethod, result, data, results, summaryKey, _summaryColumnMethod, compareValue, comparedValue, _summaryDurationResul, value1, value2, _getCompareDate, compareDate, comparedDate, index, item, currentDate;
90
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
91
+ while (1) {
92
+ switch (_context2.prev = _context2.next) {
93
+ case 0:
94
+ table_id = chart.table_id, view_id = chart.view_id, date_column = chart.date_column, date_granularity = chart.date_granularity, summary_column = chart.summary_column, summary_type = chart.summary_type, summary_method = chart.summary_method;
95
+ selectedTable = this.getTableById(table_id);
96
+ selectedView = this.getViewById(view_id, selectedTable);
97
+ selectedColumn = TableUtils.getTableColumnByKey(selectedTable, date_column);
98
+ if (selectedColumn) {
99
+ _context2.next = 6;
100
+ break;
101
+ }
102
+ return _context2.abrupt("return", {});
103
+ case 6:
104
+ sqlCondition = filter2SqlCondition(selectedTable, selectedView);
105
+ numericColumn = TableUtils.getTableColumnByKey(selectedTable, summary_column);
106
+ columnName = selectedColumn.name;
107
+ dateGroupBy = getSqlGroup(date_granularity, selectedColumn);
108
+ sqlString = '';
109
+ if (summary_type === SUMMARY_TYPE.COUNT) {
110
+ sqlString = "select ".concat(dateGroupBy, ", ").concat(DTABLE_DB_SUMMARY_METHOD.Row_count, "(").concat(columnName, ") from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(dateGroupBy, " order by ").concat(dateGroupBy, " limit 5000");
111
+ } else {
112
+ summaryColumnMethod = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[summary_method], numericColumn.name);
113
+ sqlString = "select ".concat(dateGroupBy, ", ").concat(summaryColumnMethod, " from `").concat(selectedTable.name, "` ").concat(sqlCondition, " group by ").concat(dateGroupBy, " order by ").concat(dateGroupBy, " limit 5000");
114
+ }
115
+ _context2.next = 14;
116
+ return this.sqlQuery(sqlString);
117
+ case 14:
118
+ result = _context2.sent;
119
+ if (!(result.status === 200 && result.data.success)) {
120
+ _context2.next = 45;
121
+ break;
122
+ }
123
+ data = result.data;
124
+ if (data.results) {
125
+ _context2.next = 19;
126
+ break;
127
+ }
128
+ return _context2.abrupt("return", {});
129
+ case 19:
130
+ results = data.results;
131
+ summaryKey = "".concat(DTABLE_DB_SUMMARY_METHOD.Row_count, "(").concat(columnName, ")");
132
+ if (summary_type === SUMMARY_TYPE.ADVANCED) {
133
+ _summaryColumnMethod = getSummaryColumnMethod(DTABLE_DB_SUMMARY_METHOD[summary_method], numericColumn.name);
134
+ summaryKey = _summaryColumnMethod;
135
+ }
136
+ if (!(date_granularity === 'days_30' || date_granularity === 'days_7')) {
137
+ _context2.next = 28;
138
+ break;
139
+ }
140
+ _summaryDurationResul = summaryDurationResult(results, date_granularity, summary_type, summary_method, true, dateGroupBy, summaryKey), value1 = _summaryDurationResul.compareValue, value2 = _summaryDurationResul.comparedValue;
141
+ compareValue = value1;
142
+ comparedValue = value2;
143
+ _context2.next = 44;
144
+ break;
145
+ case 28:
146
+ _getCompareDate = getCompareDate(date_granularity), compareDate = _getCompareDate.compareDate, comparedDate = _getCompareDate.comparedDate;
147
+ index = results.length - 1;
148
+ case 30:
149
+ if (!(index >= 0)) {
150
+ _context2.next = 44;
151
+ break;
152
+ }
153
+ item = results[index];
154
+ if (item[dateGroupBy]) {
155
+ _context2.next = 34;
156
+ break;
157
+ }
158
+ return _context2.abrupt("continue", 41);
159
+ case 34:
160
+ currentDate = item[dateGroupBy] + '';
161
+ if (!(currentDate && currentDate < comparedDate)) {
162
+ _context2.next = 37;
163
+ break;
164
+ }
165
+ return _context2.abrupt("break", 44);
166
+ case 37:
167
+ if (currentDate === compareDate) {
168
+ compareValue = item[summaryKey];
169
+ }
170
+ if (!(currentDate === comparedDate)) {
171
+ _context2.next = 41;
172
+ break;
173
+ }
174
+ comparedValue = item[summaryKey];
175
+ return _context2.abrupt("break", 44);
176
+ case 41:
177
+ index--;
178
+ _context2.next = 30;
179
+ break;
180
+ case 44:
181
+ return _context2.abrupt("return", {
182
+ latest: compareValue,
183
+ previous: comparedValue,
184
+ result: Math.abs(compareValue - comparedValue) / comparedValue,
185
+ type: compareValue > comparedValue ? 'up' : 'down'
186
+ });
187
+ case 45:
188
+ return _context2.abrupt("return", {});
189
+ case 46:
190
+ case "end":
191
+ return _context2.stop();
192
+ }
193
+ }
194
+ }, _callee2, this);
195
+ }));
196
+ function queryDb(_x2) {
197
+ return _queryDb.apply(this, arguments);
198
+ }
199
+ return queryDb;
200
+ }()
201
+ }]);
202
+ return TrendCalculator;
203
+ }(BaseCalculator);
204
+ export default TrendCalculator;