Skip to content

Commit f18c571

Browse files
[ML] Listing all categorization wizard checks (#60502)
* [ML] Listing all categorization wizard checks * fixing translation * changes based on review * moving check * adding real values to messages * reordering checks enum * fixing types * updating tests * updating id
1 parent 2c25520 commit f18c571

File tree

17 files changed

+167
-48
lines changed

17 files changed

+167
-48
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { i18n } from '@kbn/i18n';
8+
import { VALIDATION_RESULT } from '../types/categories';
9+
10+
export const NUMBER_OF_CATEGORY_EXAMPLES = 5;
11+
export const CATEGORY_EXAMPLES_SAMPLE_SIZE = 1000;
12+
export const CATEGORY_EXAMPLES_WARNING_LIMIT = 0.75;
13+
export const CATEGORY_EXAMPLES_ERROR_LIMIT = 0.02;
14+
15+
export const VALID_TOKEN_COUNT = 3;
16+
export const MEDIAN_LINE_LENGTH_LIMIT = 400;
17+
export const NULL_COUNT_PERCENT_LIMIT = 0.75;
18+
19+
export enum CATEGORY_EXAMPLES_VALIDATION_STATUS {
20+
VALID = 'valid',
21+
PARTIALLY_VALID = 'partially_valid',
22+
INVALID = 'invalid',
23+
}
24+
25+
export const VALIDATION_CHECK_DESCRIPTION = {
26+
[VALIDATION_RESULT.NO_EXAMPLES]: i18n.translate(
27+
'xpack.ml.models.jobService.categorization.messages.validNoDataFound',
28+
{
29+
defaultMessage: 'Examples were successfully loaded.',
30+
}
31+
),
32+
[VALIDATION_RESULT.FAILED_TO_TOKENIZE]: i18n.translate(
33+
'xpack.ml.models.jobService.categorization.messages.validFailureToGetTokens',
34+
{
35+
defaultMessage: 'The examples loaded were tokenized successfully.',
36+
}
37+
),
38+
[VALIDATION_RESULT.TOKEN_COUNT]: i18n.translate(
39+
'xpack.ml.models.jobService.categorization.messages.validTokenLength',
40+
{
41+
defaultMessage:
42+
'More than {tokenCount} tokens per example were found in over {percentage}% of the examples loaded.',
43+
values: {
44+
percentage: Math.floor(CATEGORY_EXAMPLES_WARNING_LIMIT * 100),
45+
tokenCount: VALID_TOKEN_COUNT,
46+
},
47+
}
48+
),
49+
[VALIDATION_RESULT.MEDIAN_LINE_LENGTH]: i18n.translate(
50+
'xpack.ml.models.jobService.categorization.messages.validMedianLineLength',
51+
{
52+
defaultMessage:
53+
'The median line length of the examples loaded was less than {medianCharCount} characters.',
54+
values: {
55+
medianCharCount: MEDIAN_LINE_LENGTH_LIMIT,
56+
},
57+
}
58+
),
59+
[VALIDATION_RESULT.NULL_VALUES]: i18n.translate(
60+
'xpack.ml.models.jobService.categorization.messages.validNullValues',
61+
{
62+
defaultMessage: 'Less than {percentage}% of the examples loaded were null.',
63+
values: {
64+
percentage: Math.floor(100 - NULL_COUNT_PERCENT_LIMIT * 100),
65+
},
66+
}
67+
),
68+
[VALIDATION_RESULT.TOO_MANY_TOKENS]: i18n.translate(
69+
'xpack.ml.models.jobService.categorization.messages.validTooManyTokens',
70+
{
71+
defaultMessage: 'Less than 10000 tokens were found in total in the examples loaded.',
72+
}
73+
),
74+
[VALIDATION_RESULT.INSUFFICIENT_PRIVILEGES]: i18n.translate(
75+
'xpack.ml.models.jobService.categorization.messages.validUserPrivileges',
76+
{
77+
defaultMessage: 'The user has sufficient privileges to perform the checks.',
78+
}
79+
),
80+
};

x-pack/plugins/ml/common/constants/new_job.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,3 @@ export const DEFAULT_RARE_BUCKET_SPAN = '1h';
2525
export const DEFAULT_QUERY_DELAY = '60s';
2626

2727
export const SHARED_RESULTS_INDEX_NAME = 'shared';
28-
29-
// Categorization
30-
export const NUMBER_OF_CATEGORY_EXAMPLES = 5;
31-
export const CATEGORY_EXAMPLES_SAMPLE_SIZE = 1000;
32-
export const CATEGORY_EXAMPLES_WARNING_LIMIT = 0.75;
33-
export const CATEGORY_EXAMPLES_ERROR_LIMIT = 0.02;
34-
35-
export enum CATEGORY_EXAMPLES_VALIDATION_STATUS {
36-
VALID = 'valid',
37-
PARTIALLY_VALID = 'partially_valid',
38-
INVALID = 'invalid',
39-
}

x-pack/plugins/ml/common/types/categories.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '../constants/new_job';
7+
import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '../constants/categorization_job';
88

99
export type CategoryId = number;
1010

@@ -39,12 +39,12 @@ export interface CategoryFieldExample {
3939
}
4040

4141
export enum VALIDATION_RESULT {
42+
NO_EXAMPLES,
43+
FAILED_TO_TOKENIZE,
44+
TOO_MANY_TOKENS,
4245
TOKEN_COUNT,
4346
MEDIAN_LINE_LENGTH,
4447
NULL_VALUES,
45-
NO_EXAMPLES,
46-
TOO_MANY_TOKENS,
47-
FAILED_TO_TOKENIZE,
4848
INSUFFICIENT_PRIVILEGES,
4949
}
5050

x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/categorization_job_creator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
CREATED_BY_LABEL,
1717
DEFAULT_BUCKET_SPAN,
1818
DEFAULT_RARE_BUCKET_SPAN,
19-
CATEGORY_EXAMPLES_VALIDATION_STATUS,
2019
} from '../../../../../../common/constants/new_job';
20+
import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '../../../../../../common/constants/categorization_job';
2121
import { ML_JOB_AGGREGATION } from '../../../../../../common/constants/aggregation_types';
2222
import {
2323
CategorizationAnalyzer,

x-pack/plugins/ml/public/application/jobs/new_job/common/job_validator/job_validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { JobCreator, JobCreatorType, isCategorizationJobCreator } from '../job_c
1616
import { populateValidationMessages, checkForExistingJobAndGroupIds } from './util';
1717
import { ExistingJobsAndGroups } from '../../../../services/job_service';
1818
import { cardinalityValidator, CardinalityValidatorResult } from './validators';
19-
import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '../../../../../../common/constants/new_job';
19+
import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '../../../../../../common/constants/categorization_job';
2020

2121
// delay start of validation to allow the user to make changes
2222
// e.g. if they are typing in a new value, try not to validate

x-pack/plugins/ml/public/application/jobs/new_job/common/results_loader/categorization_examples_loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ml } from '../../../../services/ml_api_service';
1111
import {
1212
NUMBER_OF_CATEGORY_EXAMPLES,
1313
CATEGORY_EXAMPLES_VALIDATION_STATUS,
14-
} from '../../../../../../common/constants/new_job';
14+
} from '../../../../../../common/constants/categorization_job';
1515

