Skip to content

Commit

Permalink
[ML] Refactor ANALYSIS_CONFIG_TYPE from enum -> const
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Sep 9, 2020
1 parent 9272d37 commit dd3517b
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ import { SavedSearchQuery } from '../../contexts/ml';
import {
AnalysisConfig,
ClassificationAnalysis,
DataFrameAnalyticsType,
OutlierAnalysis,
RegressionAnalysis,
} from '../../../../common/types/data_frame_analytics';

import { ANALYSIS_CONFIG_TYPE } from '../../../../common/constants/data_frame_analytics';
export type IndexPattern = string;

export enum ANALYSIS_CONFIG_TYPE {
OUTLIER_DETECTION = 'outlier_detection',
REGRESSION = 'regression',
CLASSIFICATION = 'classification',
}

export enum ANALYSIS_ADVANCED_FIELDS {
ETA = 'eta',
FEATURE_BAG_FRACTION = 'feature_bag_fraction',
Expand Down Expand Up @@ -492,7 +487,7 @@ interface LoadEvalDataConfig {
predictionFieldName?: string;
searchQuery?: ResultsSearchQuery;
ignoreDefaultQuery?: boolean;
jobType: ANALYSIS_CONFIG_TYPE;
jobType: DataFrameAnalyticsType;
requiresKeyword?: boolean;
}

Expand Down Expand Up @@ -607,3 +602,5 @@ export const loadDocsCount = async ({
};
}
};

