Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 19, 2021
1 parent 8fb9d38 commit 558c1cb
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/stats/outliers_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { getQuantiles } from './quantile.js'
// This is applied separately on max and min outliers.
export const getOutliersPercentages = function (measures) {
const length = Math.ceil(1 / OUTLIERS_GRANULARITY)
const maxIndex = Math.floor(length * OUTLIERS_MAX)
const minIndex = Math.floor(length * OUTLIERS_MAX)

if (maxIndex === 0) {
if (minIndex === 0) {
return { outliersMin: 0, outliersMax: 0 }
}

Expand All @@ -24,11 +24,11 @@ export const getOutliersPercentages = function (measures) {
// quantiles.map((number) => number.toFixed(3).padStart(10)).join('\n'),
// )

const outliersMin = getOutliersPercentage(quantiles, maxIndex, length)
const outliersMin = getOutliersPercentage(quantiles, minIndex, length)
const outliersMax = getOutliersPercentage(
// eslint-disable-next-line fp/no-mutating-methods
[...quantiles].reverse(),
maxIndex,
minIndex,
length,
)
return { outliersMin, outliersMax }
Expand All @@ -43,49 +43,49 @@ const OUTLIERS_MAX = 0.5
const OUTLIERS_GRANULARITY = 1e-3

// Return outliers percentage based on a specific outlier quantile
const getOutliersPercentage = function (quantiles, maxIndex, length) {
const getOutliersPercentage = function (quantiles, minIndex, length) {
// console.log('')
// console.log(
// quantiles
// .slice(0, maxIndex + 1)
// .slice(0, minIndex + 1)
// .map((number) => number.toFixed(3).padStart(10))
// .join('\n'),
// )

// eslint-disable-next-line fp/no-let
let minIndex = 0
let maxIndex = 0
// eslint-disable-next-line fp/no-let
let newMinIndex = 0
let newMaxIndex = 0

// eslint-disable-next-line fp/no-loops
do {
// console.log('')
// console.log(`${minIndex} -> ${newMinIndex}`)
// console.log(`${maxIndex} -> ${newMaxIndex}`)

// eslint-disable-next-line fp/no-mutation
minIndex = newMinIndex
maxIndex = newMaxIndex
// eslint-disable-next-line fp/no-mutation
newMinIndex = findMinIndex(quantiles, maxIndex, minIndex)
} while (newMinIndex !== undefined)
newMaxIndex = findMaxIndex(quantiles, minIndex, maxIndex)
} while (newMaxIndex !== undefined)

// console.log(`Final: ${minIndex} ${minIndex / length}`)
// console.log(`Final: ${maxIndex} ${maxIndex / length}`)
// console.log('')

return minIndex / length
return maxIndex / length
}

// eslint-disable-next-line max-statements, complexity
const findMinIndex = function (quantiles, maxIndex, minIndex) {
const max = quantiles[minIndex]
const min = quantiles[maxIndex]
const findMaxIndex = function (quantiles, minIndex, maxIndex) {
const max = quantiles[maxIndex]
const min = quantiles[minIndex]
// console.log(max, min)

if (max === min) {
return
}

// eslint-disable-next-line fp/no-loops, fp/no-let, fp/no-mutation
for (let index = minIndex + 1; index < maxIndex; index += 1) {
for (let index = maxIndex + 1; index < minIndex; index += 1) {
const quantile = quantiles[index]

// `max === quantile` happens when several consecutive quantiles have the
Expand All @@ -99,7 +99,7 @@ const findMinIndex = function (quantiles, maxIndex, minIndex) {
}

const widthPercentage = (max - quantile) / (max - min)
const quantilePercentage = (index - minIndex) / (maxIndex - minIndex)
const quantilePercentage = (index - maxIndex) / (minIndex - maxIndex)
const quantileRatio = getQuantileRatio(widthPercentage, quantilePercentage)
// const line = [
// quantile,
Expand Down

0 comments on commit 558c1cb

Please sign in to comment.