Search in sources :

Example 6 with BulkAssessmentRow

use of org.olat.course.assessment.model.BulkAssessmentRow in project openolat by klemens.

the class DataStepForm method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String val = dataEl.getValue();
    if (!StringHelper.containsNonWhitespace(val) && (returnFileEl != null ? !returnFileEl.isUploadSuccess() : true)) {
        // do not proceed when nothin in input field and no file uploaded
        setFormWarning("form.step2.error");
        return;
    }
    // reset error
    setFormWarning(null);
    BulkAssessmentDatas datas = (BulkAssessmentDatas) getFromRunContext("datas");
    if (datas == null) {
        datas = new BulkAssessmentDatas();
    }
    if (bulkAssessmentTmpDir == null) {
        OlatRootFolderImpl bulkAssessmentDir = new OlatRootFolderImpl("/bulkassessment/", null);
        bulkAssessmentTmpDir = bulkAssessmentDir.createChildContainer(UUID.randomUUID().toString());
    }
    backupInputDatas(val, datas, bulkAssessmentTmpDir);
    List<String[]> splittedRows = splitRawData(val);
    addToRunContext("splittedRows", splittedRows);
    List<BulkAssessmentRow> rows = new ArrayList<>(100);
    if (returnFileEl != null) {
        processReturnFiles(datas, rows, bulkAssessmentTmpDir);
    }
    datas.setRows(rows);
    addToRunContext("datas", datas);
    fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
}
Also used : BulkAssessmentDatas(org.olat.course.assessment.model.BulkAssessmentDatas) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ArrayList(java.util.ArrayList) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow)

Example 7 with BulkAssessmentRow

use of org.olat.course.assessment.model.BulkAssessmentRow in project OpenOLAT by OpenOLAT.

the class BulkAssessmentTask method doProcess.

