sea-chart 0.0.81-alpha.1 → 0.0.81-alpha2
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.
|
@@ -1379,4 +1379,15 @@ BaseUtils.getDateGranularityByType = chart => {
|
|
|
1379
1379
|
}
|
|
1380
1380
|
return null;
|
|
1381
1381
|
};
|
|
1382
|
+
BaseUtils.recalculateAvg = sqlRows => {
|
|
1383
|
+
sqlRows.forEach(item => {
|
|
1384
|
+
const avgItemKey = Object.keys(item).find(jtem => jtem.startsWith('AVG'));
|
|
1385
|
+
const sumItemKey = Object.keys(item).find(jtem => jtem.startsWith('SUM'));
|
|
1386
|
+
const countItemKey = Object.keys(item).find(jtem => jtem.startsWith('COUNT'));
|
|
1387
|
+
if (avgItemKey && sumItemKey && countItemKey) {
|
|
1388
|
+
item[avgItemKey] = item[sumItemKey] / item[countItemKey];
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
return sqlRows;
|
|
1392
|
+
};
|
|
1382
1393
|
export default BaseUtils;
|
|
@@ -1439,10 +1439,10 @@ SQLStatisticsUtils.sqlResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMa
|
|
|
1439
1439
|
switch (type) {
|
|
1440
1440
|
case CHART_TYPE.TABLE:
|
|
1441
1441
|
{
|
|
1442
|
+
sqlRows = BaseUtils.recalculateAvg(sqlRows);
|
|
1442
1443
|
const {
|
|
1443
1444
|
column_groupby_column_key
|
|
1444
1445
|
} = chart.config;
|
|
1445
|
-
// TODO
|
|
1446
1446
|
if (!column_groupby_column_key) {
|
|
1447
1447
|
return {
|
|
1448
1448
|
result: _SQLStatisticsUtils.oneDimensionTableSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables)
|
|
@@ -454,7 +454,7 @@ class ChartDataSQL {
|
|
|
454
454
|
}
|
|
455
455
|
return "SELECT ".concat(groupby_column_name, ", ").concat(left_summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
|
|
456
456
|
};
|
|
457
|
-
this._summary_columns_2_sql = (summary_columns, summary_column_key,
|
|
457
|
+
this._summary_columns_2_sql = (summary_columns, summary_column_key, groupby_column, summary_method) => {
|
|
458
458
|
const summary_column = this._get_column_by_key(summary_column_key);
|
|
459
459
|
summary_method = summary_method.toUpperCase();
|
|
460
460
|
let summary_column_names = [];
|
|
@@ -476,7 +476,7 @@ class ChartDataSQL {
|
|
|
476
476
|
});
|
|
477
477
|
|
|
478
478
|
// groupby_column is COLLABORATOR , replace AVG with SUM, and add 'COUNT(*)'
|
|
479
|
-
if (
|
|
479
|
+
if (groupby_column.type === CellType.COLLABORATOR) {
|
|
480
480
|
summary_column_names.forEach((item, index) => {
|
|
481
481
|
if (item.startsWith('AVG')) {
|
|
482
482
|
summary_column_names[index] = 'SUM' + item.slice(3);
|
|
@@ -484,10 +484,13 @@ class ChartDataSQL {
|
|
|
484
484
|
});
|
|
485
485
|
summary_column_names.push('COUNT(*)');
|
|
486
486
|
}
|
|
487
|
+
summary_column_names.forEach((item, index) => {
|
|
488
|
+
if (item.startsWith('AVG')) {
|
|
489
|
+
const group_column_name = this._summary_column_2_sql('ROW_COUNT', groupby_column);
|
|
490
|
+
summary_column_names[index] = item + ',SUM' + item.slice(3) + ",".concat(group_column_name);
|
|
491
|
+
}
|
|
492
|
+
});
|
|
487
493
|
let summary_column_names_str = summary_column_names.join(', ');
|
|
488
|
-
// if (summary_column_names_str) {
|
|
489
|
-
// summary_column_names_str = `, ${summary_column_names_str}`;
|
|
490
|
-
// }
|
|
491
494
|
return summary_column_names_str;
|
|
492
495
|
};
|
|
493
496
|
this._one_dimension_statistic_table_2_sql = () => {
|
|
@@ -519,7 +522,7 @@ class ChartDataSQL {
|
|
|
519
522
|
return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_name, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
|
|
520
523
|
}
|
|
521
524
|
if (summary_columns) {
|
|
522
|
-
const summary_column_names_str = this._summary_columns_2_sql(summary_columns, summary_column_key, groupby_column
|
|
525
|
+
const summary_column_names_str = this._summary_columns_2_sql(summary_columns, summary_column_key, groupby_column, summary_method);
|
|
523
526
|
return "SELECT ".concat(groupby_column_name, ", ").concat(summary_column_names_str, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, " LIMIT 0, 5000");
|
|
524
527
|
}
|
|
525
528
|
summary_method = summary_method.toUpperCase();
|
|
@@ -581,7 +584,7 @@ class ChartDataSQL {
|
|
|
581
584
|
return '';
|
|
582
585
|
}
|
|
583
586
|
summary_method = summary_method.toUpperCase();
|
|
584
|
-
summary_column_names_str = this._summary_columns_2_sql(summary_columns, summary_column_key, groupby_column
|
|
587
|
+
summary_column_names_str = this._summary_columns_2_sql(summary_columns, summary_column_key, groupby_column, summary_method);
|
|
585
588
|
}
|
|
586
589
|
}
|
|
587
590
|
return "SELECT ".concat(groupby_column_name, ", ").concat(column_groupby_column_name, ", ").concat(summary_column_names_str, " FROM ").concat(this.table_name, " ").concat(this.filter_sql, " GROUP BY ").concat(groupby_column_name, ", ").concat(column_groupby_column_name, " LIMIT 0, 5000");
|