Skip to content

Instantly share code, notes, and snippets.

@moscas
Created December 8, 2020 13:39
Show Gist options
  • Save moscas/85bcd11d4753dc1c4988c06d8a3253e1 to your computer and use it in GitHub Desktop.
Save moscas/85bcd11d4753dc1c4988c06d8a3253e1 to your computer and use it in GitHub Desktop.
Data extractor for IntelliJ which counts the arithmetic mean of the numeric values
/*
* Available context bindings:
* COLUMNS List<DataColumn>
* ROWS Iterable<DataRow>
* OUT { append() }
* FORMATTER { format(row, col); formatValue(Object, col); getTypeName(Object, col); isStringLiteral(Object, col); }
* TRANSPOSED Boolean
* plus ALL_COLUMNS, TABLE, DIALECT
*
* where:
* DataRow { rowNumber(); first(); last(); data(): List<Object>; value(column): Object }
* DataColumn { columnNumber(), name() }
*/
def RES = 0G
i = 0
ROWS.each { row ->
COLUMNS.each { column ->
def value = row.value(column)
if (value instanceof Number) {
RES += value
i++
}
else if (value.toString().isBigDecimal()) {
RES += value.toString().toBigDecimal()
i++
}
}
}
RES = RES/i
OUT.append(RES.toString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment