Created
March 4, 2024 19:47
-
-
Save aazbeltran/e98fd2de09ec31f2fef554159649f94f to your computer and use it in GitHub Desktop.
Jetbrains scripting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static java.math.MathContext.DECIMAL128 | |
def toBigDecimalFunc = { value -> | |
value instanceof Number ? value as BigDecimal : | |
value.toString().isBigDecimal() ? value.toString() as BigDecimal : | |
null | |
} | |
def valuesList = [] | |
ROWS.each { row -> | |
COLUMNS.each { column -> | |
def bigDecimalVal = toBigDecimalFunc(row.value(column)) | |
if (bigDecimalVal != null) { | |
valuesList.add(bigDecimalVal) | |
} | |
} | |
} | |
if (valuesList.isEmpty()) { | |
OUT.append("Not enough values") | |
return | |
} | |
def sumTotal = BigDecimal.ZERO | |
valuesList.each { val -> | |
sumTotal = sumTotal.add(val, DECIMAL128) | |
} | |
def avgValue = sumTotal.divide(valuesList.size(), DECIMAL128) | |
def sumSquaredDifference = BigDecimal.ZERO | |
valuesList.each { val -> | |
BigDecimal diff = val.subtract(avgValue, DECIMAL128) | |
sumSquaredDifference = sumSquaredDifference.add(diff.multiply(diff, DECIMAL128), DECIMAL128) | |
} | |
def varianceValue = sumSquaredDifference.divide(valuesList.size(), DECIMAL128) | |
def stdDeviation = varianceValue.sqrt(DECIMAL128) | |
def coefficientOfVariation = stdDeviation.divide(avgValue, DECIMAL128) | |
OUT.append(stdDeviation.round(2) + "%") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment