Skip to content

Commit

Permalink
MDL-28219 QE2 adaptive behaviour: fix scores and penalties
Browse files Browse the repository at this point in the history
  • Loading branch information
bostelm committed Oct 12, 2011
1 parent 6731a04 commit cc9fc64
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 43 deletions.
73 changes: 54 additions & 19 deletions question/behaviour/adaptive/behaviour.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,24 @@ public function process_submit(question_attempt_pending_step $pendingstep) {
return $status;
}

$prevstep = $this->qa->get_last_step_with_behaviour_var('_try');
$prevresponse = $prevstep->get_qt_data();
$prevtries = $this->qa->get_last_behaviour_var('_try', 0);
$prevbest = $pendingstep->get_fraction();
if (is_null($prevbest)) {
$prevbest = 0;
}

if ($this->question->is_same_response($response, $prevresponse)) {
return question_attempt::DISCARD;
}

list($fraction, $state) = $this->question->grade_response($response);

$pendingstep->set_fraction(max($prevbest, $this->adjusted_fraction($fraction, $prevtries)));
if ($state == question_state::$gradedright) {
if ($prevstep->get_state() == question_state::$complete) {
$pendingstep->set_state(question_state::$complete);
} else if ($state == question_state::$gradedright) {
$pendingstep->set_state(question_state::$complete);
} else {
$pendingstep->set_state(question_state::$todo);
Expand All @@ -153,32 +161,59 @@ public function process_finish(question_attempt_pending_step $pendingstep) {
return question_attempt::DISCARD;
}

$laststep = $this->qa->get_last_step();
$response = $laststep->get_qt_data();
if (!$this->question->is_gradable_response($response)) {
$pendingstep->set_state(question_state::$gaveup);
return question_attempt::KEEP;
}

$prevtries = $this->qa->get_last_behaviour_var('_try', 0);
$prevbest = $pendingstep->get_fraction();
$prevbest = $this->qa->get_fraction();
if (is_null($prevbest)) {
$prevbest = 0;
}

if ($laststep->has_behaviour_var('_try')) {
// Last answer was graded, we want to regrade it. Otherwise the answer
// has changed, and we are grading a new try.
$prevtries -= 1;
}
$laststep = $this->qa->get_last_step();
$response = $laststep->get_qt_data();
if (!$this->question->is_gradable_response($response)) {
$state = question_state::$gaveup;
$fraction = 0;
} else {

list($fraction, $state) = $this->question->grade_response($response);
if ($laststep->has_behaviour_var('_try')) {
// Last answer was graded, we want to regrade it. Otherwise the answer
// has changed, and we are grading a new try.
$prevtries -= 1;
}

list($fraction, $state) = $this->question->grade_response($response);

$pendingstep->set_behaviour_var('_try', $prevtries + 1);
$pendingstep->set_behaviour_var('_rawfraction', $fraction);
$pendingstep->set_new_response_summary($this->question->summarise_response($response));
}

$pendingstep->set_fraction(max($prevbest, $this->adjusted_fraction($fraction, $prevtries)));
$pendingstep->set_state($state);
$pendingstep->set_behaviour_var('_try', $prevtries + 1);
$pendingstep->set_behaviour_var('_rawfraction', $fraction);
$pendingstep->set_new_response_summary($this->question->summarise_response($response));
$pendingstep->set_fraction(max($prevbest, $this->adjusted_fraction($fraction, $prevtries)));
return question_attempt::KEEP;
}

/**
* Got the most recently graded step. This is mainly intended for use by the
* renderer.
* @return question_attempt_step the most recently graded step.
*/
public function get_graded_step() {
$step = $this->qa->get_last_step_with_behaviour_var('_try');
if ($step->has_behaviour_var('_try')) {
return $step;
} else {
return null;
}
}

/**
* Determine whether a question state represents an "improvable" result,
* that is, whether the user can still improve their score.
*
* @param question_state $state the question state.
* @return bool whether the state is improvable
*/
public function is_state_improvable(question_state $state) {
return $state == question_state::$todo;
}
}
16 changes: 4 additions & 12 deletions question/behaviour/adaptive/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qbehaviour_adaptive_renderer extends qbehaviour_renderer {
protected function get_graded_step(question_attempt $qa) {
foreach ($qa->get_reverse_step_iterator() as $step) {
if ($step->has_behaviour_var('_try')) {
return $step;
}
}
}

public function controls(question_attempt $qa, question_display_options $options) {
return $this->submit_button($qa, $options);
Expand All @@ -51,7 +44,7 @@ public function controls(question_attempt $qa, question_display_options $options
public function feedback(question_attempt $qa, question_display_options $options) {
// Try to find the last graded step.

$gradedstep = $this->get_graded_step($qa);
$gradedstep = $qa->get_behaviour()->get_graded_step($qa);
if (is_null($gradedstep) || $qa->get_max_mark() == 0 ||
$options->marks < question_display_options::MARK_AND_MAX) {
return '';
Expand Down Expand Up @@ -100,14 +93,13 @@ protected function penalty_info(question_attempt $qa, $mark,
}
$output = '';

// print details of grade adjustment due to penalties
// Print details of grade adjustment due to penalties
if ($mark->raw != $mark->cur) {
$output .= ' ' . get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark);
}

// print info about new penalty
// penalty is relevant only if the answer is not correct and further attempts are possible
if (!$qa->get_state()->is_finished()) {
// Print information about any new penalty, only relevant if the answer can be improved.
if ($qa->get_behaviour()->is_state_improvable($qa->get_state())) {
$output .= ' ' . get_string('gradingdetailspenalty', 'qbehaviour_adaptive',
format_float($qa->get_question()->penalty, $options->markdp));
}
Expand Down
Loading

0 comments on commit cc9fc64

Please sign in to comment.