[
https://issues.apache.org/jira/browse/KNOX-2052?focusedWorklogId=324236&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-324236
]
ASF GitHub Bot logged work on KNOX-2052:
----------------------------------------
Author: ASF GitHub Bot
Created on: 07/Oct/19 09:47
Start Date: 07/Oct/19 09:47
Worklog Time Spent: 10m
Work Description: smolnar82 commented on pull request #163: KNOX-2052 -
KnoxShellTable mean, median, and mode methods
URL: https://github.com/apache/knox/pull/163#discussion_r331928191
##########
File path:
gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTable.java
##########
@@ -76,6 +80,98 @@ public KnoxShellTable value(Comparable<? extends Object>
value) {
return col;
}
+ public double[] toDoubleArray(String colName) throws
IllegalArgumentException {
+ List<Comparable<? extends Object>> col = values(colName);
+ double[] colArray = new double[col.size()];
+ int conversionMethod = 0;
+ for (int i = 0; i < col.size(); i++) {
+ if (i == 0) {
+ if (col.get(i) instanceof Integer) {
+ conversionMethod = INTEGER_CONVERSION_METHOD;
+ }
+ else if (col.get(i) instanceof Double) {
+ conversionMethod = DOUBLE_CONVERSION_METHOD;
+ }
+ else if (col.get(i) instanceof Float) {
+ conversionMethod = FLOAT_CONVERSION_METHOD;
+ }
+ else {
+ throw new IllegalArgumentException();
+ }
+ }
+ if (conversionMethod == INTEGER_CONVERSION_METHOD) {
+ colArray[i] = (double) ((Integer) col.get(i)).intValue();
+ }
+ if (conversionMethod == DOUBLE_CONVERSION_METHOD) {
+ colArray[i] = (double) ((Double) col.get(i));
+ }
+ if (conversionMethod == FLOAT_CONVERSION_METHOD) {
+ colArray[i] = (double) ((Float) col.get(i)).floatValue();
+ }
+ }
+ return colArray;
+ }
+
+ public double mean(String colName) {
+ double[] colArray = toDoubleArray(colName);
+ double arrayMean = StatUtils.mean(colArray);
+ return arrayMean;
+ }
+
+ public double mean(int colIndex) {
+ return mean(headers.get(colIndex));
+ }
+
+ public double median(String colName) {
+ double[] colArray = toDoubleArray(colName);
+ double arrayMedian = StatUtils.percentile(colArray, 50);
+ return arrayMedian;
Review comment:
`return StatUtils. percentile(toDoubleArray(colName), 50)` directly?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 324236)
> KnoxShellTable mean, median, and mode methods
> ---------------------------------------------
>
> Key: KNOX-2052
> URL: https://issues.apache.org/jira/browse/KNOX-2052
> Project: Apache Knox
> Issue Type: Improvement
> Components: KnoxShell
> Reporter: Ljmiv
> Assignee: Ljmiv
> Priority: Major
> Fix For: 1.4.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Would be beneficial to be able to get the mean, median, and mode values from
> columns in a table. No such functions exist as of now.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)