SYNC: autodetect - with grouping field

This commit is contained in:
Jan Prochazka
2025-07-02 10:22:41 +02:00
committed by Diflow
parent 794dd5a797
commit cd3a1bebff
5 changed files with 93 additions and 70 deletions

View File

@@ -3,12 +3,23 @@ import _sum from 'lodash/sum';
import { ChartLimits, ChartYFieldDefinition, ProcessedChart } from './chartDefinitions';
export function getChartScore(chart: ProcessedChart): number {
if (chart.errorMessage) {
return -1; // negative score for charts with errors
}
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));
if (chart.groupSet?.size >= 2 && chart.groupSet?.size <= 6) {
res += 50; // bonus for nice grouping
}
if (chart.groupSet?.size == 1) {
res -= 20; // penalty for single group
}
return res;
}