You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/05/26 08:56:04 UTC
svn commit: r1901274 - in /poi/trunk/poi/src: main/java/org/apache/poi/ss/formula/eval/ main/java/org/apache/poi/ss/formula/functions/ test/java/org/apache/poi/ss/formula/functions/
Author: fanningpj
Date: Thu May 26 08:56:04 2022
New Revision: 1901274
URL: http://svn.apache.org/viewvc?rev=1901274&view=rev
Log:
add DVAR function support
Added:
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DVar.java
- copied, changed from r1901258, poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStdev.java
poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDVar.java
- copied, changed from r1901258, poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDStdev.java
Modified:
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java?rev=1901274&r1=1901273&r2=1901274&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java Thu May 26 08:56:04 2022
@@ -112,7 +112,7 @@ public final class FunctionEval {
retval[44] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DMAX);
retval[45] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DSTDEV);
retval[46] = AggregateFunction.VAR;
- // 47: DVAR
+ retval[47] = new DStarRunner(DStarRunner.DStarAlgorithmEnum.DVAR);
retval[48] = TextFunction.TEXT;
// 49: LINEST
retval[50] = new Trend();
Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java?rev=1901274&r1=1901273&r2=1901274&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStarRunner.java Thu May 26 08:56:04 2022
@@ -23,7 +23,6 @@ import org.apache.poi.ss.formula.eval.Ar
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
-import org.apache.poi.ss.formula.eval.MissingArgEval;
import org.apache.poi.ss.formula.eval.NotImplementedException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.NumericValueEval;
@@ -64,6 +63,8 @@ public final class DStarRunner implement
DAVERAGE(DAverage::new),
/** @see DStdev */
DSTDEV(DStdev::new),
+ /** @see DVar */
+ DVAR(DVar::new),
;
private final Supplier<IDStarAlgorithm> implSupplier;
Copied: poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DVar.java (from r1901258, poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStdev.java)
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DVar.java?p2=poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DVar.java&p1=poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStdev.java&r1=1901258&r2=1901274&rev=1901274&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DStdev.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/DVar.java Thu May 26 08:56:04 2022
@@ -26,10 +26,10 @@ import java.math.BigDecimal;
import java.util.ArrayList;
/**
- * Implementation of the DStdev function:
- * Gets the standard deviation value of a column in an area with given conditions.
+ * Implementation of the DVar function:
+ * Gets the variance value of a column in an area with given conditions.
*/
-public final class DStdev implements IDStarAlgorithm {
+public final class DVar implements IDStarAlgorithm {
private final ArrayList<Double> values = new ArrayList<>();
@Override
@@ -48,7 +48,7 @@ public final class DStdev implements IDS
for (Double d : values) {
array[pos++] = d;
}
- final double stdev = StatsLib.stdev(array);
- return new NumberEval(new BigDecimal(NumberToTextConverter.toText(stdev)).doubleValue());
+ final double var = StatsLib.var(array);
+ return new NumberEval(new BigDecimal(NumberToTextConverter.toText(var)).doubleValue());
}
}
Copied: poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDVar.java (from r1901258, poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDStdev.java)
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDVar.java?p2=poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDVar.java&p1=poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDStdev.java&r1=1901258&r2=1901274&rev=1901274&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDStdev.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ss/formula/functions/TestDVar.java Thu May 26 08:56:04 2022
@@ -29,17 +29,17 @@ import static org.apache.poi.ss.util.Uti
import static org.apache.poi.ss.util.Utils.assertDouble;
/**
- * Testcase for function DSTDEV()
+ * Testcase for function DVAR()
*/
-public class TestDStdev {
+public class TestDVar {
- //https://support.microsoft.com/en-us/office/dstdev-function-026b8c73-616d-4b5e-b072-241871c4ab96
+ //https://support.microsoft.com/en-us/office/dvar-function-d6747ca9-99c7-48bb-996e-9d7af00f3ed1
@Test
void testMicrosoftExample1() throws IOException {
try (HSSFWorkbook wb = initWorkbook1()) {
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
HSSFCell cell = wb.getSheetAt(0).getRow(0).createCell(12);
- assertDouble(fe, cell, "DSTDEV(A5:E11, \"Yield\", A1:A3)", 2.96647939483827, 0.0000000001);
+ assertDouble(fe, cell, "DVAR(A4:E10, \"Yield\", A1:A3)", 8.8, 0.0000000001);
}
}
@@ -49,14 +49,13 @@ public class TestDStdev {
addRow(sheet, 0, "Tree", "Height", "Age", "Yield", "Profit", "Height");
addRow(sheet, 1, "=Apple", ">10", null, null, null, "<16");
addRow(sheet, 2, "=Pear");
- addRow(sheet, 3);
- addRow(sheet, 4, "Tree", "Height", "Age", "Yield", "Profit");
- addRow(sheet, 5, "Apple", 18, 20, 14, 105);
- addRow(sheet, 6, "Pear", 12, 12, 10, 96);
- addRow(sheet, 7, "Cherry", 13, 14, 9, 105);
- addRow(sheet, 8, "Apple", 14, 15, 10, 75);
- addRow(sheet, 9, "Pear", 9, 8, 8, 77);
- addRow(sheet, 10, "Apple", 8, 9, 6, 45);
+ addRow(sheet, 3, "Tree", "Height", "Age", "Yield", "Profit");
+ addRow(sheet, 4, "Apple", 18, 20, 14, 105);
+ addRow(sheet, 5, "Pear", 12, 12, 10, 96);
+ addRow(sheet, 6, "Cherry", 13, 14, 9, 105);
+ addRow(sheet, 7, "Apple", 14, 15, 10, 75);
+ addRow(sheet, 8, "Pear", 9, 8, 8, 77);
+ addRow(sheet, 9, "Apple", 8, 9, 6, 45);
return wb;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org