export { ANALYSIS_CONFIG_TYPE };
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export {
UpdateDataFrameAnalyticsConfig,
IndexPattern,
REFRESH_ANALYTICS_LIST_STATE,
ANALYSIS_CONFIG_TYPE,
OUTLIER_ANALYSIS_METHOD,
RegressionEvaluateResponse,
getValuesFromResponse,
Expand All @@ -26,6 +25,7 @@ export {
SEARCH_SIZE,
defaultSearchQuery,
SearchQuery,
ANALYSIS_CONFIG_TYPE,
} from './analytics';

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { Fragment, FC } from 'react';
import { i18n } from '@kbn/i18n';

import { EuiFormRow, EuiSelect } from '@elastic/eui';
import { ANALYSIS_CONFIG_TYPE } from '../../../../common';
import { ANALYSIS_CONFIG_TYPE } from '../../../../../../../common/constants/data_frame_analytics';

import { AnalyticsJobType } from '../../../analytics_management/hooks/use_create_analytics_form/state';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { BASIC_NUMERICAL_TYPES, EXTENDED_NUMERICAL_TYPES } from '../../../../com
import { CATEGORICAL_TYPES } from './form_options_validation';
import { ES_FIELD_TYPES } from '../../../../../../../../../../src/plugins/data/public';
import { newJobCapsService } from '../../../../../services/new_job_capabilities_service';
import { DataFrameAnalyticsType } from '../../../../../../../common/types/data_frame_analytics';

const containsClassificationFieldsCb = ({ name, type }: Field) =>
!OMIT_FIELDS.includes(name) &&
Expand All @@ -32,13 +33,13 @@ const containsRegressionFieldsCb = ({ name, type }: Field) =>
const containsOutlierFieldsCb = ({ name, type }: Field) =>
!OMIT_FIELDS.includes(name) && name !== EVENT_RATE_FIELD_ID && BASIC_NUMERICAL_TYPES.has(type);

const callbacks: Record<ANALYSIS_CONFIG_TYPE, (f: Field) => boolean> = {
const callbacks: Record<DataFrameAnalyticsType, (f: Field) => boolean> = {
[ANALYSIS_CONFIG_TYPE.CLASSIFICATION]: containsClassificationFieldsCb,
[ANALYSIS_CONFIG_TYPE.REGRESSION]: containsRegressionFieldsCb,
[ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION]: containsOutlierFieldsCb,
};

const messages: Record<ANALYSIS_CONFIG_TYPE, JSX.Element> = {
const messages: Record<DataFrameAnalyticsType, JSX.Element> = {
[ANALYSIS_CONFIG_TYPE.CLASSIFICATION]: (
<FormattedMessage
id="xpack.ml.dataframe.analytics.create.sourceObjectClassificationHelpText"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { ml } from '../../../../../services/ml_api_service';
import { BackToListPanel } from '../back_to_list_panel';
import { ViewResultsPanel } from '../view_results_panel';
import { ProgressStats } from './progress_stats';
import { ANALYSIS_CONFIG_TYPE } from '../../../../common/analytics';
import { DataFrameAnalyticsType } from '../../../../../../../common/types/data_frame_analytics';

export const PROGRESS_REFRESH_INTERVAL_MS = 1000;

interface Props {
jobId: string;
jobType: ANALYSIS_CONFIG_TYPE;
jobType: DataFrameAnalyticsType;
showProgress: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import React, { FC, Fragment } from 'react';
import { EuiCard, EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useMlUrlGenerator } from '../../../../../contexts/kibana';
import { ANALYSIS_CONFIG_TYPE } from '../../../../common/analytics';
import { ML_PAGES } from '../../../../../../../common/constants/ml_url_generator';
import { useNavigateToPath } from '../../../../../contexts/kibana';
import { DataFrameAnalyticsType } from '../../../../../../../common/types/data_frame_analytics';
interface Props {
jobId: string;
analysisType: ANALYSIS_CONFIG_TYPE;
analysisType: DataFrameAnalyticsType;
}

export const ViewResultsPanel: FC<Props> = ({ jobId, analysisType }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import { OutlierExploration } from './components/outlier_exploration';
import { RegressionExploration } from './components/regression_exploration';
import { ClassificationExploration } from './components/classification_exploration';

import { ANALYSIS_CONFIG_TYPE } from '../../common/analytics';
import { ANALYSIS_CONFIG_TYPE } from '../../../../../common/constants/data_frame_analytics';
import { DataFrameAnalyticsType } from '../../../../../common/types/data_frame_analytics';

export const Page: FC<{
jobId: string;
analysisType: ANALYSIS_CONFIG_TYPE;
analysisType: DataFrameAnalyticsType;
}> = ({ jobId, analysisType }) => (
<Fragment>
<NavigationMenu tabId="data_frame_analytics" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ import {
EuiSearchBarProps,
EuiSpacer,
} from '@elastic/eui';

import {
DataFrameAnalyticsId,
useRefreshAnalyticsList,
ANALYSIS_CONFIG_TYPE,
} from '../../../../common';
import { ANALYSIS_CONFIG_TYPE } from '../../../../../../../common/constants/data_frame_analytics';
import { DataFrameAnalyticsId, useRefreshAnalyticsList } from '../../../../common';
import { checkPermission } from '../../../../../capabilities/check_capabilities';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import { EuiTableActionsColumnType, Query, Ast } from '@elastic/eui';
import { DATA_FRAME_TASK_STATE } from './data_frame_task_state';
export { DATA_FRAME_TASK_STATE };

import {
DataFrameAnalyticsId,
DataFrameAnalyticsConfig,
ANALYSIS_CONFIG_TYPE,
} from '../../../../common';
import { DataFrameAnalyticsId, DataFrameAnalyticsConfig } from '../../../../common';
import { DataFrameAnalyticsType } from '../../../../../../../common/types/data_frame_analytics';

export enum DATA_FRAME_MODE {
BATCH = 'batch',
Expand Down Expand Up @@ -111,10 +108,7 @@ export interface DataFrameAnalyticsListRow {
checkpointing: object;
config: DataFrameAnalyticsConfig;
id: DataFrameAnalyticsId;
job_type:
| ANALYSIS_CONFIG_TYPE.CLASSIFICATION
| ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION
| ANALYSIS_CONFIG_TYPE.REGRESSION;
job_type: DataFrameAnalyticsType;
mode: string;
state: DataFrameAnalyticsStats['state'];
stats: DataFrameAnalyticsStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import {
JOB_ID_MAX_LENGTH,
ALLOWED_DATA_UNITS,
} from '../../../../../../../common/constants/validation';
import { ANALYSIS_CONFIG_TYPE } from '../../../../../../../common/constants/data_frame_analytics';
import {
getDependentVar,
getNumTopFeatureImportanceValues,
getTrainingPercent,
isRegressionAnalysis,
isClassificationAnalysis,
ANALYSIS_CONFIG_TYPE,
NUM_TOP_FEATURE_IMPORTANCE_VALUES_MIN,
TRAINING_PERCENT_MIN,
TRAINING_PERCENT_MAX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { DeepPartial, DeepReadonly } from '../../../../../../../common/types/com
import { checkPermission } from '../../../../../capabilities/check_capabilities';
import { mlNodesAvailable } from '../../../../../ml_nodes_check';

import { ANALYSIS_CONFIG_TYPE, defaultSearchQuery } from '../../../../common/analytics';
import { defaultSearchQuery } from '../../../../common/analytics';
import { CloneDataFrameAnalyticsConfig } from '../../components/action_clone';
import {
DataFrameAnalyticsConfig,
DataFrameAnalyticsId,
DataFrameAnalyticsType,
} from '../../../../../../../common/types/data_frame_analytics';

import { ANALYSIS_CONFIG_TYPE } from '../../../../../../../common/constants/data_frame_analytics';
export enum DEFAULT_MODEL_MEMORY_LIMIT {
regression = '100mb',
outlier_detection = '50mb',
Expand All @@ -28,7 +29,7 @@ export const UNSET_CONFIG_ITEM = '--';
export type EsIndexName = string;
export type DependentVariable = string;
export type IndexPatternTitle = string;
export type AnalyticsJobType = ANALYSIS_CONFIG_TYPE | undefined;
export type AnalyticsJobType = DataFrameAnalyticsType | undefined;
type IndexPatternId = string;
export type SourceIndexMap = Record<
IndexPatternTitle,
Expand Down Expand Up @@ -290,7 +291,7 @@ export function getFormStateFromJobConfig(
analyticsJobConfig: Readonly<CloneDataFrameAnalyticsConfig>,
isClone: boolean = true
): Partial<State['form']> {
const jobType = Object.keys(analyticsJobConfig.analysis)[0] as ANALYSIS_CONFIG_TYPE;
const jobType = Object.keys(analyticsJobConfig.analysis)[0] as DataFrameAnalyticsType;

const resultState: Partial<State['form']> = {
jobType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import {
GetDataFrameAnalyticsStatsResponseError,
GetDataFrameAnalyticsStatsResponseOk,
} from '../../../../../services/ml_api_service/data_frame_analytics';
import {
ANALYSIS_CONFIG_TYPE,
REFRESH_ANALYTICS_LIST_STATE,
refreshAnalyticsList$,
} from '../../../../common';
import { REFRESH_ANALYTICS_LIST_STATE, refreshAnalyticsList$ } from '../../../../common';

import {
DATA_FRAME_MODE,
Expand All @@ -25,6 +21,7 @@ import {
isDataFrameAnalyticsStopped,
} from '../../components/analytics_list/common';
import { AnalyticStatsBarStats } from '../../../../../components/stats_bar';
import { DataFrameAnalyticsType } from '../../../../../../../common/types/data_frame_analytics';

export const isGetDataFrameAnalyticsStatsResponseOk = (
arg: any
Expand Down Expand Up @@ -143,7 +140,7 @@ export const getAnalyticsFactory = (
checkpointing: {},
config,
id: config.id,
job_type: Object.keys(config.analysis)[0] as ANALYSIS_CONFIG_TYPE,
job_type: Object.keys(config.analysis)[0] as DataFrameAnalyticsType,
mode: DATA_FRAME_MODE.BATCH,
state: stats.state,
stats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { MlRoute, PageLoader, PageProps } from '../../router';
import { useResolver } from '../../use_resolver';
import { basicResolvers } from '../../resolvers';
import { Page } from '../../../data_frame_analytics/pages/analytics_exploration';
import { ANALYSIS_CONFIG_TYPE } from '../../../data_frame_analytics/common/analytics';
import { getBreadcrumbWithUrlForApp } from '../../breadcrumbs';
import { ML_PAGES } from '../../../../../common/constants/ml_url_generator';
import { DataFrameAnalyticsType } from '../../../../../common/types/data_frame_analytics';

export const analyticsJobExplorationRouteFactory = (navigateToPath: NavigateToPath): MlRoute => ({
path: '/data_frame_analytics/exploration',
Expand Down Expand Up @@ -63,7 +63,7 @@ const PageWrapper: FC<PageProps> = ({ location, deps }) => {
return <></>;
}
const jobId: string = globalState.ml.jobId;
const analysisType: ANALYSIS_CONFIG_TYPE = globalState.ml.analysisType;
const analysisType: DataFrameAnalyticsType = globalState.ml.analysisType;

return (
<PageLoader context={context}>
Expand Down

0 comments on commit dd3517b

Please sign in to comment.