import { i18n } from '@kbn/i18n' ; export function getMetricChangeDescription ( actualProp , typicalProp ) { if ( actualProp === undefined || typicalProp === undefined ) { return { iconType : 'empty' , message : '' } ; } let iconType = 'alert' ; let message ; let actual = 0 ; let typical = 0 ; if ( Array . isArray ( actualProp ) ) { if ( actualProp . length === 1 ) { actual = actualProp [ 0 ] ; } else { return { iconType : 'alert' , message : i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.unusualValuesDescription' , { defaultMessage : 'Unusual values' , } ) , } ; } } else { actual = actualProp ; } if ( Array . isArray ( typicalProp ) ) { if ( typicalProp . length === 1 ) { typical = typicalProp [ 0 ] ; } } else { typical = typicalProp ; } if ( actual === typical ) { message = i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.actualSameAsTypicalDescription' , { defaultMessage : 'actual same as typical' , } ) ; } else { const isHigher = actual > typical ; iconType = isHigher ? 'sortUp' : 'sortDown' ; if ( typical !== 0 && actual !== 0 ) { const factor = isHigher ? actual / typical : typical / actual ; if ( factor > 1.5 ) { if ( factor <= 100 ) { message = isHigher ? i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.moreThanOneAndHalfxHigherDescription' , { defaultMessage : '{factor}x higher' , values : { factor : Math . round ( factor ) } , } ) : i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.moreThanOneAndHalfxLowerDescription' , { defaultMessage : '{factor}x lower' , values : { factor : Math . round ( factor ) } , } ) ; } else { message = isHigher ? i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.moreThan100xHigherDescription' , { defaultMessage : 'More than 100x higher' , } ) : i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.moreThan100xLowerDescription' , { defaultMessage : 'More than 100x lower' , } ) ; } } else if ( factor >= 1.05 ) { message = isHigher ? i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.moreThanOneAndFiveHundredthsxHigherDescription' , { defaultMessage : '{factor}x higher' , values : { factor : factor . toPrecision ( 2 ) } , } ) : i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.moreThanOneAndFiveHundredthsxLowerDescription' , { defaultMessage : '{factor}x lower' , values : { factor : factor . toPrecision ( 2 ) } , } ) ; } else { message = isHigher ? i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.unusuallyHighDescription' , { defaultMessage : 'Unusually high' , } ) : i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.unusuallyLowDescription' , { defaultMessage : 'Unusually low' , } ) ; } } else { if ( actual === 0 ) { message = i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.unexpectedZeroValueDescription' , { defaultMessage : 'Unexpected zero value' , } ) ; } else { message = i18n . translate ( 'xpack.ml.formatters.metricChangeDescription.unexpectedNonZeroValueDescription' , { defaultMessage : 'Unexpected non-zero value' , } ) ; } } } return { iconType , message } ; }