From a9e67d9857160aa0932f05c85a60eb10c95e36fa Mon Sep 17 00:00:00 2001 From: uhensler <urs.hensler@frentix.com> Date: Tue, 18 Jun 2019 11:11:31 +0200 Subject: [PATCH] OO-4100: Calculation of variance / standard deviation in survey reports --- .../forms/model/jpa/RubricStatisticImpl.java | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/olat/modules/forms/model/jpa/RubricStatisticImpl.java b/src/main/java/org/olat/modules/forms/model/jpa/RubricStatisticImpl.java index 612fe901e14..393dcb1e427 100644 --- a/src/main/java/org/olat/modules/forms/model/jpa/RubricStatisticImpl.java +++ b/src/main/java/org/olat/modules/forms/model/jpa/RubricStatisticImpl.java @@ -178,13 +178,17 @@ public class RubricStatisticImpl implements RubricStatistic { Double mean = getAverage(stepCounts); if (mean == null) return null; - List<Double> scaledValues = getScaledValues(stepCounts); - if (scaledValues.size() < 2) return null; - double temp = 0; - for(double a: scaledValues) - temp += (a-mean)*(a-mean); - return temp/(scaledValues.size() - 1); + int size = 0; + for (int step = 1; step <= rubric.getSteps(); step++) { + double value = rubric.getScaleType().getStepValue(rubric.getSteps(), step); + int count = stepCounts.get(step - 1).intValue(); + for (int i = 0; i < count; i++) { + temp += (value-mean)*(value-mean); + size++; + } + } + return size > 2? temp/(size - 1): null; } private Double getStdDev(List<Long> stepCounts) { @@ -194,21 +198,6 @@ public class RubricStatisticImpl implements RubricStatistic { return Math.sqrt(getVariance(stepCounts)); } - private List<Double> getScaledValues(List<Long> stepCounts) { - List<Double> scaledValues = new ArrayList<>(); - for (int step = 1; step <= rubric.getSteps(); step++) { - Long count = stepCounts.get(step - 1); - if (count != null) { - double stepValue = rubric.getScaleType().getStepValue(rubric.getSteps(), step); - for (int i = 0; i < count; i++) { - double scaledValue = stepValue * step; - scaledValues.add(Double.valueOf(scaledValue)); - } - } - } - return scaledValues; - } - private void calculateTotalStatistics() { Long numberOfNoResponses = countedNoResponses.stream().mapToLong(CalculatedLong::getValue).sum(); List<Long> totalStepCounts = getTotalStepCounts(); -- GitLab