Skip to content

Commit

Permalink
fix(ava/insight): modify parameter definition
Browse files Browse the repository at this point in the history
  • Loading branch information
LAI-X authored and BBSQQ committed Nov 3, 2023
1 parent 5bd88b2 commit 850f8d9
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('extract category-outlier insight', () => {
test('check outliers result', () => {
const result = insightPatternsExtractor({
data,
dimensions: ['type'],
dimensions: [{ fieldName: 'type' }],
measures: [{ fieldName: 'sales', method: 'SUM' }],
insightType: 'category_outlier',
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('extract change-point insight', () => {
test('check change-point result', () => {
const result = insightPatternsExtractor({
data,
dimensions: ['year'],
dimensions: [{ fieldName: 'year' }],
measures: [{ fieldName: 'value', method: 'SUM' }],
insightType: 'change_point',
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('extract low-variance insight', () => {
test('check low-variance result', () => {
const result = insightPatternsExtractor({
data,
dimensions: ['type'],
dimensions: [{ fieldName: 'type' }],
measures: [{ fieldName: 'sales', method: 'SUM' }],
insightType: 'low_variance',
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('extract majority insight', () => {
test('check majority result', () => {
const result = insightPatternsExtractor({
data,
dimensions: ['type'],
dimensions: [{ fieldName: 'type' }],
measures: [{ fieldName: 'sales', method: 'SUM' }],
insightType: 'majority',
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('extract time-series-outlier insight', () => {
test('check outliers result', () => {
const result = insightPatternsExtractor({
data,
dimensions: ['year'],
dimensions: [{ fieldName: 'year' }],
measures: [{ fieldName: 'value', method: 'SUM' }],
insightType: 'time_series_outlier',
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('extract trend insight', () => {
test('check trend result', () => {
const result = insightPatternsExtractor({
data,
dimensions: ['year'],
dimensions: [{ fieldName: 'year' }],
measures: [{ fieldName: 'value', method: 'SUM' }],
insightType: 'trend',
options: {
Expand Down
4 changes: 2 additions & 2 deletions packages/ava/src/insight/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export const SIGNIFICANCE_BENCHMARK = 0.95;

export const SIGNIFICANCE_LEVEL = 0.05;

export const InsightScoreBenchmark = 0.01;
export const INSIGHT_SCORE_BENCHMARK = 0.01;

export const IMPACT_SCORE_WEIGHT = 0.2;

export const InsightDefaultLimit = 20;
export const INSIGHT_DEFAULT_LIMIT = 20;

export const IQR_K = 1.5;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, isString, orderBy } from 'lodash';
import { get, isNil, isString, orderBy } from 'lodash';

import { distinct, mean } from '../../../data';
import { categoryOutlier } from '../../algorithms';
Expand Down Expand Up @@ -76,6 +76,13 @@ export const getCategoryOutlierInfo: GetPatternInfo<CategoryOutlierInfo> = (prop
if (isString(valid))
return getNonSignificantInsight({ detailInfo: valid, insightType, infoType: 'verificationFailure' });
const { dimension, values, measure } = getAlgorithmCommonInput(props);
if (isNil(dimension) || isNil(measure))
return getNonSignificantInsight({
detailInfo: 'Measure or dimension is empty.',
insightType,
infoType: 'verificationFailure',
});

if (distinct(values) === 1)
return getNonSignificantInsight({
insightType,
Expand Down
9 changes: 8 additions & 1 deletion packages/ava/src/insight/insights/extractors/changePoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, isString } from 'lodash';
import { get, isNil, isString } from 'lodash';

import { changePoint } from '../../algorithms';
import { getAlgorithmCommonInput, getNonSignificantInsight, preValidation } from '../util';
Expand Down Expand Up @@ -34,6 +34,13 @@ export const getChangePointInfo: GetPatternInfo<ChangePointInfo> = (props) => {

const { data } = props;
const { dimension, values, measure } = getAlgorithmCommonInput(props);
if (isNil(dimension) || isNil(measure))
return getNonSignificantInsight({
detailInfo: 'Measure or dimension is empty.',
insightType,
infoType: 'verificationFailure',
});

const changePointsParameter = get(props, 'options.algorithmParameter.changePoint');
const changePoints = findChangePoints(values, changePointsParameter);
if (changePoints.length === 0) {
Expand Down
9 changes: 8 additions & 1 deletion packages/ava/src/insight/insights/extractors/lowVariance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, isString } from 'lodash';
import { get, isNil, isString } from 'lodash';

import { coefficientOfVariance, mean } from '../../../data';
import { getAlgorithmCommonInput, getNonSignificantInsight, preValidation } from '../util';
Expand Down Expand Up @@ -36,6 +36,13 @@ export const getLowVarianceInfo: GetPatternInfo<LowVarianceInfo> = (props) => {
if (isString(valid))
return getNonSignificantInsight({ detailInfo: valid, insightType, infoType: 'verificationFailure' });
const { dimension, values, measure } = getAlgorithmCommonInput(props);
if (isNil(dimension) || isNil(measure))
return getNonSignificantInsight({
detailInfo: 'Measure or dimension is empty.',
insightType,
infoType: 'verificationFailure',
});

const lowVarianceParameter = get(props, 'options.algorithmParameter.lowVariance');
const lowVariance = findLowVariance(values, lowVarianceParameter);
if (lowVariance) {
Expand Down
9 changes: 8 additions & 1 deletion packages/ava/src/insight/insights/extractors/majority.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, isString } from 'lodash';
import { get, isNil, isString } from 'lodash';

import { getAlgorithmCommonInput, getNonSignificantInsight, preValidation } from '../util';

Expand Down Expand Up @@ -47,6 +47,13 @@ export const getMajorityInfo: GetPatternInfo<MajorityInfo> = (props) => {
return getNonSignificantInsight({ detailInfo: valid, insightType, infoType: 'verificationFailure' });
const { data } = props;
const { dimension, values, measure } = getAlgorithmCommonInput(props);
if (isNil(dimension) || isNil(measure))
return getNonSignificantInsight({
detailInfo: 'Measure or dimension is empty.',
insightType,
infoType: 'verificationFailure',
});

const majorityParameter = get(props, 'options.algorithmParameter.majority');
const majority = findMajority(values, majorityParameter);
if (majority) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, isString } from 'lodash';
import { get, isNil, isString } from 'lodash';

import { distinct, lowess } from '../../../data';
import { LowessOutput } from '../../../data/statistics/types';
Expand Down Expand Up @@ -41,6 +41,12 @@ export const getTimeSeriesOutlierInfo: GetPatternInfo<TimeSeriesOutlierInfo> = (

const { data } = props;
const { dimension, values, measure } = getAlgorithmCommonInput(props);
if (isNil(dimension) || isNil(measure))
return getNonSignificantInsight({
detailInfo: 'Measure or dimension is empty.',
insightType,
infoType: 'verificationFailure',
});

if (distinct(values) === 1) return getNonSignificantInsight({ insightType, infoType: 'noInsight' });

Expand Down
9 changes: 8 additions & 1 deletion packages/ava/src/insight/insights/extractors/trend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import regression from 'regression';
import { get, isString } from 'lodash';
import { get, isNil, isString } from 'lodash';

import { CommonParameter, GetPatternInfo, TrendInfo } from '../../types';
import { trendDirection } from '../../algorithms';
Expand Down Expand Up @@ -37,6 +37,13 @@ export const getTrendInfo: GetPatternInfo<TrendInfo> = (props) => {
return getNonSignificantInsight({ detailInfo: valid, insightType, infoType: 'verificationFailure' });

const { dimension, values, measure } = getAlgorithmCommonInput(props);
if (isNil(dimension) || isNil(measure))
return getNonSignificantInsight({
detailInfo: 'Measure or dimension is empty.',
insightType,
infoType: 'verificationFailure',
});

const trendParameter = get(props, 'options.algorithmParameter.trend');
const result: TrendResult = findTimeSeriesTrend(values, trendParameter);
return [
Expand Down
6 changes: 3 additions & 3 deletions packages/ava/src/insight/insights/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const getAlgorithmCommonInput = ({
dimensions,
measures,
}: InsightExtractorProps): AlgorithmStandardInput => {
const dimension = dimensions[0];
const measure = measures[0].fieldName;
const dimension = dimensions[0]?.fieldName;
const measure = measures[0]?.fieldName;
const values = data.map((item) => item?.[measure] as number);
return { dimension, measure, values };
};
Expand All @@ -75,7 +75,7 @@ export const preValidation = ({
if (!checker) return true;
const result = checker({
data,
subjectInfo: { dimensions, measures, subspace: [] },
subjectInfo: { dimensions: dimensions?.map((dim) => dim.fieldName), measures, subspace: [] },
fieldPropsMap,
});
return result;
Expand Down
6 changes: 3 additions & 3 deletions packages/ava/src/insight/pipeline/extract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { groupBy, uniq, flatten, isString } from 'lodash';
import Heap from 'heap-js';

import { PATTERN_TYPES, InsightScoreBenchmark, IMPACT_SCORE_WEIGHT } from '../constant';
import { PATTERN_TYPES, INSIGHT_SCORE_BENCHMARK, IMPACT_SCORE_WEIGHT } from '../constant';
import { insightPatternsExtractor, ExtractorCheckers } from '../insights';
import { aggregate } from '../utils/aggregate';
import {
Expand Down Expand Up @@ -83,7 +83,7 @@ function extractPatternsFromSubject(
};
const extractedPatterns = insightPatternsExtractor({
data,
dimensions,
dimensions: dimensions.map((dim) => ({ fieldName: dim })),
measures,
insightType,
options: extractorOptions,
Expand Down Expand Up @@ -209,7 +209,7 @@ export function extractInsightsFromSubspace(
const subspaceImpact = computeSubspaceImpact(data, subspace, impactMeasureReferences, options?.impactMeasures);

// pruning1: check the subpace impact limit
if (subspaceImpact < InsightScoreBenchmark) {
if (subspaceImpact < INSIGHT_SCORE_BENCHMARK) {
return [];
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ava/src/insight/pipeline/insight.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Heap from 'heap-js';

import { InsightDefaultLimit } from '../constant';
import { INSIGHT_DEFAULT_LIMIT } from '../constant';
import { aggregateWithSeries, aggregateWithMeasures } from '../utils/aggregate';

import { enumerateInsights } from './extract';
Expand Down Expand Up @@ -61,7 +61,7 @@ export function extractInsights(sourceData: Datum[], options?: InsightOptions):
// init insights storage
const insightsHeap = new Heap(insightPriorityComparator);
const homogeneousInsightsHeap = new Heap(homogeneousInsightPriorityComparator);
const insightsLimit = options?.limit || InsightDefaultLimit;
const insightsLimit = options?.limit || INSIGHT_DEFAULT_LIMIT;
insightsHeap.limit = insightsLimit;
insightsHeap.init([]);
homogeneousInsightsHeap.init([]);
Expand Down
6 changes: 1 addition & 5 deletions packages/ava/src/insight/pipeline/specificInsight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ export const patternInfo2InsightInfo = (props: PatternInfo2InsightInfoProps) =>
const score = patternInfos[0] ? patternInfos[0].significance * (1 - IMPACT_SCORE_WEIGHT) + IMPACT_SCORE_WEIGHT : 0;
return {
subspace: [],
dimensions: [
{
fieldName: dimensions[0],
},
],
dimensions,
measures,
patterns: patternInfos,
data,
Expand Down
4 changes: 2 additions & 2 deletions packages/ava/src/insight/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export type InsightExtractorOptions = {

export type InsightExtractorProps = {
data: Datum[];
dimensions: string[];
dimensions: Dimension[];
measures: Measure[];
insightType: InsightType;
options?: InsightExtractorOptions;
Expand Down Expand Up @@ -288,7 +288,7 @@ export type InsightsResult = {

export type SpecificInsightProps = {
data: Datum[];
dimensions: string[];
dimensions: Dimension[];
measures: Measure[];
insightType: InsightType;
/** 包括自定义的算法参数,是否进行数据校验等内容 */
Expand Down

0 comments on commit 850f8d9

Please sign in to comment.