mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[TSVB] Add a new "Series Agg" to count the number of series (#91225)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
86e035544e
commit
f4714d1667
3 changed files with 55 additions and 0 deletions
|
@ -61,6 +61,13 @@ function SeriesAggUi(props) {
|
|||
}),
|
||||
value: 'mean',
|
||||
},
|
||||
{
|
||||
label: intl.formatMessage({
|
||||
id: 'visTypeTimeseries.seriesAgg.functionOptions.countLabel',
|
||||
defaultMessage: 'Series count',
|
||||
}),
|
||||
value: 'count',
|
||||
},
|
||||
{
|
||||
label: intl.formatMessage({
|
||||
id: 'visTypeTimeseries.seriesAgg.functionOptions.overallSumLabel',
|
||||
|
|
|
@ -49,6 +49,16 @@ export const SeriesAgg = {
|
|||
});
|
||||
return [data];
|
||||
},
|
||||
count(targetSeries) {
|
||||
const data = [];
|
||||
_.zip(...targetSeries).forEach((row) => {
|
||||
const key = row[0][0];
|
||||
// Filter out undefined or null values
|
||||
const values = row.map((r) => r && r[1]).filter((v) => v || typeof v === 'number');
|
||||
data.push([key, values.length]);
|
||||
});
|
||||
return [data];
|
||||
},
|
||||
|
||||
overall_max: overall('max'),
|
||||
overall_min: overall('min'),
|
||||
|
|
|
@ -67,6 +67,44 @@ describe('seriesAgg', () => {
|
|||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('returns the count of series', () => {
|
||||
expect(seriesAgg.count(series)).toEqual([
|
||||
[
|
||||
[0, 3],
|
||||
[1, 3],
|
||||
[2, 3],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('returns the count of missing series', () => {
|
||||
expect(
|
||||
seriesAgg.count([
|
||||
[
|
||||
[0, null],
|
||||
[1, null],
|
||||
[2, 0],
|
||||
],
|
||||
[
|
||||
[0, 0],
|
||||
[1, null],
|
||||
[2, 3],
|
||||
],
|
||||
[
|
||||
[0, 2],
|
||||
[1, null],
|
||||
[2, 3],
|
||||
],
|
||||
])
|
||||
).toEqual([
|
||||
[
|
||||
[0, 2],
|
||||
[1, 0],
|
||||
[2, 3],
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('overall', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue