Skip to content

Commit

Permalink
[ML] refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Aug 14, 2020
1 parent 5c4dcc4 commit d6123a3
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 139 deletions.
70 changes: 70 additions & 0 deletions x-pack/plugins/ml/common/types/data_frame_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,77 @@
*/

import { CustomHttpResponseOptions, ResponseError } from 'kibana/server';

export interface DeleteDataFrameAnalyticsWithIndexStatus {
success: boolean;
error?: CustomHttpResponseOptions<ResponseError>;
}

export type IndexName = string;
export type DataFrameAnalyticsId = string;

export interface OutlierAnalysis {
[key: string]: {};

outlier_detection: {};
}

interface Regression {
dependent_variable: string;
training_percent?: number;
num_top_feature_importance_values?: number;
prediction_field_name?: string;
}

interface Classification {
dependent_variable: string;
training_percent?: number;
num_top_classes?: string;
num_top_feature_importance_values?: number;
prediction_field_name?: string;
}

export interface RegressionAnalysis {
[key: string]: Regression;

regression: Regression;
}

export interface ClassificationAnalysis {
[key: string]: Classification;

classification: Classification;
}

interface GenericAnalysis {
[key: string]: Record<string, any>;
}

export type AnalysisConfig =
| OutlierAnalysis
| RegressionAnalysis
| ClassificationAnalysis
| GenericAnalysis;

export interface DataFrameAnalyticsConfig {
id: DataFrameAnalyticsId;
description?: string;
dest: {
index: IndexName;
results_field: string;
};
source: {
index: IndexName | IndexName[];
query?: any;
};
analysis: AnalysisConfig;
analyzed_fields: {
includes: string[];
excludes: string[];
};
model_memory_limit: string;
max_num_threads?: number;
create_time: number;
version: string;
allow_lazy_start?: boolean;
}
63 changes: 63 additions & 0 deletions x-pack/plugins/ml/common/types/inference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { DataFrameAnalyticsConfig } from './data_frame_analytics';

export interface IngestStats {
count: number;
time_in_millis: number;
current: number;
failed: number;
}

export interface TrainedModelStat {
model_id: string;
pipeline_count: number;
inference_stats: {
failure_count: number;
inference_count: number;
cache_miss_count: number;
missing_all_fields_count: number;
timestamp: number;
};
ingest: {
total: IngestStats;
pipelines: Record<
string,
IngestStats & {
processors: Array<
Record<
string,
{
// TODO use type from ingest_pipelines plugin
type: string;
stats: IngestStats;
}
>
>;
}
>;
};
}