private void doProcess(List<BulkAssessmentFeedback> feedbacks) {
    final DB dbInstance = DBFactory.getInstance();
    final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    final Identity coachIdentity = securityManager.loadIdentityByKey(coachedIdentity);
    final ICourse course = CourseFactory.loadCourse(courseRes);
    final AssessableCourseNode courseNode = getCourseNode();
    final Roles studentRoles = new Roles(false, false, false, false, false, false, false, false);
    final boolean hasUserComment = courseNode.hasCommentConfigured();
    final boolean hasScore = courseNode.hasScoreConfigured();
    final boolean hasPassed = courseNode.hasPassedConfigured();
    final boolean hasReturnFiles = (StringHelper.containsNonWhitespace(datas.getReturnFiles()) && (courseNode instanceof TACourseNode || courseNode instanceof GTACourseNode));
    if (hasReturnFiles) {
        try {
            OlatRootFileImpl returnFilesZipped = new OlatRootFileImpl(datas.getReturnFiles(), null);
            String tmp = FolderConfig.getCanonicalTmpDir();
            unzipped = new File(tmp, UUID.randomUUID().toString() + File.separatorChar);
            unzipped.mkdirs();
            ZipUtil.unzip(returnFilesZipped.getBasefile(), unzipped);
        } catch (Exception e) {
            log.error("Cannot unzip the return files during bulk assessment", e);
        }
    }
    Float min = null;
    Float max = null;
    Float cut = null;
    if (hasScore) {
        min = courseNode.getMinScoreConfiguration();
        max = courseNode.getMaxScoreConfiguration();
    }
    if (hasPassed) {
        cut = courseNode.getCutValueConfiguration();
    }
    int count = 0;
    List<BulkAssessmentRow> rows = datas.getRows();
    for (BulkAssessmentRow row : rows) {
        Long identityKey = row.getIdentityKey();
        if (identityKey == null) {
            feedbacks.add(new BulkAssessmentFeedback("bulk.action.no.such.user", row.getAssessedId()));
            // nothing to do
            continue;
        }
        Identity identity = securityManager.loadIdentityByKey(identityKey);
        IdentityEnvironment ienv = new IdentityEnvironment(identity, studentRoles);
        UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        // update comment, empty string will reset comment
        String userComment = row.getComment();
        if (hasUserComment && userComment != null) {
            // Update userComment in db
            courseNode.updateUserUserComment(userComment, uce, coachIdentity);
        // LD: why do we have to update the efficiency statement?
        // EfficiencyStatementManager esm =	EfficiencyStatementManager.getInstance();
        // esm.updateUserEfficiencyStatement(uce);
        }
        // update score
        Float score = row.getScore();
        if (hasScore && score != null) {
            // score < minimum score
            if ((min != null && score.floatValue() < min.floatValue()) || (score.floatValue() < AssessmentHelper.MIN_SCORE_SUPPORTED)) {
            // "bulk.action.lessThanMin";
            } else // score > maximum score
            if ((max != null && score.floatValue() > max.floatValue()) || (score.floatValue() > AssessmentHelper.MAX_SCORE_SUPPORTED)) {
            // "bulk.action.greaterThanMax";
            } else {
                // score between minimum and maximum score
                ScoreEvaluation se;
                if (hasPassed && cut != null) {
                    Boolean passed = (score.floatValue() >= cut.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
                    se = new ScoreEvaluation(score, passed);
                } else {
                    se = new ScoreEvaluation(score, null);
                }
                // Update score,passed properties in db, and the user's efficiency statement
                courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, false, Role.auto);
            }
        }
        Boolean passed = row.getPassed();
        if (hasPassed && passed != null && cut == null) {
            // Configuration of manual assessment --> Display passed/not passed: yes, Type of display: Manual by tutor
            ScoreEvaluation seOld = courseNode.getUserScoreEvaluation(uce);
            Float oldScore = seOld.getScore();
            ScoreEvaluation se = new ScoreEvaluation(oldScore, passed);
            // Update score,passed properties in db, and the user's efficiency statement
            boolean incrementAttempts = false;
            courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, incrementAttempts, Role.auto);
        }
        boolean identityHasReturnFile = false;
        if (hasReturnFiles && row.getReturnFiles() != null && row.getReturnFiles().size() > 0) {
            String assessedId = row.getAssessedId();
            File assessedFolder = new File(unzipped, assessedId);
            identityHasReturnFile = assessedFolder.exists();
            if (identityHasReturnFile) {
                processReturnFile(courseNode, row, uce, assessedFolder);
            }
        }
        if (courseNode instanceof GTACourseNode) {
            // push the state further
            GTACourseNode gtaNode = (GTACourseNode) courseNode;
            if ((hasScore && score != null) || (hasPassed && passed != null)) {
                // pushed to graded
                updateTasksState(gtaNode, uce, TaskProcess.grading);
            } else if (hasReturnFiles) {
                // push to revised
                updateTasksState(gtaNode, uce, TaskProcess.correction);
            }
        }
        if (count++ % 5 == 0) {
            dbInstance.commitAndCloseSession();
        } else {
            dbInstance.commit();
        }
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) GTACourseNode(org.olat.course.nodes.GTACourseNode) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) TACourseNode(org.olat.course.nodes.TACourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow) FileNotFoundException(java.io.FileNotFoundException) BaseSecurity(org.olat.basesecurity.BaseSecurity) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BulkAssessmentFeedback(org.olat.course.assessment.model.BulkAssessmentFeedback) Identity(org.olat.core.id.Identity) File(java.io.File) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) DB(org.olat.core.commons.persistence.DB)

Example 8 with BulkAssessmentRow

use of org.olat.course.assessment.model.BulkAssessmentRow in project OpenOLAT by OpenOLAT.

the class ValidationStepForm method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (validModel.getRowCount() == 0) {
        // do not continue wizard without valid data
        return;
    }
    BulkAssessmentDatas datas = (BulkAssessmentDatas) getFromRunContext("datas");
    List<BulkAssessmentRow> rows = new ArrayList<>(validModel.getRowCount() + invalidModel.getRowCount());
    for (int i = validModel.getRowCount(); i-- > 0; ) {
        rows.add(validModel.getObject(i).getRow());
    }
    for (int i = invalidModel.getRowCount(); i-- > 0; ) {
        rows.add(invalidModel.getObject(i).getRow());
    }
    datas.setRows(rows);
    addToRunContext("datas", datas);
    fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
}
Also used : BulkAssessmentDatas(org.olat.course.assessment.model.BulkAssessmentDatas) ArrayList(java.util.ArrayList) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow)

Example 9 with BulkAssessmentRow

use of org.olat.course.assessment.model.BulkAssessmentRow in project OpenOLAT by OpenOLAT.

the class DataStepForm method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String val = dataEl.getValue();
    if (!StringHelper.containsNonWhitespace(val) && (returnFileEl != null ? !returnFileEl.isUploadSuccess() : true)) {
        // do not proceed when nothin in input field and no file uploaded
        setFormWarning("form.step2.error");
        return;
    }
    // reset error
    setFormWarning(null);
    BulkAssessmentDatas datas = (BulkAssessmentDatas) getFromRunContext("datas");
    if (datas == null) {
        datas = new BulkAssessmentDatas();
    }
    if (bulkAssessmentTmpDir == null) {
        OlatRootFolderImpl bulkAssessmentDir = new OlatRootFolderImpl("/bulkassessment/", null);
        bulkAssessmentTmpDir = bulkAssessmentDir.createChildContainer(UUID.randomUUID().toString());
    }
    backupInputDatas(val, datas, bulkAssessmentTmpDir);
    List<String[]> splittedRows = splitRawData(val);
    addToRunContext("splittedRows", splittedRows);
    List<BulkAssessmentRow> rows = new ArrayList<>(100);
    if (returnFileEl != null) {
        processReturnFiles(datas, rows, bulkAssessmentTmpDir);
    }
    datas.setRows(rows);
    addToRunContext("datas", datas);
    fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
}
Also used : BulkAssessmentDatas(org.olat.course.assessment.model.BulkAssessmentDatas) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ArrayList(java.util.ArrayList) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow)

Example 10 with BulkAssessmentRow

use of org.olat.course.assessment.model.BulkAssessmentRow in project OpenOLAT by OpenOLAT.

the class ChooseColumnsStepForm method createRow.

/**
 * Create a row object from an array of strings. The array
 * is assessed identity identifier, score, status, comment.
 * @param values
 * @return
 */
private void createRow(String[] values, BulkAssessmentColumnSettings settings, List<BulkAssessmentRow> rows, Map<String, BulkAssessmentRow> assessedIdToRow) {
    int valuesLength = values.length;
    if (valuesLength <= 0 || valuesLength <= settings.getUsernameColumn()) {
        return;
    }
    String identifyer = values[settings.getUsernameColumn()];
    identifyer.trim();
    if (!StringHelper.containsNonWhitespace(identifyer)) {
        identifyer = "-";
    }
    BulkAssessmentRow row;
    if (assessedIdToRow.containsKey(identifyer)) {
        row = assessedIdToRow.get(identifyer);
    } else {
        row = new BulkAssessmentRow();
        row.setAssessedId(identifyer);
        rows.add(row);
    }
    if (valuesLength > settings.getScoreColumn()) {
        String scoreStr = values[settings.getScoreColumn()];
        scoreStr = scoreStr.trim();
        Float score;
        if (StringHelper.containsNonWhitespace(scoreStr)) {
            try {
                // accept writing with , or .
                score = Float.parseFloat(scoreStr.replace(',', '.'));
            } catch (NumberFormatException e) {
                score = null;
            }
        } else {
            // only set new numbers, ignore everything else
            score = null;
        }
        row.setScore(score);
    }
    if (valuesLength > settings.getPassedColumn()) {
        String passedStr = values[settings.getPassedColumn()];
        passedStr = passedStr.trim();
        Boolean passed;
        if ("y".equalsIgnoreCase(passedStr) || "yes".equalsIgnoreCase(passedStr) || "passed".equalsIgnoreCase(passedStr) || "true".equalsIgnoreCase(passedStr) || "1".equalsIgnoreCase(passedStr)) {
            passed = Boolean.TRUE;
        } else if ("n".equalsIgnoreCase(passedStr) || "no".equalsIgnoreCase(passedStr) || "false".equalsIgnoreCase(passedStr) || "failed".equalsIgnoreCase(passedStr) || "0".equalsIgnoreCase(passedStr)) {
            passed = Boolean.FALSE;
        } else {
            // only set defined values, ignore everything else
            passed = null;
        }
        row.setPassed(passed);
    }
    if (valuesLength > settings.getCommentColumn()) {
        String commentStr = values[settings.getCommentColumn()];
        commentStr = commentStr.trim();
        if (commentStr.isEmpty()) {
            // ignore empty values
            row.setComment(null);
        } else if ("\"\"".equals(commentStr) || "''".equals(commentStr)) {
            row.setComment("");
        } else {
            row.setComment(commentStr);
        }
    }
}
Also used : BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow)

Aggregations

BulkAssessmentRow (org.olat.course.assessment.model.BulkAssessmentRow)14 ArrayList (java.util.ArrayList)6 BulkAssessmentDatas (org.olat.course.assessment.model.BulkAssessmentDatas)6 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 HashMap (java.util.HashMap)4 Identity (org.olat.core.id.Identity)4 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 OlatRootFileImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 DB (org.olat.core.commons.persistence.DB)2 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)2 Roles (org.olat.core.id.Roles)2 ICourse (org.olat.course.ICourse)2