import { isFiniteNumber } from '../../../../common/utils/is_finite_number' ; import { ConnectionStatsItem , ConnectionStatsItemWithImpact , } from '../../../../common/connections' ; export function getConnectionStatsItemsWithRelativeImpact ( items ) { const latencySums = items . map ( ( { stats } ) => ( stats . latency . value ?? 0 ) * ( stats . throughput . value ?? 0 ) ) . filter ( isFiniteNumber ) ; const minLatencySum = Math . min ( ... latencySums ) ; const maxLatencySum = Math . max ( ... latencySums ) ; const itemsWithImpact = items . map ( ( item ) => { const { stats } = item ; const impact = isFiniteNumber ( stats . latency . value ) && isFiniteNumber ( stats . throughput . value ) ? ( ( stats . latency . value * stats . throughput . value - minLatencySum ) / ( maxLatencySum - minLatencySum ) ) * 100 : 0 ; return { ... item , stats : { ... stats , impact , } , } ; } ) ; return itemsWithImpact ; }