-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Maps] Add percentile #85367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thomasneirynck
merged 82 commits into
elastic:master
from
thomasneirynck:maps/add_percentile2
Dec 15, 2020
Merged
[Maps] Add percentile #85367
Changes from all commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
61f9729
init
thomasneirynck 18dac03
Fix tests/rename
thomasneirynck 934d689
Type fixes
thomasneirynck dca9608
adding descriptors
thomasneirynck ef00fdd
remove fluffy export
thomasneirynck e640b9d
remove redundant cast
thomasneirynck 6e3463f
rename to count-agg field
thomasneirynck fa0d459
extract types
thomasneirynck 750eb78
rename
thomasneirynck cb331e0
boilerplate
thomasneirynck 8380a56
remove switching
thomasneirynck 0577e9d
remove count type-checking
thomasneirynck 05f7fdc
Merge branch 'maps/add_descriptors' into maps/add_percentile
thomasneirynck 82863b7
more boilerplate
thomasneirynck 0c8ea4f
simplify
thomasneirynck 43ef71b
move files
thomasneirynck d2aa300
Merge branch 'maps/add_descriptors' into maps/add_percentile
thomasneirynck d3103e9
boilerplate
thomasneirynck e1fca30
type fix
thomasneirynck dce131d
Merge branch 'master' of github.com:elastic/kibana into maps/add_perc…
thomasneirynck 25f5960
add slider
thomasneirynck 211bb3c
type fixes
thomasneirynck 6105ba7
init commit
thomasneirynck 47560f9
some type fixes
thomasneirynck f54ca8a
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 71e49df
add type check
thomasneirynck b7d8bbd
only take into account invalid dynamic fields
thomasneirynck c507a77
tmp debug
thomasneirynck e861f26
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck ffad517
ts type fixes
thomasneirynck e002047
retype
thomasneirynck ef1f225
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 9590abd
fix field-lookup after refactor
thomasneirynck e1e7ea0
type fixes
thomasneirynck c941774
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 54eacb3
add test covergage
thomasneirynck 001e0e1
add edge case test
thomasneirynck 6b70fcb
fix test for new behavior
thomasneirynck 361486a
fix rum test
thomasneirynck 67c1362
type fix
thomasneirynck 4f72d40
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 4475c94
Merge branch 'master' of github.com:elastic/kibana into maps/add_perc…
thomasneirynck c2b0750
type fixes
thomasneirynck a14e3f0
type fix
thomasneirynck 2069fcd
fix test
thomasneirynck ab8f0a5
Merge branch 'maps/update_style' into maps/add_percentile
thomasneirynck f23c642
simplify
thomasneirynck caaebb0
Merge branch 'master' of github.com:elastic/kibana into maps/add_perc…
thomasneirynck f794114
Merge branch 'master' into maps/update_style
thomasneirynck 09e8dba
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 0efe401
revert uptime change
thomasneirynck 3f9ffdf
Merge branch 'master' into maps/update_style
kibanamachine b4f3ea2
Merge branch 'maps/update_style' into maps/add_percentile
thomasneirynck dc5c8c8
fix term join parsing
thomasneirynck 6ea286b
feedback
thomasneirynck 5d6fa3e
rearrange
thomasneirynck ac2f943
switch inner-outer loop
thomasneirynck bb65b1d
use foreach
thomasneirynck 9eee260
Merge branch 'maps/update_style' into maps/add_percentile
thomasneirynck 1029527
Merge branch 'master' of github.com:elastic/kibana into maps/add_perc…
thomasneirynck 13a408a
implement new stylemeta api
thomasneirynck eeda3c4
type fix
thomasneirynck 510d4bd
remove crufty space
thomasneirynck a2e3e87
add more test coverage
thomasneirynck a66037b
remove agg field
thomasneirynck f754916
subclass from aggfield instead
thomasneirynck c294c20
show median
thomasneirynck 8d0e500
Merge branch 'master' of github.com:elastic/kibana into maps/add_perc…
thomasneirynck 9f11deb
use number input
thomasneirynck b2e0482
fix test
thomasneirynck 16f27a3
order alphabetically
thomasneirynck 4b2d8b8
Merge branch 'master' of github.com:elastic/kibana into maps/add_perc…
thomasneirynck bb96ffd
isolate component
thomasneirynck d8b7da1
typecheck/move file
thomasneirynck 0ac90cd
remove update on prop-change
thomasneirynck ca95f46
add unit test
thomasneirynck 84c2167
Merge branch 'master' of github.com:elastic/kibana into maps/add_perc…
thomasneirynck 0ea0b06
feedback
thomasneirynck 02ccab5
test fix
thomasneirynck c53d81d
feedback
thomasneirynck b7e8b73
status
thomasneirynck 49239fa
update snapshot
thomasneirynck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
x-pack/plugins/maps/public/classes/fields/agg/percentile_agg_field.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * 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 { AGG_TYPE, FIELD_ORIGIN } from '../../../../common/constants'; | ||
| import { IESAggSource } from '../../sources/es_agg_source'; | ||
| import { IndexPattern } from 'src/plugins/data/public'; | ||
| import { PercentileAggField } from './percentile_agg_field'; | ||
| import { ESDocField } from '../es_doc_field'; | ||
|
|
||
| const mockFields = [ | ||
| { | ||
| name: 'foo*', | ||
| }, | ||
| ]; | ||
| // @ts-expect-error | ||
| mockFields.getByName = (name: string) => { | ||
| return { | ||
| name, | ||
| }; | ||
| }; | ||
|
|
||
| const mockIndexPattern = { | ||
| title: 'wildIndex', | ||
| fields: mockFields, | ||
| }; | ||
|
|
||
| const mockEsAggSource = { | ||
| getAggKey: (aggType: AGG_TYPE, fieldName: string) => { | ||
| return 'agg_key'; | ||
| }, | ||
| getAggLabel: (aggType: AGG_TYPE, fieldName: string) => { | ||
| return 'agg_label'; | ||
| }, | ||
| getIndexPattern: async () => { | ||
| return mockIndexPattern; | ||
| }, | ||
| } as IESAggSource; | ||
|
|
||
| const mockEsDocField = { | ||
| getName() { | ||
| return 'foobar'; | ||
| }, | ||
| }; | ||
|
|
||
| const defaultParams = { | ||
| source: mockEsAggSource, | ||
| origin: FIELD_ORIGIN.SOURCE, | ||
| }; | ||
|
|
||
| describe('percentile agg field', () => { | ||
| test('should include percentile in name', () => { | ||
| const field = new PercentileAggField({ | ||
| ...defaultParams, | ||
| esDocField: mockEsDocField as ESDocField, | ||
| percentile: 80, | ||
| }); | ||
| expect(field.getName()).toEqual('agg_key_80'); | ||
| }); | ||
|
|
||
| test('should create percentile dsl', () => { | ||
| const field = new PercentileAggField({ | ||
| ...defaultParams, | ||
| esDocField: mockEsDocField as ESDocField, | ||
| percentile: 80, | ||
| }); | ||
|
|
||
| expect(field.getValueAggDsl(mockIndexPattern as IndexPattern)).toEqual({ | ||
| percentiles: { field: 'foobar', percents: [80] }, | ||
| }); | ||
| }); | ||
|
|
||
| test('label', async () => { | ||
| const field = new PercentileAggField({ | ||
| ...defaultParams, | ||
| esDocField: mockEsDocField as ESDocField, | ||
| percentile: 80, | ||
| }); | ||
|
|
||
| expect(await field.getLabel()).toEqual('80th agg_label'); | ||
| }); | ||
|
|
||
| test('label (median)', async () => { | ||
| const field = new PercentileAggField({ | ||
| ...defaultParams, | ||
| label: '', | ||
| esDocField: mockEsDocField as ESDocField, | ||
| percentile: 50, | ||
| }); | ||
|
|
||
| expect(await field.getLabel()).toEqual('median foobar'); | ||
| }); | ||
| }); |
72 changes: 72 additions & 0 deletions
72
x-pack/plugins/maps/public/classes/fields/agg/percentile_agg_field.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * 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 { IndexPattern } from 'src/plugins/data/common/index_patterns/index_patterns'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { AGG_TYPE } from '../../../../common/constants'; | ||
| import { IESAggField, CountAggFieldParams } from './agg_field_types'; | ||
| import { addFieldToDSL, getField } from '../../../../common/elasticsearch_util'; | ||
| import { ESDocField } from '../es_doc_field'; | ||
| import { getOrdinalSuffix } from '../../util/ordinal_suffix'; | ||
| import { AggField } from './agg_field'; | ||
|
|
||
| interface PercentileAggParams extends CountAggFieldParams { | ||
| esDocField?: ESDocField; | ||
| percentile: number; | ||
| } | ||
|
|
||
| export class PercentileAggField extends AggField implements IESAggField { | ||
| private readonly _percentile: number; | ||
| constructor(params: PercentileAggParams) { | ||
| super({ | ||
| ...params, | ||
| ...{ | ||
| aggType: AGG_TYPE.PERCENTILE, | ||
| }, | ||
| }); | ||
| this._percentile = params.percentile; | ||
| } | ||
|
|
||
| supportsFieldMeta(): boolean { | ||
| return true; | ||
| } | ||
|
|
||
| canValueBeFormatted(): boolean { | ||
| return true; | ||
| } | ||
|
|
||
| async getLabel(): Promise<string> { | ||
| if (this._label) { | ||
| return this._label; | ||
| } | ||
|
|
||
| if (this._percentile === 50) { | ||
| const median = i18n.translate('xpack.maps.fields.percentileMedianLabek', { | ||
| defaultMessage: 'median', | ||
| }); | ||
| return `${median} ${this.getRootName()}`; | ||
| } | ||
|
|
||
| const suffix = getOrdinalSuffix(this._percentile); | ||
| return `${this._percentile}${suffix} ${this._source.getAggLabel( | ||
| this._getAggType(), | ||
| this.getRootName() | ||
| )}`; | ||
| } | ||
|
|
||
| getName() { | ||
| return `${super.getName()}_${this._percentile}`; | ||
| } | ||
|
|
||
| getValueAggDsl(indexPattern: IndexPattern): unknown { | ||
| const field = getField(indexPattern, this.getRootName()); | ||
| const dsl: Record<string, unknown> = addFieldToDSL({}, field); | ||
| dsl.percents = [this._percentile]; | ||
| return { | ||
| percentiles: dsl, | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.