Search in sources :

Example 71 with ScoreEvaluation

use of org.olat.course.run.scoring.ScoreEvaluation in project openolat by klemens.

the class PassedRuleSPI method filter.

@Override
public void filter(RepositoryEntry entry, List<Identity> identities, ReminderRule rule) {
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        String nodeIdent = r.getLeftOperand();
        String status = r.getRightOperand();
        ICourse course = CourseFactory.loadCourse(entry);
        CourseNode courseNode = course.getRunStructure().getNode(nodeIdent);
        if (courseNode == null) {
            identities.clear();
            log.error("Passed rule in course " + entry.getKey() + " (" + entry.getDisplayname() + ") is missing a course element");
            return;
        }
        Map<Long, Boolean> passeds;
        if (courseNode instanceof STCourseNode) {
            passeds = new HashMap<>();
            STCourseNode structureNode = (STCourseNode) courseNode;
            if (structureNode.hasPassedConfigured()) {
                for (Identity identity : identities) {
                    UserCourseEnvironment uce = AssessmentHelper.createAndInitUserCourseEnvironment(identity, course);
                    ScoreEvaluation scoreEval = structureNode.getUserScoreEvaluation(uce);
                    Boolean passed = scoreEval.getPassed();
                    if (passed != null) {
                        passeds.put(identity.getKey(), passed);
                    }
                }
            }
        } else {
            passeds = helperDao.getPassed(entry, courseNode, identities);
        }
        if ("passed".equals(status)) {
            for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
                Boolean passed = passeds.get(identityIt.next().getKey());
                if (passed == null || !passed.booleanValue()) {
                    identityIt.remove();
                }
            }
        } else if ("failed".equals(status)) {
            for (Iterator<Identity> identityIt = identities.iterator(); identityIt.hasNext(); ) {
                Boolean passed = passeds.get(identityIt.next().getKey());
                if (passed != null && passed.booleanValue()) {
                    identityIt.remove();
                }
            }
        }
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) STCourseNode(org.olat.course.nodes.STCourseNode) Iterator(java.util.Iterator) STCourseNode(org.olat.course.nodes.STCourseNode) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity)

Example 72 with ScoreEvaluation

use of org.olat.course.run.scoring.ScoreEvaluation in project openolat by klemens.

the class ConvertToGTACourseNode method convertAssessmentDatas.

private void convertAssessmentDatas(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, ICourse course) {
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    CoursePropertyManager propertyMgr = courseEnv.getCoursePropertyManager();
    Map<Long, AssessmentEntry> datas = new HashMap<>();
    List<AssessmentEntry> properties = courseEnv.getAssessmentManager().getAssessmentEntries(sourceNode);
    for (AssessmentEntry property : properties) {
        Identity identity = property.getIdentity();
        datas.put(identity.getKey(), property);
    }
    properties = null;
    DBFactory.getInstance().getCurrentEntityManager().clear();
    AssessmentManager assessmentMgr = courseEnv.getAssessmentManager();
    for (AssessmentEntry assessmentData : datas.values()) {
        Identity assessedIdentity = securityManager.loadIdentityByKey(assessmentData.getIdentity().getKey());
        if (assessmentData.getPassed() != null || assessmentData.getScore() != null) {
            UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
            Float score = assessmentData.getScore() == null ? null : assessmentData.getScore().floatValue();
            ScoreEvaluation scoreEval = new ScoreEvaluation(score, assessmentData.getPassed());
            assessmentMgr.saveScoreEvaluation(gtaNode, null, assessedIdentity, scoreEval, userCourseEnv, false, Role.auto);
            // set graded
            Task task = gtaManager.getTask(assessedIdentity, taskList);
            if (task == null) {
                gtaManager.createTask(null, taskList, TaskProcess.graded, null, assessedIdentity, gtaNode);
            } else {
                gtaManager.updateTask(task, TaskProcess.graded, gtaNode, Role.auto);
            }
        }
        if (assessmentData.getAttempts() != null) {
            assessmentMgr.saveNodeAttempts(gtaNode, null, assessedIdentity, assessmentData.getAttempts().intValue(), Role.auto);
        }
        if (StringHelper.containsNonWhitespace(assessmentData.getCoachComment())) {
            assessmentMgr.saveNodeCoachComment(gtaNode, assessedIdentity, assessmentData.getCoachComment());
        }
        if (StringHelper.containsNonWhitespace(assessmentData.getComment())) {
            assessmentMgr.saveNodeComment(gtaNode, null, assessedIdentity, assessmentData.getComment());
        }
    }
    DBFactory.getInstance().getCurrentEntityManager().clear();
    // copy log entries
    List<Property> logEntries = propertyMgr.listCourseNodeProperties(sourceNode, null, null, UserNodeAuditManager.LOG_IDENTIFYER);
    for (Property logEntry : logEntries) {
        String logText = logEntry.getTextValue();
        Identity identity = securityManager.loadIdentityByKey(logEntry.getIdentity().getKey());
        Property targetProp = propertyMgr.findCourseNodeProperty(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER);
        if (targetProp == null) {
            targetProp = propertyMgr.createCourseNodePropertyInstance(gtaNode, identity, null, UserNodeAuditManager.LOG_IDENTIFYER, null, null, null, logText);
        } else {
            targetProp.setTextValue(logText);
        }
        propertyMgr.saveProperty(targetProp);
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) Task(org.olat.course.nodes.gta.Task) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) HashMap(java.util.HashMap) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessmentManager(org.olat.course.assessment.AssessmentManager) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 73 with ScoreEvaluation