1616
export class CategorizationExamplesLoader {
1717
private _jobCreator: CategorizationJobCreator;

x-pack/plugins/ml/public/application/jobs/new_job/pages/components/job_details_step/components/additional_section/additional_section.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
*/
66

77
import React, { FC, Fragment } from 'react';
8+
import { i18n } from '@kbn/i18n';
89
import { EuiAccordion, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
910
import { CalendarsSelection } from './components/calendars';
1011
import { CustomUrlsSelection } from './components/custom_urls';
1112

12-
const ButtonContent = <Fragment>Additional settings</Fragment>;
13+
const buttonContent = i18n.translate(
14+
'xpack.ml.newJob.wizard.jobDetailsStep.additionalSectionButton',
15+
{
16+
defaultMessage: 'Additional settings',
17+
}
18+
);
1319

1420
interface Props {
1521
additionalExpanded: boolean;
@@ -22,7 +28,7 @@ export const AdditionalSection: FC<Props> = ({ additionalExpanded, setAdditional
2228
<EuiSpacer />
2329
<EuiAccordion
2430
id="advanced-section"
25-
buttonContent={ButtonContent}
31+
buttonContent={buttonContent}
2632
onToggle={setAdditionalExpanded}
2733
initialIsOpen={additionalExpanded}
2834
data-test-subj="mlJobWizardToggleAdditionalSettingsSection"

x-pack/plugins/ml/public/application/jobs/new_job/pages/components/job_details_step/components/advanced_section/advanced_section.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ModelMemoryLimitInput } from '../../../common/model_memory_limit';
1919
import { JobCreatorContext } from '../../../job_creator_context';
2020
import { JOB_TYPE } from '../../../../../../../../../common/constants/new_job';
2121

22-
const ButtonContent = i18n.translate(
22+
const buttonContent = i18n.translate(
2323
'xpack.ml.newJob.wizard.jobDetailsStep.advancedSectionButton',
2424
{
2525
defaultMessage: 'Advanced',
@@ -55,7 +55,7 @@ export const AdvancedSection: FC<Props> = ({ advancedExpanded, setAdvancedExpand
5555
<EuiSpacer size="xl" />
5656
<EuiAccordion
5757
id="advanced-section"
58-
buttonContent={ButtonContent}
58+
buttonContent={buttonContent}
5959
onToggle={setAdvancedExpanded}
6060
initialIsOpen={advancedExpanded}
6161
data-test-subj="mlJobWizardToggleAdvancedSection"

x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_view/examples_valid_callout.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
*/
66

77
import React, { FC } from 'react';
8-
import { EuiCallOut, EuiSpacer, EuiCallOutProps } from '@elastic/eui';
8+
import {
9+
EuiCallOut,
10+
EuiSpacer,
11+
EuiCallOutProps,
12+
EuiAccordion,
13+
EuiListGroup,
14+
EuiListGroupItemProps,
15+
} from '@elastic/eui';
916
import { i18n } from '@kbn/i18n';
1017
import { FormattedMessage } from '@kbn/i18n/react';
1118

@@ -14,14 +21,25 @@ import {
1421
FieldExampleCheck,
1522
} from '../../../../../../../../../common/types/categories';
1623
import { EditCategorizationAnalyzerFlyout } from '../../../common/edit_categorization_analyzer_flyout';
17-
import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '../../../../../../../../../common/constants/new_job';
24+
import {
25+
CATEGORY_EXAMPLES_VALIDATION_STATUS,
26+
VALIDATION_CHECK_DESCRIPTION,
27+
} from '../../../../../../../../../common/constants/categorization_job';
28+
import { VALIDATION_RESULT } from '../../../../../../../../../common/types/categories';
1829

1930
interface Props {
2031
validationChecks: FieldExampleCheck[];
2132
overallValidStatus: CATEGORY_EXAMPLES_VALIDATION_STATUS;
2233
categorizationAnalyzer: CategorizationAnalyzer;
2334
}
2435

36+
const allChecksButtonContent = i18n.translate(
37+
'xpack.ml.newJob.wizard.jobDetailsStep.allChecksButton',
38+
{
39+
defaultMessage: 'View all checks performed',
40+
}
41+
);
42+
2543
export const ExamplesValidCallout: FC<Props> = ({
2644
overallValidStatus,
2745
validationChecks,
@@ -66,6 +84,10 @@ export const ExamplesValidCallout: FC<Props> = ({
6684
))}
6785
<EuiSpacer size="s" />
6886
{analyzerUsed}
87+
<EuiSpacer size="s" />
88+
<EuiAccordion id="all-checks" buttonContent={allChecksButtonContent}>
89+
<AllValidationChecks validationChecks={validationChecks} />
90+
</EuiAccordion>
6991
</EuiCallOut>
7092
);
7193
};
@@ -96,3 +118,28 @@ const AnalyzerUsed: FC<{ categorizationAnalyzer: CategorizationAnalyzer }> = ({
96118
</>
97119
);
98120
};
121+
122+
const AllValidationChecks: FC<{ validationChecks: FieldExampleCheck[] }> = ({
123+
validationChecks,
124+
}) => {
125+
const list: EuiListGroupItemProps[] = Object.keys(VALIDATION_CHECK_DESCRIPTION).map((k, i) => {
126+
const failedCheck = validationChecks.find(vc => vc.id === i);
127+
if (
128+
failedCheck !== undefined &&
129+
failedCheck?.valid !== CATEGORY_EXAMPLES_VALIDATION_STATUS.VALID
130+
) {
131+
return {
132+
iconType: 'cross',
133+
label: failedCheck.message,
134+
size: 's',
135+
};
136+
}
137+
return {
138+
iconType: 'check',
139+
label: VALIDATION_CHECK_DESCRIPTION[i as VALIDATION_RESULT],
140+
size: 's',
141+
};
142+
});
143+
144+
return <EuiListGroup listItems={list} maxWidth={false} />;
145+
};

x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_view/metric_selection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
CategoryFieldExample,
1919
FieldExampleCheck,
2020
} from '../../../../../../../../../common/types/categories';
21-
import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '../../../../../../../../../common/constants/new_job';
21+
import { CATEGORY_EXAMPLES_VALIDATION_STATUS } from '../../../../../../../../../common/constants/categorization_job';
2222
import { LoadingWrapper } from '../../../charts/loading_wrapper';
2323

2424
interface Props {

0 commit comments

Comments
 (0)