Computes Correction score from criteria grades.

@param Correction $correction

@return Correction
517462
public function computeCorrectionScore(Correction $correction)
    {
        $drop = $correction->getDrop();
        $dropzone = $drop->getDropzone();
        $criteria = $dropzone->getCriteria();

        if ($dropzone->isCriteriaEnabled() && count($criteria) > 0) {
            $score = 0;
            $criteriaIds = [];
            $scoreMax = $dropzone->getScoreMax();
            $total = ($dropzone->getCriteriaTotal() - 1) * count($criteria);
            $grades = $correction->getGrades();

            foreach ($criteria as $criterion) {
                $criteriaIds[] = $criterion->getUuid();
            }
            foreach ($grades as $grade) {
                $gradeCriterion = $grade->getCriterion();

                if (in_array($gradeCriterion->getUuid(), $criteriaIds)) {
                    $score += $grade->getValue();
                }
            }
            $score = round(($score / $total) * $scoreMax, 2);
            $correction->setScore($score);
        }
        $this->om->persist($correction);
        $this->om->flush();

        return $correction;
    }
1011658
public function score(array $predictions, array $labels) : float
    {
        if (empty($predictions)) {
            return 0.;
        }

        $n = count($predictions);

        if ($n !== count($labels)) {
            throw new InvalidArgumentException('The number of labels'
                . ' must equal the number of predictions.');
        }

        $table = Matrix::build((new ContingencyTable())->generate($predictions, $labels));

        $sigma = $table->map([self::class, 'comb'])->sum()->sum();

        $alpha = $table->sum()->map([self::class, 'comb'])->sum();
        $beta = $table->transpose()->sum()->map([self::class, 'comb'])->sum();

        $pHat = ($alpha * $beta) / self::comb($n);
        $mean = ($alpha + $beta) / 2.;

        return ($sigma - $pHat) / ($mean - $pHat);
    }
174168
public function deleteCorrection(Correction $correction)
    {
        $this->om->startFlushSuite();

        $drop = $correction->getDrop();
        $drop->removeCorrection($correction);
        $this->om->remove($correction);
        $drop = $this->computeDropScore($drop);
        $this->checkSuccess($drop);

        $this->om->endFlushSuite();

        $this->eventDispatcher->dispatch('log', new LogCorrectionDeleteEvent($correction->getDrop()->getDropzone(), $drop, $correction));
    }
754269
public function score(Learner $estimator, Labeled $dataset) : float
    {
        return $this->validator->test($estimator, $dataset, $this->metric);
    }
702221
public function calculateScore(Item $question, Answer $answer)
    {
        // Let the question correct the answer
        $definition = $this->itemDefinitions->get($question->getMimeType());
        /** @var AnswerableItemDefinitionInterface $definition */
        $corrected = $definition->correctAnswer($question->getInteraction(), json_decode($answer->getData(), true));
        if (!$corrected instanceof CorrectedAnswer) {
            $corrected = new CorrectedAnswer();
        }

        // Add hints
        foreach ($answer->getUsedHints() as $hintId) {
            // Get hint definition from question data
            $hint = null;
            foreach ($question->getHints() as $questionHint) {
                if ($hintId === $questionHint->getUuid()) {
                    $hint = $questionHint;
                    break;
                }
            }
            if ($hint) {
                $corrected->addPenalty($hint);
            }
        }

        return $this->scoreManager->calculate(json_decode($question->getScoreRule(), true), $corrected);
    }
665890
public function validate($value) {
        if(filter_var($value, FILTER_VALIDATE_FLOAT, array('options' => array('decimal' => $this->decimal)))===false) {
            return new ValidationResult(false, 'Not a floating point value');
        }        
        return new ValidationResult(true);
    }
108093
private function getValidRotationAmount($rotationAmount)
    {
        $rotationAmount = (int) $rotationAmount;

        $alphabetSize = $this->getAlphabetSize();

        if ($rotationAmount < 0) {
            $rotationAmount += (int) ceil(-1 * $rotationAmount / $alphabetSize) * $alphabetSize;
        }

        return $rotationAmount;
    }
516734
protected function getNormalizedPosition($pos)
    {
        if ($pos >= strlen($this->account) || $pos < -strlen($this->account)) {
            throw new ValidatorOutOfBoundsException("Cannot access offset $pos in String $this->account");

        }

        if ($pos >= 0) {
            return $pos;

        }
        return strlen($this->account) + $pos;
    }