export interface ModelConfigResponse {
created_by: string;
create_time: string;
default_field_map: Record<string, string>;
estimated_heap_memory_usage_bytes: number;
estimated_operations: number;
license_level: string;
metadata?:
| {
analytics_config: DataFrameAnalyticsConfig;
input: any;
}
| Record<string, any>;
model_id: string;
tags: string;
version: string;
inference_config: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
*/

import { useEffect } from 'react';
import { BehaviorSubject } from 'rxjs';
import { filter, distinctUntilChanged } from 'rxjs/operators';
import { Subscription } from 'rxjs';
import { BehaviorSubject, Subscription } from 'rxjs';
import { distinctUntilChanged, filter } from 'rxjs/operators';
import { cloneDeep } from 'lodash';
import { ml } from '../../services/ml_api_service';
import { Dictionary } from '../../../../common/types/common';
import { getErrorMessage } from '../../../../common/util/errors';
import { SavedSearchQuery } from '../../contexts/ml';
import {
AnalysisConfig,
ClassificationAnalysis,
OutlierAnalysis,
RegressionAnalysis,
} from '../../../../common/types/data_frame_analytics';

export type IndexName = string;
export type IndexPattern = string;
export type DataFrameAnalyticsId = string;

export enum ANALYSIS_CONFIG_TYPE {
OUTLIER_DETECTION = 'outlier_detection',
Expand Down Expand Up @@ -46,34 +49,6 @@ export enum OUTLIER_ANALYSIS_METHOD {
DISTANCE_KNN = 'distance_knn',
}

interface OutlierAnalysis {
[key: string]: {};
outlier_detection: {};
}

interface Regression {
dependent_variable: string;
training_percent?: number;
num_top_feature_importance_values?: number;
prediction_field_name?: string;
}
export interface RegressionAnalysis {
[key: string]: Regression;
regression: Regression;
}

interface Classification {
dependent_variable: string;
training_percent?: number;
num_top_classes?: string;
num_top_feature_importance_values?: number;
prediction_field_name?: string;
}
export interface ClassificationAnalysis {
[key: string]: Classification;
classification: Classification;
}

export interface LoadExploreDataArg {
filterByIsTraining?: boolean;
searchQuery: SavedSearchQuery;
Expand Down Expand Up @@ -165,22 +140,12 @@ export interface ClassificationEvaluateResponse {
};
}

interface GenericAnalysis {
[key: string]: Record<string, any>;
}

interface LoadEvaluateResult {
success: boolean;
eval: RegressionEvaluateResponse | ClassificationEvaluateResponse | null;
error: string | null;
}

type AnalysisConfig =
| OutlierAnalysis
| RegressionAnalysis
| ClassificationAnalysis
| GenericAnalysis;

export const getAnalysisType = (analysis: AnalysisConfig): string => {
const keys = Object.keys(analysis);

Expand Down Expand Up @@ -342,29 +307,6 @@ export interface UpdateDataFrameAnalyticsConfig {
max_num_threads?: number;
}

export interface DataFrameAnalyticsConfig {
id: DataFrameAnalyticsId;
description?: string;
dest: {
index: IndexName;
results_field: string;
};
source: {
index: IndexName | IndexName[];
query?: any;
};
analysis: AnalysisConfig;
analyzed_fields: {
includes: string[];
excludes: string[];
};
model_memory_limit: string;
max_num_threads?: number;
create_time: number;
version: string;
allow_lazy_start?: boolean;
}

export enum REFRESH_ANALYTICS_LIST_STATE {
ERROR = 'error',
IDLE = 'idle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import {
isClassificationAnalysis,
isOutlierAnalysis,
isRegressionAnalysis,
DataFrameAnalyticsConfig,
} from './analytics';
import { Field } from '../../../../common/types/fields';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../../../../../../../src/plugins/data/public';
import { newJobCapsService } from '../../services/new_job_capabilities_service';

import { FEATURE_IMPORTANCE, FEATURE_INFLUENCE, OUTLIER_SCORE, TOP_CLASSES } from './constants';
import { DataFrameAnalyticsConfig } from '../../../../common/types/data_frame_analytics';

export type EsId = string;
export type EsDocSource = Record<string, any>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { ml } from '../../services/ml_api_service';
import { isKeywordAndTextType } from '../common/fields';
import { SavedSearchQuery } from '../../contexts/ml';

import { DataFrameAnalyticsConfig, INDEX_STATUS } from './analytics';
import { INDEX_STATUS } from './analytics';
import { DataFrameAnalyticsConfig } from '../../../../common/types/data_frame_analytics';

export const getIndexData = async (
jobConfig: DataFrameAnalyticsConfig | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ export {
isOutlierAnalysis,
refreshAnalyticsList$,
useRefreshAnalyticsList,
DataFrameAnalyticsId,
DataFrameAnalyticsConfig,
UpdateDataFrameAnalyticsConfig,
IndexName,
IndexPattern,
REFRESH_ANALYTICS_LIST_STATE,
ANALYSIS_CONFIG_TYPE,
Expand Down Expand Up @@ -45,3 +42,6 @@ export { getIndexData } from './get_index_data';
export { getIndexFields } from './get_index_fields';

export { useResultsViewConfig } from './use_results_view_config';
export { DataFrameAnalyticsConfig } from '../../../../common/types/data_frame_analytics';
export { DataFrameAnalyticsId } from '../../../../common/types/data_frame_analytics';
export { IndexName } from '../../../../common/types/data_frame_analytics';
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { useMlContext } from '../../../contexts/ml';
import { newJobCapsService } from '../../../services/new_job_capabilities_service';
import { ml } from '../../../services/ml_api_service';
import { DataFrameAnalyticsId } from '../../common/analytics';
import { useCreateAnalyticsForm } from '../analytics_management/hooks/use_create_analytics_form';
import { CreateAnalyticsAdvancedEditor } from './components/create_analytics_advanced_editor';
import { AdvancedStep, ConfigurationStep, CreateStep, DetailsStep } from './components';
import { DataFrameAnalyticsId } from '../../../../../common/types/data_frame_analytics';

export enum ANALYTICS_STEPS {
CONFIGURATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@ import { EuiBasicTableColumn } from '@elastic/eui/src/components/basic_table/bas
import { EuiTableSelectionType } from '@elastic/eui/src/components/basic_table/table_types';
import { Action } from '@elastic/eui/src/components/basic_table/action_types';
import { StatsBar, ModelsBarStats } from '../../../../../components/stats_bar';
import {
ModelConfigResponse,
ModelStats,
useInferenceApiService,
} from '../../../../../services/ml_api_service/inference';
import { useInferenceApiService } from '../../../../../services/ml_api_service/inference';
import { ModelsTableToConfigMapping } from './index';
import { TIME_FORMAT } from '../../../../../../../common/constants/time_format';
import { DeleteModelsModal } from './delete_models_modal';
import { useMlKibana, useNotifications } from '../../../../../contexts/kibana';
import { ExpandedRow } from './expanded_row';
import { getResultsUrl } from '../analytics_list/common';
import { ModelConfigResponse, TrainedModelStat } from '../../../../../../../common/types/inference';

type Stats = Omit<ModelStats, 'model_id'>;
type Stats = Omit<TrainedModelStat, 'model_id'>;

export type ModelItem = ModelConfigResponse & {
type?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ 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 { CloneDataFrameAnalyticsConfig } from '../../components/action_clone';
import {
DataFrameAnalyticsId,
DataFrameAnalyticsConfig,
ANALYSIS_CONFIG_TYPE,
defaultSearchQuery,
} from '../../../../common/analytics';
import { CloneDataFrameAnalyticsConfig } from '../../components/action_clone';
DataFrameAnalyticsId,
} from '../../../../../../../common/types/data_frame_analytics';

export enum DEFAULT_MODEL_MEMORY_LIMIT {
regression = '100mb',
Expand Down
Loading

0 comments on commit d6123a3

Please sign in to comment.