Skip to content

Commit

Permalink
[ML] ExplorationResultsPage.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Apr 22, 2020
1 parent f0bcb3d commit d06310d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const sortColumns = (obj: EsDocSource, resultsField: string) => (a: strin
return a.localeCompare(b);
};

export const sortRegressionResultsFields = (
export const sortExplorationResultsFields = (
a: string,
b: string,
jobConfig: DataFrameAnalyticsConfig
Expand Down Expand Up @@ -298,7 +298,7 @@ export const getDefaultFieldsFromJobCaps = (

allFields.push(...fields, ...featureImportanceFields);
allFields.sort(({ name: a }: { name: string }, { name: b }: { name: string }) =>
sortRegressionResultsFields(a, b, jobConfig)
sortExplorationResultsFields(a, b, jobConfig)
);

let selectedFields = allFields.filter(
Expand Down Expand Up @@ -349,7 +349,7 @@ export const getDefaultClassificationFields = (

return docs.some(row => row._source[k] !== null);
})
.sort((a, b) => sortRegressionResultsFields(a, b, jobConfig))
.sort((a, b) => sortExplorationResultsFields(a, b, jobConfig))
.slice(0, DEFAULT_REGRESSION_COLUMNS);
};

Expand Down Expand Up @@ -382,7 +382,7 @@ export const getDefaultRegressionFields = (

return docs.some(row => row._source[k] !== null);
})
.sort((a, b) => sortRegressionResultsFields(a, b, jobConfig))
.sort((a, b) => sortExplorationResultsFields(a, b, jobConfig))
.slice(0, DEFAULT_REGRESSION_COLUMNS);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { i18n } from '@kbn/i18n';
import { ExplorationPageWrapper } from '../exploration_page_wrapper';

import { EvaluatePanel } from './evaluate_panel';
import { ResultsTable } from './results_table';

interface Props {
jobId: string;
Expand All @@ -29,7 +28,6 @@ export const ClassificationExploration: FC<Props> = ({ jobId }) => {
}
)}
EvaluatePanel={EvaluatePanel}
ResultsTable={ResultsTable}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@ import React, { FC, useState } from 'react';

import { EuiSpacer } from '@elastic/eui';

import { useResultsViewConfig } from '../../../../common';
import { useResultsViewConfig, DataFrameAnalyticsConfig } from '../../../../common';
import { ResultsSearchQuery, defaultSearchQuery } from '../../../../common/analytics';

import { DATA_FRAME_TASK_STATE } from '../../../analytics_management/components/analytics_list/common';

import { ExplorationResultsTable } from '../exploration_results_table';
import { JobConfigErrorCallout } from '../job_config_error_callout';
import { LoadingPanel } from '../loading_panel';

export interface EvaluatePanelProps {
jobConfig: DataFrameAnalyticsConfig;
jobStatus?: DATA_FRAME_TASK_STATE;
searchQuery: ResultsSearchQuery;
}

interface Props {
jobId: string;
title: string;
EvaluatePanel: any;
ResultsTable: any;
EvaluatePanel: FC<EvaluatePanelProps>;
}

export const ExplorationPageWrapper: FC<Props> = ({
jobId,
title,
EvaluatePanel,
ResultsTable,
}) => {
export const ExplorationPageWrapper: FC<Props> = ({ jobId, title, EvaluatePanel }) => {
const {
indexPattern,
isInitialized,
Expand Down Expand Up @@ -60,7 +63,7 @@ export const ExplorationPageWrapper: FC<Props> = ({
jobConfig !== undefined &&
indexPattern !== undefined &&
isInitialized === true && (
<ResultsTable
<ExplorationResultsTable
jobConfig={jobConfig}
indexPattern={indexPattern}
jobStatus={jobStatus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { ExplorationPageWrapper } from './exploration_page_wrapper';
export { EvaluatePanelProps, ExplorationPageWrapper } from './exploration_page_wrapper';
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { DATA_FRAME_TASK_STATE } from '../../../analytics_management/components/
import { ExplorationTitle } from '../exploration_title';
import { ExplorationQueryBar } from '../exploration_query_bar';

import { useClassificationData } from './use_classification_data';
import { useExplorationResults } from './use_exploration_results';

const showingDocs = i18n.translate(
'xpack.ml.dataframe.analytics.classificationExploration.documentsShownHelpText',
Expand All @@ -59,15 +59,15 @@ interface Props {
title: string;
}

export const ResultsTable: FC<Props> = React.memo(
export const ExplorationResultsTable: FC<Props> = React.memo(
({ indexPattern, jobConfig, jobStatus, setEvaluateSearchQuery, title }) => {
const [searchQuery, setSearchQuery] = useState<SavedSearchQuery>(defaultSearchQuery);

useEffect(() => {
setEvaluateSearchQuery(searchQuery);
}, [JSON.stringify(searchQuery)]);

const classificationData = useClassificationData(indexPattern, jobConfig, searchQuery);
const classificationData = useExplorationResults(indexPattern, jobConfig, searchQuery);
const docFieldsCount = classificationData.columns.length;
const { columns, errorMessage, status, tableItems, visibleColumns } = classificationData;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export { ExplorationResultsTable } from './exploration_results_table';
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import {
import { SavedSearchQuery } from '../../../../../contexts/ml';

import { getIndexData, getIndexFields, DataFrameAnalyticsConfig } from '../../../../common';
import { sortRegressionResultsFields } from '../../../../common/fields';
import { sortExplorationResultsFields } from '../../../../common/fields';

const FEATURE_IMPORTANCE = 'feature_importance';

export const useClassificationData = (
export const useExplorationResults = (
indexPattern: IndexPattern | undefined,
jobConfig: DataFrameAnalyticsConfig | undefined,
searchQuery: SavedSearchQuery
Expand All @@ -38,7 +38,7 @@ export const useClassificationData = (
const { fieldTypes } = getIndexFields(jobConfig, needsDestIndexFields);
columns.push(
...getDataGridSchemasFromFieldTypes(fieldTypes, resultsField).sort((a: any, b: any) =>
sortRegressionResultsFields(a.id, b.id, jobConfig)
sortExplorationResultsFields(a.id, b.id, jobConfig)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { i18n } from '@kbn/i18n';
import { ExplorationPageWrapper } from '../exploration_page_wrapper';

import { EvaluatePanel } from './evaluate_panel';
import { ResultsTable } from './results_table';

interface Props {
jobId: string;
Expand All @@ -26,7 +25,6 @@ export const RegressionExploration: FC<Props> = ({ jobId }) => {
values: { jobId },
})}
EvaluatePanel={EvaluatePanel}
ResultsTable={ResultsTable}
/>
);
};

This file was deleted.

Loading

0 comments on commit d06310d

Please sign in to comment.