Search in sources :

Example 1 with HighScoreTableEntry

use of org.olat.course.highscore.ui.HighScoreTableEntry in project OpenOLAT by OpenOLAT.

the class HighScoreManagerTest method highscoreTest.

@Test
public void highscoreTest() {
    List<AssessmentEntry> assessEntries = new ArrayList<>();
    int[] scores = { 1, 23, 10 };
    Identity assessedIdentity = null;
    // Create entries, add to List
    for (int i = 0; i < scores.length; i++) {
        assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-2");
        RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
        String subIdent = UUID.randomUUID().toString();
        AssessmentEntry nodeAssessment = courseNodeAssessmentDao.createAssessmentEntry(assessedIdentity, subIdent, entry, subIdent, entry);
        nodeAssessment.setScore(new BigDecimal(scores[i]));
        dbInstance.commitAndCloseSession();
        AssessmentEntry reloadedAssessment = courseNodeAssessmentDao.loadAssessmentEntryById(nodeAssessment.getKey());
        assessEntries.add(reloadedAssessment);
    }
    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")).getScores();
    assertNotNull(allScores);
    assertEquals(allMembers.size(), scores.length);
    assertTrue(allScores[0] > 20);
    assertTrue(allScores[2] < 10);
    double[] histogramData = highScoreManager.processHistogramData(allScores, 0F, 30F).getModifiedScores();
    assertNotNull(histogramData);
    long classwidth = highScoreManager.processHistogramData(allScores, 0F, 30F).getClasswidth();
    assertEquals(2L, classwidth);
}
Also used : ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) HighScoreTableEntry(org.olat.course.highscore.ui.HighScoreTableEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) BigDecimal(java.math.BigDecimal) ArrayList(java.util.ArrayList) List(java.util.List) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 2 with HighScoreTableEntry

use of org.olat.course.highscore.ui.HighScoreTableEntry in project OpenOLAT by OpenOLAT.

the class HighScoreManager method sortRankByScore.

/**
 * Sort rank by score, then by id and last alphabetically,
 * determine rank of each member dependent on score,
 * decide whether there is a second table or not
 */
public HighScoreRankingResults sortRankByScore(List<AssessmentEntry> assessEntries, List<HighScoreTableEntry> allMembers, List<HighScoreTableEntry> ownIdMembers, List<List<HighScoreTableEntry>> allPodium, List<Integer> ownIdIndices, int tableSize, Identity ownIdentity) {
    HighScoreTableEntry ownTableEntry = null;
    for (AssessmentEntry assessmentEntry : assessEntries) {
        float score = assessmentEntry.getScore() == null ? 0f : assessmentEntry.getScore().floatValue();
        HighScoreTableEntry tableEntry = new HighScoreTableEntry(score, userManager.getUserDisplayName(assessmentEntry.getIdentity()), assessmentEntry.getIdentity());
        if (tableEntry.getIdentity().equals(ownIdentity)) {
            ownTableEntry = tableEntry;
        }
        allMembers.add(tableEntry);
    }
    assessEntries.clear();
    // 3 step comparator, sorts by score then own Identity comes first, last alphabetically
    Collections.sort(allMembers, new HighscoreComparator(ownIdentity));
    float buffer = -1;
    int index = 0;
    // int rank = 1;
    double[] allScores = new double[allMembers.size()];
    for (int j = 0; j < allMembers.size(); j++) {
        HighScoreTableEntry member = allMembers.get(j);
        if (member.getScore() < buffer) {
            index++;
        // rank = j + 1;
        }
        // first three position are put in separate lists, exclude zero scorers
        if (index < 3 && member.getScore() > 0) {
            allPodium.get(index).add(member);
        }
        // finding position rank for own id
        if (member.getIdentity().equals(ownIdentity)) {
            ownIdIndices.add(j);
        }
        // setting rank for each member
        member.setRank(index + 1);
        buffer = member.getScore();
        // adding scores for histogram
        allScores[j] = buffer;
    }
    // only getting member with own id for 2nd table
    ownIdMembers.addAll(allMembers.stream().skip(tableSize).filter(a -> a.getIdentity().equals(ownIdentity)).collect(Collectors.toList()));
    if (ownIdMembers.size() > 0) {
        log.audit("2nd Highscore Table established");
    }
    return new HighScoreRankingResults(allScores, ownTableEntry);
}
Also used : HighScoreTableEntry(org.olat.course.highscore.ui.HighScoreTableEntry) HighScoreRankingResults(org.olat.course.highscore.model.HighScoreRankingResults) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Example 3 with HighScoreTableEntry

use of org.olat.course.highscore.ui.HighScoreTableEntry in project openolat by klemens.

the class HighScoreManagerTest method highscoreTest.

@Test
public void highscoreTest() {
    List<AssessmentEntry> assessEntries = new ArrayList<>();
    int[] scores = { 1, 23, 10 };
    Identity assessedIdentity = null;
    // Create entries, add to List
    for (int i = 0; i < scores.length; i++) {
        assessedIdentity = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-2");
        RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
        String subIdent = UUID.randomUUID().toString();
        AssessmentEntry nodeAssessment = courseNodeAssessmentDao.createAssessmentEntry(assessedIdentity, subIdent, entry, subIdent, entry);
        nodeAssessment.setScore(new BigDecimal(scores[i]));
        dbInstance.commitAndCloseSession();
        AssessmentEntry reloadedAssessment = courseNodeAssessmentDao.loadAssessmentEntryById(nodeAssessment.getKey());
        assessEntries.add(reloadedAssessment);
    }
    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")).getScores();
    assertNotNull(allScores);
    assertEquals(allMembers.size(), scores.length);
    assertTrue(allScores[0] > 20);
    assertTrue(allScores[2] < 10);
    double[] histogramData = highScoreManager.processHistogramData(allScores, 0F, 30F).getModifiedScores();
    assertNotNull(histogramData);
    long classwidth = highScoreManager.processHistogramData(allScores, 0F, 30F).getClasswidth();
    assertEquals(2L, classwidth);
}
Also used : ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) HighScoreTableEntry(org.olat.course.highscore.ui.HighScoreTableEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) BigDecimal(java.math.BigDecimal) ArrayList(java.util.ArrayList) List(java.util.List) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 4 with HighScoreTableEntry

use of org.olat.course.highscore.ui.HighScoreTableEntry in project openolat by klemens.

the class HighScoreManager method sortRankByScore.

/**
 * Sort rank by score, then by id and last alphabetically,
 * determine rank of each member dependent on score,
 * decide whether there is a second table or not
 */
public HighScoreRankingResults sortRankByScore(List<AssessmentEntry> assessEntries, List<HighScoreTableEntry> allMembers, List<HighScoreTableEntry> ownIdMembers, List<List<HighScoreTableEntry>> allPodium, List<Integer> ownIdIndices, int tableSize, Identity ownIdentity) {
    HighScoreTableEntry ownTableEntry = null;
    for (AssessmentEntry assessmentEntry : assessEntries) {
        float score = assessmentEntry.getScore() == null ? 0f : assessmentEntry.getScore().floatValue();
        HighScoreTableEntry tableEntry = new HighScoreTableEntry(score, userManager.getUserDisplayName(assessmentEntry.getIdentity()), assessmentEntry.getIdentity());
        if (tableEntry.getIdentity().equals(ownIdentity)) {
            ownTableEntry = tableEntry;
        }
        allMembers.add(tableEntry);
    }
    assessEntries.clear();
    // 3 step comparator, sorts by score then own Identity comes first, last alphabetically
    Collections.sort(allMembers, new HighscoreComparator(ownIdentity));
    float buffer = -1;
    int index = 0;
    // int rank = 1;
    double[] allScores = new double[allMembers.size()];
    for (int j = 0; j < allMembers.size(); j++) {
        HighScoreTableEntry member = allMembers.get(j);
        if (member.getScore() < buffer) {
            index++;
        // rank = j + 1;
        }
        // first three position are put in separate lists, exclude zero scorers
        if (index < 3 && member.getScore() > 0) {
            allPodium.get(index).add(member);
        }
        // finding position rank for own id
        if (member.getIdentity().equals(ownIdentity)) {
            ownIdIndices.add(j);
        }
        // setting rank for each member
        member.setRank(index + 1);
        buffer = member.getScore();
        // adding scores for histogram
        allScores[j] = buffer;
    }
    // only getting member with own id for 2nd table
    ownIdMembers.addAll(allMembers.stream().skip(tableSize).filter(a -> a.getIdentity().equals(ownIdentity)).collect(Collectors.toList()));
    if (ownIdMembers.size() > 0) {
        log.audit("2nd Highscore Table established");
    }
    return new HighScoreRankingResults(allScores, ownTableEntry);
}
Also used : HighScoreTableEntry(org.olat.course.highscore.ui.HighScoreTableEntry) HighScoreRankingResults(org.olat.course.highscore.model.HighScoreRankingResults) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Aggregations

HighScoreTableEntry (org.olat.course.highscore.ui.HighScoreTableEntry)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)4 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 Identity (org.olat.core.id.Identity)2 HighScoreRankingResults (org.olat.course.highscore.model.HighScoreRankingResults)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2