Skip to content

Commit

Permalink
GH-791 Remove checkitemparams preselect-task
Browse files Browse the repository at this point in the history
This removes the checkitemparams.php preselect-task middleware and makes it a normal method of the strategy class.
  • Loading branch information
davidszkiba committed Dec 23, 2024
1 parent 4c7cbd3 commit c09238d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 108 deletions.
94 changes: 0 additions & 94 deletions classes/teststrategy/preselect_task/checkitemparams.php

This file was deleted.

54 changes: 52 additions & 2 deletions classes/teststrategy/strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
use coding_exception;
use Exception;
use dml_exception;
use local_catquiz\catquiz;
use local_catquiz\catscale;
use local_catquiz\local\model\model_item_param_list;
use local_catquiz\local\model\model_strategy;
use local_catquiz\local\result;
use local_catquiz\local\status;
use local_catquiz\output\attemptfeedback;
Expand All @@ -38,7 +39,6 @@
use local_catquiz\teststrategy\progress;
use local_catquiz\wb_middleware_runner;
use moodle_exception;
use stdClass;

/**
* Base class for test strategies.
Expand Down Expand Up @@ -83,6 +83,18 @@ abstract class strategy {
*/
protected progress $progress;

/**
* These data provide the context for the selection of the next question.
*
* In a previous implementation, this object was passed between middlewares
* and allowed them to decide what to do.
* It would be good to refactor this in such a way that the different
* elements of this array become class properties of this (strategy) class.
*
* @var array
*/
protected array $context;

