mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 03:45:59 +00:00
SYNC: Merge pull request #4 from dbgate/feature/charts
This commit is contained in:
23
packages/datalib/src/chartScoring.ts
Normal file
23
packages/datalib/src/chartScoring.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import _sortBy from 'lodash/sortBy';
|
||||
import _sum from 'lodash/sum';
|
||||
import { ChartLimits, ChartYFieldDefinition, ProcessedChart } from './chartDefinitions';
|
||||
|
||||
export function getChartScore(chart: ProcessedChart): number {
|
||||
let res = 0;
|
||||
res += chart.rowsAdded * 5;
|
||||
|
||||
const ydefScores = chart.definition.ydefs.map(yField => getChartYFieldScore(chart, yField));
|
||||
const sorted = _sortBy(ydefScores).reverse();
|
||||
res += _sum(sorted.slice(0, ChartLimits.AUTODETECT_MEASURES_LIMIT));
|
||||
return res;
|
||||
}
|
||||
|
||||
export function getChartYFieldScore(chart: ProcessedChart, yField: ChartYFieldDefinition): number {
|
||||
let res = 0;
|
||||
res += chart.validYRows[yField.field] * 5; // score for valid Y rows
|
||||
res += (chart.topDistinctValues[yField.field]?.size ?? 0) * 20; // score for distinct values in Y field
|
||||
res += chart.rowsAdded * 2; // base score for rows added
|
||||
res -= (chart.invalidYRows[yField.field] ?? 0) * 50; // penalty for invalid Y rows
|
||||
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user