Skip to content

Commit

Permalink
feat: mega auto view size control
Browse files Browse the repository at this point in the history
  • Loading branch information
ObservedObserver committed Oct 3, 2023
1 parent 236eb9c commit a2e2ad7
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 32 deletions.
4 changes: 4 additions & 0 deletions packages/rath-client/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export interface PreferencePanelConfig {
visMode: 'common' | 'dist';
nlg: boolean;
excludeScaleZero: boolean;
viewSizeLimit: {
dimension: number;
measure: number;
}
}
export interface IDBFieldMeta {
fid: string;
Expand Down
6 changes: 1 addition & 5 deletions packages/rath-client/src/loggers/dataImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ export async function dataBackup (file: File) {
method: 'POST',
credentials: 'include',
body: data
}).then(res => res.json())
.then(res => {
// eslint-disable-next-line no-console
console.log(res)
}).catch(err => {
}).then(res => res.json()).catch(err => {
console.warn(err)
})
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import intl from 'react-intl-universal';
import { Menu, MenuButtonProps, MenuItem, MenuList, MenuPopover, MenuTrigger, SplitButton } from '@fluentui/react-components';
import { Poll24Regular } from '@fluentui/react-icons';
import va from '@vercel/analytics';
import { toJS } from 'mobx';
import { EXPLORE_MODE, PIVOT_KEYS } from '../../../constants';
import { useGlobalStore } from '../../../store';

