import { getSplits , getLastMetric , mapEmptyToZero } from '../../helpers' ; import { TSVB_METRIC_TYPES } from '../../../../../common/enums' ; import type { TableResponseProcessorsFunction } from './types' ; export const stdMetric = ( { response , panel , series , meta , extractFields } ) => ( next ) => async ( results ) => { const metric = getLastMetric ( series ) ; if ( metric . type === TSVB_METRIC_TYPES . STD_DEVIATION && metric . mode === 'band' ) { return next ( results ) ; } if ( [ TSVB_METRIC_TYPES . PERCENTILE_RANK , TSVB_METRIC_TYPES . PERCENTILE ] . includes ( metric . type as TSVB_METRIC_TYPES ) ) { return next ( results ) ; } if ( /_bucket$/ . test ( metric . type ) ) { return next ( results ) ; } ( await getSplits ( response , panel , series , meta , extractFields ) ) . forEach ( ( split ) => { const data = mapEmptyToZero ( metric , split . timeseries . buckets ) ; results . push ( { id : split . id , label : split . label , data , } ) ; } ) ; return next ( results ) ; } ;