/**
* Instantioate parameters.
*/
Expand Down Expand Up @@ -125,6 +137,7 @@ public function get_description(): string {
*
*/
public function return_next_testitem(array $context) {
$this->context = $context;
$cache = cache::make('local_catquiz', 'adaptivequizattempt');
$maxtime = $context['progress']->get_starttime() + $context['max_attempttime_in_sec'];
if (time() > $maxtime) {
Expand All @@ -137,6 +150,12 @@ public function return_next_testitem(array $context) {
return result::err(status::EXCEEDED_MAX_ATTEMPT_TIME);
}

try {
$this->check_item_params();
} catch (Exception $e) {
return result::err($e->getMessage());
}

foreach ($this->get_preselecttasks() as $modifier) {
// When this is called for running tests, check if there is a
// X_testing class and if so, use that one.
Expand Down Expand Up @@ -288,4 +307,35 @@ abstract public function select_scales_for_report(
int $catscaleid = 0,
bool $feedbackonlyfordefinedscaleid = false
): array;

/**
* Checks if there are item params for the given combination of scale and context
*/
protected function check_item_params() {
$selectedscales = [$this->context['catscaleid'], ...$this->context['progress']->get_selected_subscales()];
foreach ($selectedscales as $catscaleid) {
$catscalecontext = catscale::get_context_id($catscaleid);
$catscaleids = [
$catscaleid,
...catscale::get_subscale_ids($catscaleid),
];
$itemparamlists = [];
foreach (array_keys(model_strategy::get_installed_models()) as $model) {
$itemparamlists[$model] = model_item_param_list::get(
$catscalecontext,
$model,
$catscaleids
)->count();
}
if (array_sum($itemparamlists) === 0) {
$this->context['progress']->drop_scale($catscaleid);
unset($selectedscales[array_search($catscaleid, $selectedscales)]);
}
}

// If there are no active scales left, show a message that the quiz can not be started.
if (!$selectedscales) {
throw new Exception(status::ERROR_NO_ITEMS);
}
}
}
2 changes: 0 additions & 2 deletions classes/teststrategy/strategy/classicalcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use local_catquiz\teststrategy\feedbacksettings;
use local_catquiz\teststrategy\preselect_task\addscalestandarderror;
use local_catquiz\teststrategy\preselect_task\checkbreak;
use local_catquiz\teststrategy\preselect_task\checkitemparams;
use local_catquiz\teststrategy\preselect_task\checkpagereload;
use local_catquiz\teststrategy\preselect_task\fisherinformation;
use local_catquiz\teststrategy\preselect_task\maximumquestionscheck;
Expand Down Expand Up @@ -77,7 +76,6 @@ class classicalcat extends strategy {
*/
public function get_preselecttasks(): array {
return [
checkitemparams::class,
checkbreak::class,
checkpagereload::class,
updatepersonability::class,
Expand Down
2 changes: 0 additions & 2 deletions classes/teststrategy/strategy/inferallsubscales.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use local_catquiz\teststrategy\feedbacksettings;
use local_catquiz\teststrategy\preselect_task\addscalestandarderror;
use local_catquiz\teststrategy\preselect_task\checkbreak;
use local_catquiz\teststrategy\preselect_task\checkitemparams;
use local_catquiz\teststrategy\preselect_task\checkpagereload;
use local_catquiz\teststrategy\preselect_task\filterbyquestionsperscale;
use local_catquiz\teststrategy\preselect_task\filterbystandarderror;
Expand Down Expand Up @@ -87,7 +86,6 @@ class inferallsubscales extends strategy {
*/
public function get_preselecttasks(): array {
return [
checkitemparams::class,
checkbreak::class,
updatepersonability::class,
firstquestionselector::class, // If this is the first question of this attempt, return it here.
Expand Down
2 changes: 0 additions & 2 deletions classes/teststrategy/strategy/infergreateststrength.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use local_catquiz\teststrategy\feedbacksettings;
use local_catquiz\teststrategy\preselect_task\addscalestandarderror;
use local_catquiz\teststrategy\preselect_task\checkbreak;
use local_catquiz\teststrategy\preselect_task\checkitemparams;
use local_catquiz\teststrategy\preselect_task\checkpagereload;
use local_catquiz\teststrategy\preselect_task\filterbystandarderror;
use local_catquiz\teststrategy\preselect_task\filterbytestinfo;
Expand Down Expand Up @@ -92,7 +91,6 @@ class infergreateststrength extends strategy {
*/
public function get_preselecttasks(): array {
return [
checkitemparams::class,
checkbreak::class,
updatepersonability::class,
firstquestionselector::class, // If this is the first question of this attempt, return it here.
Expand Down
2 changes: 0 additions & 2 deletions classes/teststrategy/strategy/inferlowestskillgap.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use local_catquiz\teststrategy\feedbacksettings;
use local_catquiz\teststrategy\preselect_task\addscalestandarderror;
use local_catquiz\teststrategy\preselect_task\checkbreak;
use local_catquiz\teststrategy\preselect_task\checkitemparams;
use local_catquiz\teststrategy\preselect_task\checkpagereload;
use local_catquiz\teststrategy\preselect_task\filterbystandarderror;
use local_catquiz\teststrategy\preselect_task\filterbytestinfo;
Expand Down Expand Up @@ -86,7 +85,6 @@ class inferlowestskillgap extends strategy {
*/
public function get_preselecttasks(): array {
return [
checkitemparams::class,
checkbreak::class,
updatepersonability::class,
firstquestionselector::class, // If this is the first question of this attempt, return it here.
Expand Down
2 changes: 0 additions & 2 deletions classes/teststrategy/strategy/relevantscales.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use local_catquiz\teststrategy\feedbacksettings;
use local_catquiz\teststrategy\preselect_task\addscalestandarderror;
use local_catquiz\teststrategy\preselect_task\checkbreak;
use local_catquiz\teststrategy\preselect_task\checkitemparams;
use local_catquiz\teststrategy\preselect_task\checkpagereload;
use local_catquiz\teststrategy\preselect_task\filterbystandarderror;
use local_catquiz\teststrategy\preselect_task\filterbytestinfo;
Expand Down Expand Up @@ -86,7 +85,6 @@ class relevantscales extends strategy {
*/
public function get_preselecttasks(): array {
return [
checkitemparams::class,
checkbreak::class,
updatepersonability::class,
firstquestionselector::class, // If this is the first question of this attempt, return it here.
Expand Down
2 changes: 0 additions & 2 deletions classes/teststrategy/strategy/teststrategy_fastest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use local_catquiz\teststrategy\feedbacksettings;
use local_catquiz\teststrategy\preselect_task\addscalestandarderror;
use local_catquiz\teststrategy\preselect_task\checkbreak;
use local_catquiz\teststrategy\preselect_task\checkitemparams;
use local_catquiz\teststrategy\preselect_task\checkpagereload;
use local_catquiz\teststrategy\preselect_task\filterbystandarderror;
use local_catquiz\teststrategy\preselect_task\firstquestionselector;
Expand Down Expand Up @@ -81,7 +80,6 @@ class teststrategy_fastest extends strategy {
*/
public function get_preselecttasks(): array {
return [
checkitemparams::class,
checkbreak::class,
checkpagereload::class,
firstquestionselector::class,
Expand Down

0 comments on commit c09238d

Please sign in to comment.