Expand All @@ -14,7 +15,7 @@ export const useActionModes = function () {
const { exploreMode, taskMode } = commonStore;
const { satisfyAnalysisCondition, fieldMetas } = dataSourceStore;
const startMegaAutoAnalysis = useCallback(() => {
ltsPipeLineStore.startTask(taskMode).then(() => {
ltsPipeLineStore.startTask(taskMode, toJS(megaAutoStore.visualConfig.viewSizeLimit)).then(() => {
megaAutoStore.emitViewChangeTransaction(0);
});
commonStore.setAppKey(PIVOT_KEYS.megaAuto);
Expand Down
4 changes: 2 additions & 2 deletions packages/rath-client/src/pages/megaAutomation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useRef } from 'react';
import { observer } from 'mobx-react-lite';
import styled from 'styled-components';
import intl from 'react-intl-universal';
import { runInAction } from 'mobx';
import { runInAction, toJS } from 'mobx';
import { DefaultButton, PrimaryButton } from '@fluentui/react';
import { useGlobalStore } from '../../store';
import { PIVOT_KEYS } from '../../constants';
Expand Down Expand Up @@ -82,7 +82,7 @@ const LTSPage: React.FC = () => {
// })
// }, [megaAutoStore])
const startTask = useCallback(() => {
ltsPipeLineStore.startTask(taskMode).then(() => {
ltsPipeLineStore.startTask(taskMode, toJS(megaAutoStore.visualConfig.viewSizeLimit)).then(() => {
megaAutoStore.emitViewChangeTransaction(0);
});
commonStore.setAppKey(PIVOT_KEYS.megaAuto);
Expand Down
21 changes: 18 additions & 3 deletions packages/rath-client/src/pages/megaAutomation/preference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import { runInAction } from 'mobx';
import { useGlobalStore } from '../../store';
import { EXPLORE_VIEW_ORDER } from '../../store/megaAutomation';
import { IResizeMode } from '../../interfaces';
import { Label } from '@fluentui/react-components';

const PreferencePanel: React.FC = () => {
const { megaAutoStore } = useGlobalStore();
const { visualConfig, showPreferencePannel, nlgThreshold, vizMode } = megaAutoStore;

const { nlg } = visualConfig;
const { nlg, viewSizeLimit } = visualConfig;

const orderOptions: IDropdownOption[] = Object.values(EXPLORE_VIEW_ORDER).map((or) => ({
text: intl.get(`megaAuto.orderBy.${or}`),
Expand Down Expand Up @@ -52,8 +53,8 @@ const PreferencePanel: React.FC = () => {
runInAction(() => {
megaAutoStore.setShowPreferencePannel(false);
megaAutoStore.refreshMainViewSpec();
})
}, [megaAutoStore])
});
}, [megaAutoStore]);

const onRenderFooterContent = () => (
<div>
Expand All @@ -77,6 +78,20 @@ const PreferencePanel: React.FC = () => {
closeButtonAriaLabel="Close"
onRenderFooterContent={onRenderFooterContent}
>
<Stack.Item>
<Label>Default SpinButton</Label>
<SpinButton
value={viewSizeLimit.measure.toString()}
min={1}
max={20}
step={1}
onChange={(e, v) => {
megaAutoStore.setVisualConig((cnf) => {
cnf.viewSizeLimit.measure = Number(v);
});
}}
/>
</Stack.Item>
<Stack.Item>
<ChoiceGroup
label={intl.get('semiAuto.main.vizsys.title')}
Expand Down
4 changes: 4 additions & 0 deletions packages/rath-client/src/store/megaAutomation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export class MegaAutomationStore {
},
nlg: false,
excludeScaleZero: false,
viewSizeLimit: {
dimension: 2,
measure: 3
}
};
this.globalConstraints = {
dimensions: [],
Expand Down
19 changes: 6 additions & 13 deletions packages/rath-client/src/store/pipeLineStore/lts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeAutoObservable, observable, runInAction } from "mobx";
import { ICubeStorageManageMode, Sampling, IFieldSummary, IInsightSpace } from "visual-insights";

import { IRow, ISyncEngine, ITaskTestMode } from "../../interfaces";
import { IRow, ISyncEngine, ITaskTestMode, PreferencePanelConfig } from "../../interfaces";
import { initRathWorker, rathEngineServerService, rathEngineService, destroyRathWorker } from "../../services/index";
import { IRathStorage } from "../../utils/storage";
import { ClickHouseStore } from "../clickhouseStore";
Expand Down Expand Up @@ -67,7 +67,7 @@ export class LTSPipeLine {
public setCubeStorageManageMode (mode: ICubeStorageManageMode) {
this.cubeStorageManageMode = mode;
}
public async startTask (taskMode: ITaskTestMode = ITaskTestMode.local) {
public async startTask (taskMode: ITaskTestMode = ITaskTestMode.local, limit: PreferencePanelConfig['viewSizeLimit']) {
const { cleanedData, fieldMetas } = this.dataSourceStore;
this.computing = true;
try {
Expand All @@ -80,26 +80,19 @@ export class LTSPipeLine {
dataSource: cleanedData,
cubeStorageManageMode: this.cubeStorageManageMode,
fieldMetas,
viewName: `${this.clickHouseStore.currentDB}.${this.clickHouseStore.currentView}`
viewName: `${this.clickHouseStore.currentDB}.${this.clickHouseStore.currentView}`,
limit
}
})
} else {
await rathEngineService({
task: 'start',
props: {
mode: this.commonStore.computationEngine,
dataSource: cleanedData,
fieldMetas,
viewName: `${this.clickHouseStore.currentDB}.${this.clickHouseStore.currentView}`
}
})
res = await rathEngineServerService({
task: 'start',
dataSource: cleanedData,
fields: fieldMetas,
props: {
mode: this.commonStore.computationEngine,
viewName: `${this.clickHouseStore.currentDB}.${this.clickHouseStore.currentView}`
viewName: `${this.clickHouseStore.currentDB}.${this.clickHouseStore.currentView}`,
limit
}
})
}
Expand Down
19 changes: 15 additions & 4 deletions packages/rath-client/src/workers/engine/core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { getCombination } from '@kanaries/loa';
import { IInsightSpace, InsightFlow, Cube, ViewSpace, } from 'visual-insights'
import { IRow } from '../../interfaces';
import { IRow, PreferencePanelConfig } from '../../interfaces';
import { IVizSpace } from '../../store/megaAutomation';
import { isSetEqual } from '../../utils';
// import { setStateInStorage } from '../../utils/storage';
Expand Down Expand Up @@ -120,6 +120,14 @@ class CustomDataGraph extends DataGraph {
// }
}
export class RathEngine extends VIEngine {
public params: {
limit: PreferencePanelConfig['viewSizeLimit']
} = {
limit: {
dimension: 2,
measure: 3
}
}
public constructor() {
super();
// this.workerCollection.register('clusters', KNNClusterWorker);
Expand Down Expand Up @@ -320,15 +328,15 @@ export class RathEngine extends VIEngine {
// console.log(this.dataGraph.dimensions.map(d => this.fields.find(f => f.key === d)!.name))
const context = this;
const DEFAULT_BIN_NUM = 16;
const { measures: globalMeasures, fieldDictonary } = context
const { measures: globalMeasures, fieldDictonary, params } = context
let ansSpace: IInsightSpace[] = [];
if (context.cube === null) return ansSpace;
const globalCuboid = await context.cube.getCuboid([]);
const globalDist = await globalCuboid.getAggregatedRows(globalMeasures, globalMeasures.map(() => 'dist'));
const pureMeasureViewMeasures: string[][] = [];
for (let measures of context.dataGraph.MClusters) {
if (measures.length > 4) {
pureMeasureViewMeasures.push(...getCombination(measures, 4, 4))
if (measures.length > params.limit.measure) {
pureMeasureViewMeasures.push(...getCombination(measures, params.limit.measure, params.limit.measure))
} else {
pureMeasureViewMeasures.push(measures)
}
Expand Down Expand Up @@ -372,6 +380,9 @@ export class RathEngine extends VIEngine {
// FIXME: throtte
ii % 10 === 0 && setStateInStorage('explore_progress', ii / viewSpaces.length)
const { dimensions, measures } = space;
if (dimensions.length > params.limit.dimension || measures.length > params.limit.measure) {
continue;
}
let dropSpace = false;
const localCuboid = await context.cube.getCuboid(dimensions);
await localCuboid.loadStateInCache();
Expand Down
10 changes: 6 additions & 4 deletions packages/rath-client/src/workers/engine/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ICubeStorageManageMode, IFieldSummary, IInsightSpace, Cube, ViewSpace, StatFuncName } from "visual-insights";

import { IFieldMeta, IRow, ISyncEngine } from "../../interfaces";
import { IFieldMeta, IRow, ISyncEngine, PreferencePanelConfig } from "../../interfaces";
import { IRathStorage } from "../../utils/storage";
import { RathCHEngine } from "./clickhouse";
// import { isSetEqual } from "../../utils/index";
Expand Down Expand Up @@ -37,15 +37,16 @@ function destroyEngine () {
EngineRef.current = null;
}

type StartPipeLineProps = {
type StartPipeLineProps = ({
mode: 'webworker';
cubeStorageManageMode: ICubeStorageManageMode;
dataSource: IRow[];
fieldMetas: IFieldMeta[];
} | {
mode: 'clickhouse';
fieldMetas: IFieldMeta[];
viewName: string;
}) & {
limit: PreferencePanelConfig['viewSizeLimit']
}

async function startPipeLine (props: StartPipeLineProps) {
Expand All @@ -56,10 +57,11 @@ async function startPipeLine (props: StartPipeLineProps) {
let viewFields: IFieldSummary[] = [];
times.push(performance.now())
if (EngineRef.mode === 'webworker' && props.mode === 'webworker') {
const { dataSource, fieldMetas } = props;
const { dataSource, fieldMetas, limit } = props;
const fieldsProps = fieldMetas.map(f => ({ key: f.fid, semanticType: f.semanticType, analyticType: f.analyticType, dataType: '?' as '?' }));
const engine = EngineRef.current;
if (engine === null) throw new Error('Engine is not created.');
engine.params.limit = limit
engine.setData(dataSource)
.setFields(fieldsProps)
engine.univarSelection();
Expand Down

1 comment on commit a2e2ad7

@vercel
Copy link

@vercel vercel bot commented on a2e2ad7 Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.