505549
public function scoring($field = null, $weight = 1, $ascending = false, $type = self::SCORING_FIELD_ORDER) {
		if(empty($this->data['scorings'])) {
			$this->data['scorings'] = array();
		}
		$newScoring = array(
			'ascending' => (boolean) $ascending,
			'type' => $type,
			'weight' => $weight
		);
		if(!empty($field)) {
			$newScoring['field'] = $field;
		}
		$this->data['scorings'][] = $newScoring;
		return $this;
	}
964703
protected function validate_grade($value) {
        if ($value !== null && $value <= 0) {
            return new lang_string('invalidgrade', 'core_competency');
        }

        $action = $this->get('action');
        if ($value === null && $action == self::ACTION_COMPLETE) {
            return new lang_string('invalidgrade', 'core_competency');

        } else if ($value !== null && $action == self::ACTION_LOG) {
            return new lang_string('invalidgrade', 'core_competency');
        }

        if ($value !== null) {
            // TODO MDL-52243 Use a core method to validate the grade_scale item.
            // Check if grade exist in the scale item values.
            $competency = $this->get_competency();
            if (!array_key_exists($value - 1, $competency->get_scale()->scale_items)) {
                return new lang_string('invalidgrade', 'core_competency');
            }
        }

        return true;
    }
568008
public function validate($data, QuestionInterface $question, ScoreInterface $score)
    {
        $answersValid = array();

        foreach ($question->getAnswers() as $answer) {
            if ($answer->isValid()) {
                $answersValid[] = $answer->getId();
            }
        }

        $tooManyAnswers = array_diff($data, $answersValid);

        if (!empty($tooManyAnswers)) {
            $score->addNotValid();

            return false;
        }

        $answerCompare = array_diff($answersValid, $data);

        if (empty($answersValid) && !empty($data)) {
            $score->addNotValid();

            return false;
        }

        if (count($answerCompare) === 0) {
            $score->addValid();
        } else if (count($answersValid) === count($answerCompare)) {
            $score->addNotValid();

            return false;
        } else if (count($answersValid) > count($answerCompare)) {
            $score->addPartial();

            return false;
        }

        return true;
    }
651296
public function score(array $predictions, array $labels) : float
    {
        if (empty($predictions)) {
            return 0.;
        }

        $homogeneity = (new Homogeneity())->score($predictions, $labels);
        $completeness = (new Completeness())->score($predictions, $labels);

        return 2. * ($homogeneity * $completeness)
            / ($homogeneity + $completeness);
    }
423812
public function track($grade_grade) {

        if (empty($grade_grade->exported) or empty($grade_grade->timemodified)) {
            if (is_null($grade_grade->finalgrade)) {
                // grade does not exist yet
                $status = 'unknown';
            } else {
                $status = 'new';
                $this->update_list[] = $grade_grade->id;
            }

        } else if ($grade_grade->exported < $grade_grade->timemodified) {
            $status = 'regrade';
            $this->update_list[] = $grade_grade->id;

        } else if ($grade_grade->exported >= $grade_grade->timemodified) {
            $status = 'nochange';

        } else {
            // something is wrong?
            $status = 'unknown';
        }

        $this->flush(100);

        return $status;
    }
488686
private function activity_format_grade($grade) {
        if (is_null($grade)) {
            return get_string('notyetgraded', 'block_activity_results');
        }
        return format_float($grade, $this->config->decimalpoints);
    }
665149
private function sanitizeScore($score)
    {
        $sanitized = ['type' => $score['type']];

        switch ($score['type']) {
            case 'fixed':
                $sanitized['success'] = $score['success'];
                $sanitized['failure'] = $score['failure'];
                break;

            case 'manual':
                $sanitized['max'] = $score['max'];
                break;

            case 'rules':
                $sanitized['noWrongChoice'] = isset($score['noWrongChoice']) ? $score['noWrongChoice'] : false;
                $sanitized['rules'] = $score['rules'];
                break;
        }

        return $sanitized;
    }
821418
public function get_calculation() {
        if ($this->is_calculated()) {
            return grade_item::denormalize_formula($this->calculation, $this->courseid);

        } else {
            return NULL;
        }
    }
892653
public function applyPenalties($score, CorrectedAnswer $correctedAnswer)
    {
        $penalties = $correctedAnswer->getPenalties();
        foreach ($penalties as $penalty) {
            $score -= $penalty->getPenalty();
        }

        return $score;
    }