public function test_set_var() {
     $step = new question_attempt_step();
     $step->set_qt_var('_x', 1);
     $step->set_behaviour_var('_x', 2);
     $this->assertEquals('1', $step->get_qt_var('_x'));
     $this->assertEquals('2', $step->get_behaviour_var('_x'));
 }
Example #2
0
    /**
     * Checks whether two manual grading actions are the same. That is, whether
     * the comment, and the mark (if given) is the same.
     *
     * @param question_attempt_step $pendingstep contains the new responses.
     * @return bool whether the new response is the same as we already have.
     */
    protected function is_same_comment($pendingstep) {
        $previouscomment = $this->qa->get_last_behaviour_var('comment');
        $newcomment = $pendingstep->get_behaviour_var('comment');

        if (is_null($previouscomment) && !html_is_blank($newcomment) ||
                $previouscomment != $newcomment) {
            return false;
        }

        // So, now we know the comment is the same, so check the mark, if present.
        $previousfraction = $this->qa->get_fraction();
        $newmark = $pendingstep->get_behaviour_var('mark');

        if (is_null($previousfraction)) {
            return is_null($newmark) || $newmark === '';
        } else if (is_null($newmark) || $newmark === '') {
            return false;
        }

        $newfraction = $newmark / $pendingstep->get_behaviour_var('maxmark');

        return abs($newfraction - $previousfraction) < 0.0000001;
    }
 public function apply_attempt_state(question_attempt_step $step)
 {
     if ($step->has_behaviour_var('_applypenalties')) {
         $this->applypenalties = (bool) $step->get_behaviour_var('_applypenalties');
     }
     parent::apply_attempt_state($step);
 }
Example #4
0
    protected function do_grading(question_attempt_step $responsesstep,
            question_attempt_pending_step $pendingstep) {
        if (!$this->question->is_gradable_response($responsesstep->get_qt_data())) {
            $pendingstep->set_state(question_state::$gaveup);

        } else {
            $response = $responsesstep->get_qt_data();
            list($fraction, $state) = $this->question->grade_response($response);

            if ($responsesstep->has_behaviour_var('certainty')) {
                $certainty = $responsesstep->get_behaviour_var('certainty');
            } else {
                $certainty = question_cbm::default_certainty();
                $pendingstep->set_behaviour_var('_assumedcertainty', $certainty);
            }

            $pendingstep->set_behaviour_var('_rawfraction', $fraction);
            $pendingstep->set_fraction(question_cbm::adjust_fraction($fraction, $certainty));
            $pendingstep->set_state($state);
            $pendingstep->set_new_response_summary(question_cbm::summary_with_certainty(
                    $this->question->summarise_response($response),
                    $responsesstep->get_behaviour_var('certainty')));
        }
        return question_attempt::KEEP;
    }
Example #5
0
    /**
     * Actually populate the qbehaviour_adaptive_mark_details object.
     * @param question_attempt_step $gradedstep the step that holds the relevant mark details.
     * @param question_state $state the state corresponding to $gradedstep.
     * @param unknown_type $maxmark the maximum mark for this question_attempt.
     * @param unknown_type $penalty the penalty for this question, as a fraction.
     */
    protected function adaptive_mark_details_from_step(question_attempt_step $gradedstep,
            question_state $state, $maxmark, $penalty) {

        $details = new qbehaviour_adaptive_mark_details($state);
        $details->maxmark    = $maxmark;
        $details->actualmark = $gradedstep->get_fraction() * $details->maxmark;
        $details->rawmark    = $gradedstep->get_behaviour_var('_rawfraction') * $details->maxmark;

        $details->currentpenalty = $penalty * $details->maxmark;
        $details->totalpenalty   = $details->currentpenalty * $this->qa->get_last_behaviour_var('_try', 0);

        $details->improvable = $this->is_state_improvable($gradedstep->get_state());

        return $details;
    }