use of org.olat.course.run.scoring.ScoreEvaluation in project OpenOLAT by OpenOLAT.

the class ReminderRuleEngineTest method score.

@Test
public void score() {
    // create a course with 3 members and generate some datas
    Identity tutor = JunitTestHelper.createAndPersistIdentityAsRndUser("score-tutor-1");
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("score-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("score-2");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("score-3");
    RepositoryEntry re = JunitTestHelper.deployDemoCourse(id1);
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(id2, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(id3, re, GroupRoles.participant.name());
    dbInstance.commit();
    String nodeIdent = assessmentData(tutor, id1, new ScoreEvaluation(1.0f, false), re);
    assessmentData(tutor, id2, new ScoreEvaluation(5.0f, true), re);
    assessmentData(tutor, id3, new ScoreEvaluation(10.0f, true), re);
    List<Identity> identities = new ArrayList<>();
    identities.add(id1);
    identities.add(id2);
    identities.add(id3);
    {
        // check score > 0.5
        List<ReminderRule> rules = getScoreRules(">", 0.5f, nodeIdent);
        List<Identity> all = new ArrayList<>(identities);
        ruleEngine.filterByRules(re, all, rules);
        Assert.assertEquals(3, all.size());
    }
    {
        // check score > 20.0
        List<ReminderRule> rules = getScoreRules(">", 20.0f, nodeIdent);
        List<Identity> all = new ArrayList<>(identities);
        ruleEngine.filterByRules(re, all, rules);
        Assert.assertEquals(0, all.size());
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 74 with ScoreEvaluation

use of org.olat.course.run.scoring.ScoreEvaluation in project OpenOLAT by OpenOLAT.

the class ScormAPIMapper method calculateScorePassed.

private void calculateScorePassed(String olatSahsId, Properties scoProperties, boolean finish) {
    // do a sum-of-scores over all sco scores
    // <OLATEE-27>
    float score = -1f;
    // </OLATEE-27>
    for (Iterator<Object> it_score = scoProperties.values().iterator(); it_score.hasNext(); ) {
        // <OLATEE-27>
        if (score < 0f) {
            score = 0f;
        }
        // </OLATEE-27>
        String aScore = (String) it_score.next();
        float ascore = Float.parseFloat(aScore);
        score += ascore;
    }
    float cutval = scormNode.getCutValueConfiguration().floatValue();
    boolean passed = (score >= cutval);
    // if advanceScore option is set update the score only if it is higher
    // <OLATEE-27>
    ModuleConfiguration config = scormNode.getModuleConfiguration();
    if (config.getBooleanSafe(ScormEditController.CONFIG_ADVANCESCORE, true)) {
        if (score > (currentScore != null ? currentScore : -1f)) {
            // </OLATEE-27>
            boolean increment = !attemptsIncremented && finish;
            ScoreEvaluation sceval = new ScoreEvaluation(new Float(score), Boolean.valueOf(passed));
            scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, increment, Role.user);
            if (increment) {
                attemptsIncremented = true;
            }
        } else if (!config.getBooleanSafe(ScormEditController.CONFIG_ATTEMPTSDEPENDONSCORE, false)) {
            boolean increment = !attemptsIncremented && finish;
            ScoreEvaluation sceval = scormNode.getUserScoreEvaluation(userCourseEnv);
            scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, increment, Role.user);
            if (increment) {
                attemptsIncremented = true;
            }
        }
    } else {
        // <OLATEE-27>
        if (score < 0f) {
            score = 0f;
        }
        // </OLATEE-27>
        boolean increment = !attemptsIncremented && finish;
        ScoreEvaluation sceval = new ScoreEvaluation(new Float(score), Boolean.valueOf(passed));
        scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, false, Role.user);
        if (increment) {
            attemptsIncremented = true;
        }
    }
    if (log.isDebug()) {
        String msg = "for scorm node:" + scormNode.getIdent() + " (" + scormNode.getShortTitle() + ") a lmsCommit for scoId " + olatSahsId + " occured, total sum = " + score + ", cutvalue =" + cutval + ", passed: " + passed + ", all scores now = " + scoProperties.toString();
        log.debug(msg, null);
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ModuleConfiguration(org.olat.modules.ModuleConfiguration)

Example 75 with ScoreEvaluation

use of org.olat.course.run.scoring.ScoreEvaluation in project OpenOLAT by OpenOLAT.

the class ScormAPIMapper method calculatePassed.

private void calculatePassed(String olatSahsId, Properties lessonStatusProp, boolean finish) {
    int found = 0;
    boolean passedScos = true;
    for (Iterator<Object> it_status = lessonStatusProp.values().iterator(); it_status.hasNext(); ) {
        String status = (String) it_status.next();
        passedScos &= "passed".equals(status);
        found++;
    }
    boolean passed = (found == scormAdapter.getNumOfSCOs()) && passedScos;
    // if advanceScore option is set update the score only if it is higher
    // <OLATEE-27>
    ModuleConfiguration config = scormNode.getModuleConfiguration();
    if (config.getBooleanSafe(ScormEditController.CONFIG_ADVANCESCORE, true)) {
        if (currentPassed == null || !currentPassed.booleanValue()) {
            // </OLATEE-27>
            boolean increment = !attemptsIncremented && finish;
            ScoreEvaluation sceval = new ScoreEvaluation(new Float(0.0f), Boolean.valueOf(passed));
            scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, increment, Role.user);
            if (increment) {
                attemptsIncremented = true;
            }
        } else if (!config.getBooleanSafe(ScormEditController.CONFIG_ATTEMPTSDEPENDONSCORE, false)) {
            boolean increment = !attemptsIncremented && finish;
            ScoreEvaluation sceval = scormNode.getUserScoreEvaluation(userCourseEnv);
            scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, increment, Role.user);
            if (increment) {
                attemptsIncremented = true;
            }
        }
    } else {
        boolean increment = !attemptsIncremented && finish;
        ScoreEvaluation sceval = new ScoreEvaluation(new Float(0.0f), Boolean.valueOf(passed));
        scormNode.updateUserScoreEvaluation(sceval, userCourseEnv, identity, false, Role.user);
        if (increment) {
            attemptsIncremented = true;
        }
    }
    if (log.isDebug()) {
        String msg = "for scorm node:" + scormNode.getIdent() + " (" + scormNode.getShortTitle() + ") a lmsCommit for scoId " + olatSahsId + " occured, passed: " + passed + ", all lesson status now = " + lessonStatusProp.toString();
        log.debug(msg, null);
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ModuleConfiguration(org.olat.modules.ModuleConfiguration)

Aggregations

ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)130 Identity (org.olat.core.id.Identity)54 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)52 ICourse (org.olat.course.ICourse)40 AssessmentManager (org.olat.course.assessment.AssessmentManager)34 CourseNode (org.olat.course.nodes.CourseNode)28 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)26 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)22 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)22 RepositoryEntry (org.olat.repository.RepositoryEntry)20 ArrayList (java.util.ArrayList)16 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)14 ModuleConfiguration (org.olat.modules.ModuleConfiguration)14 ScoreAccounting (org.olat.course.run.scoring.ScoreAccounting)12 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)12 List (java.util.List)10 Test (org.junit.Test)10 AssessmentEntryStatus (org.olat.modules.assessment.model.AssessmentEntryStatus)10 BigDecimal (java.math.BigDecimal)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8