Skip to content
Snippets Groups Projects
Commit 4c391d05 authored by uhensler's avatar uhensler
Browse files

OO-4134: Exclude questions in report statistics if weight is 0

parent 81a1cfb8
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,8 @@ class RubricStatisticCalculator { ...@@ -98,7 +98,8 @@ class RubricStatisticCalculator {
long stepCount = 0; long stepCount = 0;
for (Slider slider: rubric.getSliders()) { for (Slider slider: rubric.getSliders()) {
Long sliderStepCount = sliderStepCounts.getStepCounts(slider).getStepCount(step); Long sliderStepCount = sliderStepCounts.getStepCounts(slider).getStepCount(step);
long weightedCount = weighted // Sliders with weight 0 are ignored even if it is not weighted
long weightedCount = weighted || slider.getWeight().intValue() == 0
? sliderStepCount.longValue() * slider.getWeight().intValue() ? sliderStepCount.longValue() * slider.getWeight().intValue()
: sliderStepCount.longValue(); : sliderStepCount.longValue();
stepCount += weightedCount; stepCount += weightedCount;
...@@ -121,7 +122,7 @@ class RubricStatisticCalculator { ...@@ -121,7 +122,7 @@ class RubricStatisticCalculator {
long noResponses = 0; long noResponses = 0;
for (Slider slider: rubric.getSliders()) { for (Slider slider: rubric.getSliders()) {
Long sliderNoResponses = slidersStepCounts.getStepCounts(slider).getNumberOfNoResponses(); Long sliderNoResponses = slidersStepCounts.getStepCounts(slider).getNumberOfNoResponses();
if (sliderNoResponses != null ) { if (sliderNoResponses != null && slider.getWeight().intValue() > 0) {
noResponses += sliderNoResponses.longValue(); noResponses += sliderNoResponses.longValue();
} }
} }
......
...@@ -751,7 +751,7 @@ public class RubricEditorController extends FormBasicController implements PageE ...@@ -751,7 +751,7 @@ public class RubricEditorController extends FormBasicController implements PageE
for(SliderRow row:sliders) { for(SliderRow row:sliders) {
TextElement weightEl = row.getWeightEl(); TextElement weightEl = row.getWeightEl();
weightEl.clearError(); weightEl.clearError();
if (isInvalidInteger(weightEl.getValue(), 1, 1000)) { if (isInvalidInteger(weightEl.getValue(), 0, 1000)) {
weightEl.setErrorKey("error.wrong.int", null); weightEl.setErrorKey("error.wrong.int", null);
allOk = false; allOk = false;
} }
...@@ -993,7 +993,7 @@ public class RubricEditorController extends FormBasicController implements PageE ...@@ -993,7 +993,7 @@ public class RubricEditorController extends FormBasicController implements PageE
private Integer getIntOrNull(TextElement weightEl) { private Integer getIntOrNull(TextElement weightEl) {
return StringHelper.containsNonWhitespace(weightEl.getValue()) return StringHelper.containsNonWhitespace(weightEl.getValue())
&& isValidInteger(weightEl.getValue(), 1, 10000000) && isValidInteger(weightEl.getValue(), 0, 10000000)
? Integer.parseInt(weightEl.getValue()) ? Integer.parseInt(weightEl.getValue())
: null; : null;
} }
......
...@@ -133,8 +133,9 @@ public class StatisticsCalculator { ...@@ -133,8 +133,9 @@ public class StatisticsCalculator {
Long statisticCount = statistic.getCount(); Long statisticCount = statistic.getCount();
if (statisticCount != null) { if (statisticCount != null) {
count += statisticCount.longValue(); count += statisticCount.longValue();
sumCount += statisticCount.longValue() * slider.getWeight().intValue(); long weightedCount = statisticCount.longValue() * slider.getWeight().intValue();
sumValues += statisticCount.longValue() * statistic.getAvg().doubleValue() * slider.getWeight().intValue(); sumCount += weightedCount;
sumValues += weightedCount * statistic.getAvg().doubleValue();
} }
} }
} }
...@@ -222,8 +223,8 @@ public class StatisticsCalculator { ...@@ -222,8 +223,8 @@ public class StatisticsCalculator {
double sumValues = 0; double sumValues = 0;
for (RawGroupedStatistic statistic : keysStatistics) { for (RawGroupedStatistic statistic : keysStatistics) {
long statisticCount = statistic.getCount()!= null? statistic.getCount().longValue(): 0; long statisticCount = statistic.getCount()!= null? statistic.getCount().longValue(): 0;
count += statisticCount;
Integer weight = sliderToWeight.get(statistic.getIdentifier()); Integer weight = sliderToWeight.get(statistic.getIdentifier());
count += weight != 0? statisticCount: 0;
sumCount += statisticCount * weight; sumCount += statisticCount * weight;
double statisticAvg = statistic.getRawAvg()!= null? statistic.getRawAvg().doubleValue(): 0; double statisticAvg = statistic.getRawAvg()!= null? statistic.getRawAvg().doubleValue(): 0;
sumValues += statisticAvg * statisticCount * weight; sumValues += statisticAvg * statisticCount * weight;
......
...@@ -50,7 +50,7 @@ public class RubricStatisticCalculatorTest { ...@@ -50,7 +50,7 @@ public class RubricStatisticCalculatorTest {
private RubricStatisticCalculator sut = new RubricStatisticCalculator(); private RubricStatisticCalculator sut = new RubricStatisticCalculator();
@Test @Test
public void shouldCountNoResponses() { public void shouldGetSliderCountNoResponses() {
long expectedCounts = 10; long expectedCounts = 10;
Slider slider = new Slider(); Slider slider = new Slider();
String sliderId = random(); String sliderId = random();
...@@ -66,7 +66,7 @@ public class RubricStatisticCalculatorTest { ...@@ -66,7 +66,7 @@ public class RubricStatisticCalculatorTest {
} }
@Test @Test
public void shouldCountNoResponsesDefault() { public void shouldGetSliderCountNoResponsesDefault() {
Slider slider = new Slider(); Slider slider = new Slider();
String sliderId = random(); String sliderId = random();
slider.setId(sliderId); slider.setId(sliderId);
...@@ -151,7 +151,7 @@ public class RubricStatisticCalculatorTest { ...@@ -151,7 +151,7 @@ public class RubricStatisticCalculatorTest {
} }
@Test @Test
public void shouldCalculateMean() { public void shouldCalculateSliderMedian() {
StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(3); StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(3);
stepCountsBuilder.withCount(1, Long.valueOf(3)); stepCountsBuilder.withCount(1, Long.valueOf(3));
stepCountsBuilder.withCount(2, Long.valueOf(6)); stepCountsBuilder.withCount(2, Long.valueOf(6));
...@@ -163,7 +163,7 @@ public class RubricStatisticCalculatorTest { ...@@ -163,7 +163,7 @@ public class RubricStatisticCalculatorTest {
} }
@Test @Test
public void shouldCalculateMeanBetween() { public void shouldCalculateSliderMedianBetween() {
StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(3); StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(3);
stepCountsBuilder.withCount(1, Long.valueOf(1)); stepCountsBuilder.withCount(1, Long.valueOf(1));
stepCountsBuilder.withCount(2, Long.valueOf(1)); stepCountsBuilder.withCount(2, Long.valueOf(1));
...@@ -175,7 +175,7 @@ public class RubricStatisticCalculatorTest { ...@@ -175,7 +175,7 @@ public class RubricStatisticCalculatorTest {
} }
@Test @Test
public void shouldCalculateMeanNoValues() { public void shouldCalculateSliderMedianNoValues() {
StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(3); StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(3);
stepCountsBuilder.withCount(1, Long.valueOf(0)); stepCountsBuilder.withCount(1, Long.valueOf(0));
stepCountsBuilder.withCount(2, Long.valueOf(0)); stepCountsBuilder.withCount(2, Long.valueOf(0));
...@@ -187,7 +187,7 @@ public class RubricStatisticCalculatorTest { ...@@ -187,7 +187,7 @@ public class RubricStatisticCalculatorTest {
} }
@Test @Test
public void shouldCalculateVariance() { public void shouldCalculateSliderVariance() {
ScaleType scaleType = ScaleType.oneToMax; ScaleType scaleType = ScaleType.oneToMax;
StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(4); StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(4);
stepCountsBuilder.withCount(1, Long.valueOf(2)); stepCountsBuilder.withCount(1, Long.valueOf(2));
...@@ -202,7 +202,7 @@ public class RubricStatisticCalculatorTest { ...@@ -202,7 +202,7 @@ public class RubricStatisticCalculatorTest {
} }
@Test @Test
public void shouldCalculateVarianceScaled() { public void shouldCalculateSliderVarianceScaled() {
ScaleType scaleType = ScaleType.zeroBallanced; ScaleType scaleType = ScaleType.zeroBallanced;
StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(4); StepCountsBuilder stepCountsBuilder = StepCountsBuilder.builder(4);
stepCountsBuilder.withCount(1, Long.valueOf(2)); stepCountsBuilder.withCount(1, Long.valueOf(2));
...@@ -245,6 +245,15 @@ public class RubricStatisticCalculatorTest { ...@@ -245,6 +245,15 @@ public class RubricStatisticCalculatorTest {
stepCountsBuilder3.withCount(2, Long.valueOf(2)); stepCountsBuilder3.withCount(2, Long.valueOf(2));
stepCountsBuilder3.withCount(3, Long.valueOf(3)); stepCountsBuilder3.withCount(3, Long.valueOf(3));
stepCountsImpl.put(slider3, stepCountsBuilder3.build()); stepCountsImpl.put(slider3, stepCountsBuilder3.build());
Slider slider4 = new Slider();
slider4.setId(random());
slider4.setWeight(0);
sliders.add(slider4);
StepCountsBuilder stepCountsBuilder4 = StepCountsBuilder.builder(4);
stepCountsBuilder4.withCount(1, Long.valueOf(1));
stepCountsBuilder4.withCount(2, Long.valueOf(2));
stepCountsBuilder4.withCount(3, Long.valueOf(4));
stepCountsImpl.put(slider4, stepCountsBuilder4.build());
Rubric rubric = new Rubric(); Rubric rubric = new Rubric();
rubric.setSliders(sliders); rubric.setSliders(sliders);
rubric.setSteps(3); rubric.setSteps(3);
...@@ -293,6 +302,16 @@ public class RubricStatisticCalculatorTest { ...@@ -293,6 +302,16 @@ public class RubricStatisticCalculatorTest {
stepCountsBuilder3.withCount(3, Long.valueOf(5)); stepCountsBuilder3.withCount(3, Long.valueOf(5));
stepCountsBuilder3.withCountNoResponses(Long.valueOf(3)); stepCountsBuilder3.withCountNoResponses(Long.valueOf(3));
slidersStepCountsImpl.put(slider3, stepCountsBuilder3.build()); slidersStepCountsImpl.put(slider3, stepCountsBuilder3.build());
Slider slider4 = new Slider();
slider4.setId(random());
slider4.setWeight(0);
sliders.add(slider4);
StepCountsBuilder stepCountsBuilder4 = StepCountsBuilder.builder(4);
stepCountsBuilder4.withCount(1, Long.valueOf(4));
stepCountsBuilder4.withCount(2, Long.valueOf(4));
stepCountsBuilder4.withCount(4, Long.valueOf(5));
stepCountsBuilder4.withCountNoResponses(Long.valueOf(4));
slidersStepCountsImpl.put(slider4, stepCountsBuilder4.build());
Rubric rubric = new Rubric(); Rubric rubric = new Rubric();
rubric.setSliders(sliders); rubric.setSliders(sliders);
rubric.setSteps(3); rubric.setSteps(3);
...@@ -300,13 +319,13 @@ public class RubricStatisticCalculatorTest { ...@@ -300,13 +319,13 @@ public class RubricStatisticCalculatorTest {
SliderStatistic totalStatistic = sut.calculateTotalStatistic(rubric, slidersStepCountsImpl); SliderStatistic totalStatistic = sut.calculateTotalStatistic(rubric, slidersStepCountsImpl);
SoftAssertions softly = new SoftAssertions(); SoftAssertions softly = new SoftAssertions();
softly.assertThat(totalStatistic.getNumberOfNoResponses()).isEqualTo(6); softly.assertThat(totalStatistic.getNumberOfNoResponses()).as("Number of no responses").isEqualTo(6);
softly.assertThat(totalStatistic.getNumberOfResponses()).isEqualTo(21); softly.assertThat(totalStatistic.getNumberOfResponses()).as("Number of responses").isEqualTo(21);
softly.assertThat(totalStatistic.getSum()).isEqualTo(96); softly.assertThat(totalStatistic.getSum()).as("Sum").isEqualTo(96);
softly.assertThat(totalStatistic.getAvg()).isEqualTo(2.13, offset(0.01)); softly.assertThat(totalStatistic.getAvg()).as("Avg").isEqualTo(2.13, offset(0.01));
softly.assertThat(totalStatistic.getMedian()).isEqualTo(2); softly.assertThat(totalStatistic.getMedian()).as("Median").isEqualTo(2);
softly.assertThat(totalStatistic.getVariance()).isEqualTo(0.663, offset(0.001)); softly.assertThat(totalStatistic.getVariance()).as("Variance").isEqualTo(0.663, offset(0.001));
softly.assertThat(totalStatistic.getStdDev()).isEqualTo(0.814, offset(0.001)); softly.assertThat(totalStatistic.getStdDev()).as("StdDev").isEqualTo(0.814, offset(0.001));
softly.assertAll(); softly.assertAll();
} }
......
...@@ -347,6 +347,10 @@ public class StatisticsCalculatorTest { ...@@ -347,6 +347,10 @@ public class StatisticsCalculatorTest {
slider21.setId(random()); slider21.setId(random());
slider21.setWeight(3); slider21.setWeight(3);
sliders2.add(slider21); sliders2.add(slider21);
Slider slider22 = new Slider();
slider22.setId(random());
slider22.setWeight(0);
sliders2.add(slider22);
Rubric rubric2 = new Rubric(); Rubric rubric2 = new Rubric();
rubric2.setId(random()); rubric2.setId(random());
rubric2.setSliders(sliders2); rubric2.setSliders(sliders2);
...@@ -362,13 +366,16 @@ public class StatisticsCalculatorTest { ...@@ -362,13 +366,16 @@ public class StatisticsCalculatorTest {
statisticsList.add(new RawGroupedStatisticImpl(slider11.getId(), multiKey1, temporalKey1, 1l, 1.0)); statisticsList.add(new RawGroupedStatisticImpl(slider11.getId(), multiKey1, temporalKey1, 1l, 1.0));
statisticsList.add(new RawGroupedStatisticImpl(slider12.getId(), multiKey1, temporalKey1, 1l, 1.0)); statisticsList.add(new RawGroupedStatisticImpl(slider12.getId(), multiKey1, temporalKey1, 1l, 1.0));
statisticsList.add(new RawGroupedStatisticImpl(slider21.getId(), multiKey1, temporalKey1, 1l, 1.0)); statisticsList.add(new RawGroupedStatisticImpl(slider21.getId(), multiKey1, temporalKey1, 1l, 1.0));
statisticsList.add(new RawGroupedStatisticImpl(slider22.getId(), multiKey1, temporalKey1, 1l, 1.0));
statisticsList.add(new RawGroupedStatisticImpl(slider11.getId(), multiKey1, temporalKey2, 2l, 1.0)); statisticsList.add(new RawGroupedStatisticImpl(slider11.getId(), multiKey1, temporalKey2, 2l, 1.0));
statisticsList.add(new RawGroupedStatisticImpl(slider12.getId(), multiKey1, temporalKey2, 2l, 2.0)); statisticsList.add(new RawGroupedStatisticImpl(slider12.getId(), multiKey1, temporalKey2, 2l, 2.0));
statisticsList.add(new RawGroupedStatisticImpl(slider21.getId(), multiKey1, temporalKey2, 2l, 3.0)); statisticsList.add(new RawGroupedStatisticImpl(slider21.getId(), multiKey1, temporalKey2, 2l, 3.0));
statisticsList.add(new RawGroupedStatisticImpl(slider22.getId(), multiKey1, temporalKey2, 2l, 3.0));
statisticsList.add(new RawGroupedStatisticImpl(slider12.getId(), multiKey2, temporalKey1, 100l, 20.2)); statisticsList.add(new RawGroupedStatisticImpl(slider12.getId(), multiKey2, temporalKey1, 100l, 20.2));
statisticsList.add(new RawGroupedStatisticImpl(slider11.getId(), multiKey2, temporalKey2, 3l, 3.0)); statisticsList.add(new RawGroupedStatisticImpl(slider11.getId(), multiKey2, temporalKey2, 3l, 3.0));
statisticsList.add(new RawGroupedStatisticImpl(slider12.getId(), multiKey2, temporalKey2, 2l, 2.0)); statisticsList.add(new RawGroupedStatisticImpl(slider12.getId(), multiKey2, temporalKey2, 2l, 2.0));
statisticsList.add(new RawGroupedStatisticImpl(slider21.getId(), multiKey2, temporalKey2, 1l, 1.0)); statisticsList.add(new RawGroupedStatisticImpl(slider21.getId(), multiKey2, temporalKey2, 1l, 1.0));
statisticsList.add(new RawGroupedStatisticImpl(slider22.getId(), multiKey2, temporalKey2, 2l, 2.0));
List<RawGroupedStatistic> reducedStatistics = sut.reduceIdentifier(statisticsList, rubrics); List<RawGroupedStatistic> reducedStatistics = sut.reduceIdentifier(statisticsList, rubrics);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment