Skip to content
Snippets Groups Projects
Commit 6e9fd291 authored by srosse's avatar srosse
Browse files

OO-2943: calculate a lower bound and upper bound if they are not available

parent 87d6b3bd
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ import org.olat.course.highscore.model.HighScoreRankingResults;
import org.olat.course.highscore.ui.HighScoreTableEntry;
import org.olat.modules.assessment.AssessmentEntry;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
......@@ -44,6 +45,9 @@ public class HighScoreManager {
private static final OLog log = Tracing.createLoggerFor(HighScoreManager.class);
@Autowired
private UserManager userManager;
/**
* Sort rank by score, then by id and last alphabetically,
* determine rank of each member dependent on score,
......@@ -52,7 +56,7 @@ public class HighScoreManager {
public HighScoreRankingResults sortRankByScore (List<AssessmentEntry> assessEntries,
List<HighScoreTableEntry> allMembers, List<HighScoreTableEntry> ownIdMembers,
List<List<HighScoreTableEntry>> allPodium, List<Integer> ownIdIndices,
int tableSize, Identity ownIdentity, UserManager userManager){
int tableSize, Identity ownIdentity){
HighScoreTableEntry ownTableEntry = null;
......@@ -118,10 +122,17 @@ public class HighScoreManager {
double min = Math.floor(Arrays.stream(scores).min().getAsDouble());
double range = max - min;
// use original scores if range is too small else convert results to fit histogram
if (range <= 20) {
if (range <= 20 && range <0) {
classwidth = 1;
return new HighScoreRankingResults(scores, classwidth, min);
} else {
if(lowerBorder == null) {
lowerBorder = 0f;
}
if(upperBorder == null) {
upperBorder = (float)max;
}
// decrease amount of possible classes to avoid overlapping of large numbers(condition) on x-axis
boolean largeNumbers = range > 100d || max >= 1000d;
int maxnumberofclasses = largeNumbers ? 12 : 20;
......
......@@ -182,7 +182,7 @@ public class HighScoreRunController extends FormBasicController{
// compute ranking and order
highscoreDataModel = highScoreManager.sortRankByScore(assessEntries, allMembers, ownIdMembers,
allPodium, ownIdIndices, tableSize, ownIdentity, userManager);
allPodium, ownIdIndices, tableSize, ownIdentity);
allScores = highscoreDataModel.getScores();
......
......@@ -24,6 +24,12 @@
* <p>
*/
package org.olat.course.highscore;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.math.BigDecimal;
import java.util.ArrayList;
/**
* Description:<br>
* HighScoreManagerTest
......@@ -31,11 +37,6 @@ package org.olat.course.highscore;
* @author fkiefer
*/
import java.util.List;
import static org.junit.Assert.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.UUID;
import org.junit.Test;
......@@ -48,35 +49,19 @@ import org.olat.modules.assessment.manager.AssessmentEntryDAO;
import org.olat.repository.RepositoryEntry;
import org.olat.test.JunitTestHelper;
import org.olat.test.OlatTestCase;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
public class HighScoreManagerTest extends OlatTestCase {
private List<HighScoreTableEntry> allMembers, ownIdMembers;
private List<List<HighScoreTableEntry>> allPodium;
private List<Integer> ownIdIndices;
@Autowired
private HighScoreManager highScoreManager;
@Autowired
private UserManager userManager;
@Autowired
private DB dbInstance;
@Autowired
private HighScoreManager highScoreManager;
@Autowired
private AssessmentEntryDAO courseNodeAssessmentDao;
@Test
public void springtest() {
assertNotNull(highScoreManager);
assertNotNull(userManager);
assertNotNull(dbInstance);
assertNotNull(courseNodeAssessmentDao);
}
@Test
public void highscoreTest() {
List<AssessmentEntry> assessEntries = new ArrayList<>();
int[] scores = {1,23,10};
Identity assessedIdentity = null;
......@@ -92,17 +77,17 @@ public class HighScoreManagerTest extends OlatTestCase {
AssessmentEntry reloadedAssessment = courseNodeAssessmentDao.loadAssessmentEntryById(nodeAssessment.getKey());
assessEntries.add(reloadedAssessment);
}
ownIdIndices = new ArrayList<>();
allMembers = new ArrayList<>();
ownIdMembers = new ArrayList<>();
allPodium = new ArrayList<>();
List<Integer> ownIdIndices = new ArrayList<>();
List<HighScoreTableEntry> allMembers = new ArrayList<>();
List<HighScoreTableEntry> ownIdMembers = new ArrayList<>();
List<List<HighScoreTableEntry>> allPodium = new ArrayList<>();
allPodium.add(new ArrayList<>());
allPodium.add(new ArrayList<>());
allPodium.add(new ArrayList<>());
double[] allScores = highScoreManager.sortRankByScore(assessEntries, allMembers, ownIdMembers, allPodium,
ownIdIndices, 5, JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-2"), userManager)
ownIdIndices, 5, JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-2"))
.getScores();
assertNotNull(allScores);
......@@ -115,7 +100,5 @@ public class HighScoreManagerTest extends OlatTestCase {
long classwidth = highScoreManager.processHistogramData(allScores, 0F, 30F).getClasswidth();
assertEquals(2L, classwidth);
}
}
}
\ No newline at end of file
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