Merge branch 'MDL-87182-main' of https://github.com/srobotta/moodle

This commit is contained in:
Mihail Geshoski
2025-12-12 09:43:38 +07:00
committed by Huong Nguyen
2 changed files with 31 additions and 2 deletions
@@ -48,7 +48,8 @@ class qbehaviour_deferredcbm_type extends qbehaviour_deferredfeedback_type {
}
// Prepare accumulators to hold the data we are about to collect.
$notansweredcount = 0;
$totalquestions = 0;
$notansweredcount = 0;
$notansweredweight = 0;
$attemptcount = array(
question_cbm::HIGH => 0,
@@ -76,6 +77,7 @@ class qbehaviour_deferredcbm_type extends qbehaviour_deferredfeedback_type {
if (strpos($qa->get_behaviour_name(), 'cbm') === false || $qa->get_max_mark() < 0.0000005) {
continue;
}
$totalquestions += 1;
$gradedstep = $qa->get_last_step_with_behaviour_var('_rawfraction');
@@ -100,8 +102,12 @@ class qbehaviour_deferredcbm_type extends qbehaviour_deferredfeedback_type {
$totalcbmscore[$certainty] += $qa->get_mark();
}
// Did we find any CBM questions? If not, just quit here.
if ($totalquestions === 0) {
return $summarydata;
}
// Hence compute some statistics.
$totalquestions = $notansweredcount + array_sum($attemptcount);
$grandtotalweight = $notansweredweight + array_sum($totalweight);
$accuracy = array_sum($totalrawscore) / $grandtotalweight;
$averagecbm = array_sum($totalcbmscore) / $grandtotalweight;
@@ -134,6 +134,29 @@ final class behaviour_type_test extends \qbehaviour_walkthrough_test_base {
$summarydata['qbehaviour_cbm_judgement1']['content']);
}
/**
* Test that CBM summary is not shown when there are no CBM questions in the attempt.
* @covers \qbehaviour_deferredcbm_type::summarise_usage
*/
public function test_summarise_usage_no_cbm_questions(): void {
// Create a usage comprising 2 essay questions.
$this->quba->set_preferred_behaviour('deferredcbm');
$this->quba->add_question(\test_question_maker::make_an_essay_question(), 1);
$this->quba->add_question(\test_question_maker::make_an_essay_question(), 1);
$this->quba->start_all_questions();
// Process responses right, high certainty; right, med certainty; wrong, med certainty.
$this->quba->process_action(1, ['answer' => 'essay answer1', 'answerformat' => FORMAT_PLAIN]);
$this->quba->process_action(2, ['answer' => 'essay answer2', 'answerformat' => FORMAT_PLAIN]);
$this->quba->finish_all_questions();
// Get the summary.
$summarydata = $this->quba->get_summary_information(new question_display_options());
// Verify that there is no CBM summary.
$this->assertArrayNotHasKey('qbehaviour_cbm_entire_quiz_heading', $summarydata);
}
public function test_calculate_bonus(): void {
$this->assertEqualsWithDelta(0.05, $this->behaviourtype->calculate_bonus(1, 1 / 2), question_testcase::GRADE_DELTA);
$this->assertEqualsWithDelta(-0.01, $this->behaviourtype->calculate_bonus(2, 9 / 10), question_testcase::GRADE_DELTA);