import * as TYPE from 'vega-lite/build/src/type' ; import { QueryConfig } from '../config' ; import { SpecQueryModel } from '../model' ; import { EncodingQuery , isDimension , isEnabledAutoCountQuery , isFieldQuery } from '../query/encoding' ; import { Schema } from '../schema' ; import { some } from '../util' ; import { FeatureScore , RankingScore } from './ranking' ; export const name = 'aggregationQuality' ; export function score ( specM , schema , opt ) { const feature = aggregationQualityFeature ( specM , schema , opt ) ; return { score : feature . score , features : [ feature ] , } ; } function aggregationQualityFeature ( specM , _ , __ ) { const encodings = specM . getEncodings ( ) ; if ( specM . isAggregate ( ) ) { const isRawContinuous = ( encQ ) => { return ( isFieldQuery ( encQ ) && ( ( encQ . type === TYPE . QUANTITATIVE && ! encQ . bin && ! encQ . aggregate ) || ( encQ . type === TYPE . TEMPORAL && ! encQ . timeUnit ) ) ) ; } ; if ( some ( encodings , isRawContinuous ) ) { return { type : name , score : 0.1 , feature : 'Aggregate with raw continuous' , } ; } if ( some ( encodings , ( encQ ) => isFieldQuery ( encQ ) && isDimension ( encQ ) ) ) { const hasCount = some ( encodings , ( encQ ) => { return ( isFieldQuery ( encQ ) && encQ . aggregate === 'count' ) || isEnabledAutoCountQuery ( encQ ) ; } ) ; const hasBin = some ( encodings , ( encQ ) => { return isFieldQuery ( encQ ) && ! ! encQ . bin ; } ) ; if ( hasCount ) { return { type : name , score : 0.8 , feature : 'Aggregate with count' , } ; } else if ( hasBin ) { return { type : name , score : 0.7 , feature : 'Aggregate with bin but without count' , } ; } else { return { type : name , score : 0.9 , feature : 'Aggregate without count and without bin' , } ; } } return { type : name , score : 0.3 , feature : 'Aggregate without dimension' , } ; } else { if ( some ( encodings , ( encQ ) => isFieldQuery ( encQ ) && ! isDimension ( encQ ) ) ) { return { type : name , score : 1 , feature : 'Raw with measure' , } ; } return { type : name , score : 0.2 , feature : 'Raw without measure' , } ; } }