mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
MDL-84107 core_analytics: Switch PHPUnit to use Python backend
This commit is contained in:
parent
2aeef38c7b
commit
5dc4290eba
@ -53,9 +53,13 @@ class admin_setting_predictor extends \admin_setting_configselect {
|
||||
|
||||
// Calling it here without checking if it is ready because we check it below and show it as a controlled case.
|
||||
$selectedprocessor = \core_analytics\manager::get_predictions_processor($data, false);
|
||||
$isready = $selectedprocessor->is_ready();
|
||||
if ($isready !== true) {
|
||||
return get_string('errorprocessornotready', 'analytics', $isready);
|
||||
|
||||
if (!during_initial_install() && !moodle_needs_upgrading()) {
|
||||
// TODO: Do not check if the processor is ready during installation or upgrade. See MDL-84481.
|
||||
$isready = $selectedprocessor->is_ready();
|
||||
if ($isready !== true) {
|
||||
return get_string('errorprocessornotready', 'analytics', $isready);
|
||||
}
|
||||
}
|
||||
|
||||
$currentvalue = get_config('analytics', 'predictionsprocessor');
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core_analytics\tests;
|
||||
|
||||
/**
|
||||
* A trait to check machine learning configurations.
|
||||
*
|
||||
* @package core_analytics
|
||||
* @category test
|
||||
* @copyright 2024 David Woloszyn <david.woloszyn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
trait mlbackend_configuration_trait {
|
||||
/**
|
||||
* Check if mlbackend_python is configured.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_mlbackend_python_configured(): bool {
|
||||
if (defined('TEST_MLBACKEND_PYTHON_HOST') && defined('TEST_MLBACKEND_PYTHON_PORT')
|
||||
&& defined('TEST_MLBACKEND_PYTHON_USERNAME') && defined('TEST_MLBACKEND_PYTHON_USERNAME')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
77
analytics/tests/classes/mlbackend_helper_trait.php
Normal file
77
analytics/tests/classes/mlbackend_helper_trait.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core_analytics\tests;
|
||||
|
||||
use phpunit_util;
|
||||
|
||||
/**
|
||||
* A trait to check machine learning configurations.
|
||||
*
|
||||
* @package core_analytics
|
||||
* @category test
|
||||
* @copyright 2024 David Woloszyn <david.woloszyn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
trait mlbackend_helper_trait {
|
||||
/**
|
||||
* Check if mlbackend_python is configured.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_mlbackend_python_configured(): bool {
|
||||
if (defined('TEST_MLBACKEND_PYTHON_HOST') && defined('TEST_MLBACKEND_PYTHON_PORT')
|
||||
&& defined('TEST_MLBACKEND_PYTHON_USERNAME') && defined('TEST_MLBACKEND_PYTHON_USERNAME')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate test courses.
|
||||
*
|
||||
* @param int $ncourses Number of courses to generate.
|
||||
* @param array $params Additional parameters for the courses.
|
||||
* @param bool $ismulticlass Whether to generate courses for multi-classification.
|
||||
*/
|
||||
public function generate_courses(
|
||||
int $ncourses,
|
||||
array $params = [],
|
||||
bool $ismulticlass = false,
|
||||
): void {
|
||||
$params = $params + [
|
||||
'startdate' => mktime(0, 0, 0, 10, 24, 2015),
|
||||
'enddate' => mktime(0, 0, 0, 2, 24, 2016),
|
||||
];
|
||||
for ($i = 0; $i < $ncourses; $i++) {
|
||||
$name = 'a' . random_string(10);
|
||||
$courseparams = ['shortname' => $name, 'fullname' => $name] + $params;
|
||||
phpunit_util::get_data_generator()->create_course($courseparams);
|
||||
}
|
||||
for ($i = 0; $i < $ncourses; $i++) {
|
||||
$name = 'b' . random_string(10);
|
||||
$courseparams = ['shortname' => $name, 'fullname' => $name] + $params;
|
||||
phpunit_util::get_data_generator()->create_course($courseparams);
|
||||
}
|
||||
if ($ismulticlass) {
|
||||
for ($i = 0; $i < $ncourses; $i++) {
|
||||
$name = 'c' . random_string(10);
|
||||
$courseparams = ['shortname' => $name, 'fullname' => $name] + $params;
|
||||
phpunit_util::get_data_generator()->create_course($courseparams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
|
||||
namespace core_analytics;
|
||||
|
||||
use core_analytics\tests\mlbackend_configuration_trait;
|
||||
use core_analytics\tests\mlbackend_helper_trait;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -34,7 +34,7 @@ require_once(__DIR__ . '/fixtures/test_target_course_level_shortname.php');
|
||||
* @covers \core_analytics\manager
|
||||
*/
|
||||
final class manager_test extends \advanced_testcase {
|
||||
use mlbackend_configuration_trait;
|
||||
use mlbackend_helper_trait;
|
||||
|
||||
/**
|
||||
* test_deleted_context
|
||||
@ -50,6 +50,10 @@ final class manager_test extends \advanced_testcase {
|
||||
$this->setAdminuser();
|
||||
set_config('enabled_stores', 'logstore_standard', 'tool_log');
|
||||
|
||||
// Create some courses.
|
||||
$this->generate_courses(2, ['visible' => 0]);
|
||||
$this->generate_courses(2, ['visible' => 1]);
|
||||
|
||||
$target = \core_analytics\manager::get_target('test_target_course_level_shortname');
|
||||
$indicators = ['test_indicator_max', 'test_indicator_min', 'test_indicator_fullname'];
|
||||
foreach ($indicators as $key => $indicator) {
|
||||
@ -59,11 +63,6 @@ final class manager_test extends \advanced_testcase {
|
||||
$model = \core_analytics\model::create($target, $indicators);
|
||||
$modelobj = $model->get_model_obj();
|
||||
|
||||
$coursepredict1 = $this->getDataGenerator()->create_course(['visible' => 0]);
|
||||
$coursepredict2 = $this->getDataGenerator()->create_course(['visible' => 0]);
|
||||
$coursetrain1 = $this->getDataGenerator()->create_course(['visible' => 1]);
|
||||
$coursetrain2 = $this->getDataGenerator()->create_course(['visible' => 1]);
|
||||
|
||||
$model->enable('\core\analytics\time_splitting\no_splitting');
|
||||
|
||||
$model->train();
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
namespace core_analytics;
|
||||
|
||||
use core_analytics\tests\mlbackend_configuration_trait;
|
||||
use core_analytics\tests\mlbackend_helper_trait;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -44,7 +44,7 @@ require_once(__DIR__ . '/fixtures/test_analysis.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
final class model_test extends \advanced_testcase {
|
||||
use mlbackend_configuration_trait;
|
||||
use mlbackend_helper_trait;
|
||||
|
||||
/** @var model Store Model. */
|
||||
protected $model;
|
||||
@ -105,10 +105,9 @@ final class model_test extends \advanced_testcase {
|
||||
$this->resetAfterTest(true);
|
||||
set_config('enabled_stores', 'logstore_standard', 'tool_log');
|
||||
|
||||
$coursepredict1 = $this->getDataGenerator()->create_course(array('visible' => 0));
|
||||
$coursepredict2 = $this->getDataGenerator()->create_course(array('visible' => 0));
|
||||
$coursetrain1 = $this->getDataGenerator()->create_course(array('visible' => 1));
|
||||
$coursetrain2 = $this->getDataGenerator()->create_course(array('visible' => 1));
|
||||
// Create some courses.
|
||||
$this->generate_courses(2, ['visible' => 0]);
|
||||
$this->generate_courses(2, ['visible' => 1]);
|
||||
|
||||
$this->model->enable('\core\analytics\time_splitting\single_range');
|
||||
|
||||
@ -118,9 +117,6 @@ final class model_test extends \advanced_testcase {
|
||||
// Fake evaluation results record to check that it is actually deleted.
|
||||
$this->add_fake_log();
|
||||
|
||||
$modeloutputdir = $this->model->get_output_dir(array(), true);
|
||||
$this->assertTrue(is_dir($modeloutputdir));
|
||||
|
||||
// Generate a prediction action to confirm that it is deleted when there is an important update.
|
||||
$predictions = $DB->get_records('analytics_predictions');
|
||||
$prediction = reset($predictions);
|
||||
@ -135,7 +131,6 @@ final class model_test extends \advanced_testcase {
|
||||
$this->assertEmpty($DB->count_records('analytics_train_samples'));
|
||||
$this->assertEmpty($DB->count_records('analytics_predict_samples'));
|
||||
$this->assertEmpty($DB->count_records('analytics_used_files'));
|
||||
$this->assertFalse(is_dir($modeloutputdir));
|
||||
|
||||
set_config('enabled_stores', '', 'tool_log');
|
||||
get_log_manager(true);
|
||||
@ -154,10 +149,9 @@ final class model_test extends \advanced_testcase {
|
||||
$this->resetAfterTest(true);
|
||||
set_config('enabled_stores', 'logstore_standard', 'tool_log');
|
||||
|
||||
$coursepredict1 = $this->getDataGenerator()->create_course(array('visible' => 0));
|
||||
$coursepredict2 = $this->getDataGenerator()->create_course(array('visible' => 0));
|
||||
$coursetrain1 = $this->getDataGenerator()->create_course(array('visible' => 1));
|
||||
$coursetrain2 = $this->getDataGenerator()->create_course(array('visible' => 1));
|
||||
// Create some courses.
|
||||
$this->generate_courses(2, ['visible' => 0]);
|
||||
$this->generate_courses(2, ['visible' => 1]);
|
||||
|
||||
$this->model->enable('\core\analytics\time_splitting\single_range');
|
||||
|
||||
@ -178,7 +172,6 @@ final class model_test extends \advanced_testcase {
|
||||
|
||||
// Update to an empty time splitting method to force model::clear execution.
|
||||
$this->model->clear();
|
||||
$this->assertFalse(is_dir($modelversionoutputdir));
|
||||
|
||||
// Check that most of the stuff got deleted.
|
||||
$this->assertEquals(1, $DB->count_records('analytics_models', array('id' => $this->modelobj->id)));
|
||||
|
@ -31,6 +31,8 @@ require_once(__DIR__ . '/fixtures/test_static_target_shortname.php');
|
||||
|
||||
require_once(__DIR__ . '/../../course/lib.php');
|
||||
|
||||
use core_analytics\tests\mlbackend_helper_trait;
|
||||
|
||||
/**
|
||||
* Unit tests for evaluation, training and prediction.
|
||||
*
|
||||
@ -48,6 +50,8 @@ require_once(__DIR__ . '/../../course/lib.php');
|
||||
*/
|
||||
final class prediction_test extends \advanced_testcase {
|
||||
|
||||
use mlbackend_helper_trait;
|
||||
|
||||
/**
|
||||
* Purge all the mlbackend outputs.
|
||||
*
|
||||
@ -546,7 +550,7 @@ final class prediction_test extends \advanced_testcase {
|
||||
}
|
||||
// Generate training courses.
|
||||
$ncourses = 5;
|
||||
$this->generate_courses_multiclass($ncourses);
|
||||
$this->generate_courses(ncourses: $ncourses, ismulticlass: true);
|
||||
$model = $this->add_multiclass_model();
|
||||
$model->update(true, false, $timesplittingid, get_class($predictionsprocessor));
|
||||
$results = $model->train();
|
||||
@ -857,63 +861,6 @@ final class prediction_test extends \advanced_testcase {
|
||||
return new \core_analytics\model($model->get_id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates $ncourses courses
|
||||
*
|
||||
* @param int $ncourses The number of courses to be generated.
|
||||
* @param array $params Course params
|
||||
* @return null
|
||||
*/
|
||||
protected function generate_courses($ncourses, array $params = []) {
|
||||
|
||||
$params = $params + [
|
||||
'startdate' => mktime(0, 0, 0, 10, 24, 2015),
|
||||
'enddate' => mktime(0, 0, 0, 2, 24, 2016),
|
||||
];
|
||||
|
||||
for ($i = 0; $i < $ncourses; $i++) {
|
||||
$name = 'a' . random_string(10);
|
||||
$courseparams = array('shortname' => $name, 'fullname' => $name) + $params;
|
||||
$this->getDataGenerator()->create_course($courseparams);
|
||||
}
|
||||
for ($i = 0; $i < $ncourses; $i++) {
|
||||
$name = 'b' . random_string(10);
|
||||
$courseparams = array('shortname' => $name, 'fullname' => $name) + $params;
|
||||
$this->getDataGenerator()->create_course($courseparams);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates ncourses for multi-classification
|
||||
*
|
||||
* @param int $ncourses The number of courses to be generated.
|
||||
* @param array $params Course params
|
||||
* @return null
|
||||
*/
|
||||
protected function generate_courses_multiclass($ncourses, array $params = []) {
|
||||
|
||||
$params = $params + [
|
||||
'startdate' => mktime(0, 0, 0, 10, 24, 2015),
|
||||
'enddate' => mktime(0, 0, 0, 2, 24, 2016),
|
||||
];
|
||||
|
||||
for ($i = 0; $i < $ncourses; $i++) {
|
||||
$name = 'a' . random_string(10);
|
||||
$courseparams = array('shortname' => $name, 'fullname' => $name) + $params;
|
||||
$this->getDataGenerator()->create_course($courseparams);
|
||||
}
|
||||
for ($i = 0; $i < $ncourses; $i++) {
|
||||
$name = 'b' . random_string(10);
|
||||
$courseparams = array('shortname' => $name, 'fullname' => $name) + $params;
|
||||
$this->getDataGenerator()->create_course($courseparams);
|
||||
}
|
||||
for ($i = 0; $i < $ncourses; $i++) {
|
||||
$name = 'c' . random_string(10);
|
||||
$courseparams = array('shortname' => $name, 'fullname' => $name) + $params;
|
||||
$this->getDataGenerator()->create_course($courseparams);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces some configuration values.
|
||||
*
|
||||
|
@ -14,21 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for privacy.
|
||||
*
|
||||
* @package core_analytics
|
||||
* @copyright 2018 David Monllaó {@link http://www.davidmonllao.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_analytics\privacy;
|
||||
|
||||
use core_analytics\privacy\provider;
|
||||
use core_privacy\local\request\transform;
|
||||
use core_privacy\local\request\writer;
|
||||
use core_privacy\local\request\approved_contextlist;
|
||||
use core_privacy\local\request\approved_userlist;
|
||||
use core_analytics\tests\mlbackend_configuration_trait;
|
||||
use core_analytics\tests\mlbackend_helper_trait;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -45,7 +34,7 @@ require_once(__DIR__ . '/../fixtures/test_target_course_users.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
use mlbackend_configuration_trait;
|
||||
use mlbackend_helper_trait;
|
||||
|
||||
/** @var \core_analytics\model Store Model 1. */
|
||||
protected $model1;
|
||||
@ -83,6 +72,12 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
/** @var \stdClass $u8 User 8 record. */
|
||||
protected $u8;
|
||||
|
||||
/** @var \stdClass $u9 User 9 record. */
|
||||
protected $u9;
|
||||
|
||||
/** @var \stdClass $u10 User 10 record. */
|
||||
protected $u10;
|
||||
|
||||
/** @var \stdClass $c1 Course 1 record. */
|
||||
protected $c1;
|
||||
|
||||
@ -124,10 +119,13 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->u6 = $this->getdatagenerator()->create_user(['firstname' => 'a666666666666', 'lastname' => 'a']);
|
||||
$this->u7 = $this->getdatagenerator()->create_user(['firstname' => 'b777777777777', 'lastname' => 'b']);
|
||||
$this->u8 = $this->getDataGenerator()->create_user(['firstname' => 'b888888888888', 'lastname' => 'b']);
|
||||
$this->u9 = $this->getDataGenerator()->create_user(['firstname' => 'a999999999999', 'lastname' => 'a']);
|
||||
$this->u10 = $this->getDataGenerator()->create_user(['firstname' => 'b000000000000', 'lastname' => 'a']);
|
||||
|
||||
$this->c1 = $this->getDataGenerator()->create_course(['visible' => false]);
|
||||
$this->c2 = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Enrol users to course 1.
|
||||
$this->getDataGenerator()->enrol_user($this->u1->id, $this->c1->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u2->id, $this->c1->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u3->id, $this->c1->id, 'student');
|
||||
@ -136,6 +134,9 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->getDataGenerator()->enrol_user($this->u6->id, $this->c1->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u7->id, $this->c1->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u8->id, $this->c1->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u9->id, $this->c1->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u10->id, $this->c1->id, 'student');
|
||||
// Enrol users to course 2.
|
||||
$this->getDataGenerator()->enrol_user($this->u1->id, $this->c2->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u2->id, $this->c2->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u3->id, $this->c2->id, 'student');
|
||||
@ -144,6 +145,8 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->getDataGenerator()->enrol_user($this->u6->id, $this->c2->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u7->id, $this->c2->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u8->id, $this->c2->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u9->id, $this->c2->id, 'student');
|
||||
$this->getDataGenerator()->enrol_user($this->u10->id, $this->c2->id, 'student');
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
@ -174,7 +177,7 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$course2context = \context_course::instance($this->c2->id);
|
||||
$systemcontext = \context_system::instance();
|
||||
$expected = [$this->u1->id, $this->u2->id, $this->u3->id, $this->u4->id, $this->u5->id, $this->u6->id,
|
||||
$this->u7->id, $this->u8->id];
|
||||
$this->u7->id, $this->u8->id, $this->u9->id, $this->u10->id];
|
||||
|
||||
// Check users exist in the relevant contexts.
|
||||
$userlist = new \core_privacy\local\request\userlist($course1context, $component);
|
||||
@ -210,7 +213,7 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
|
||||
// We have 4 predictions for model1 and 8 predictions for model2.
|
||||
$this->assertEquals(12, $DB->count_records('analytics_predictions'));
|
||||
$this->assertEquals(26, $DB->count_records('analytics_indicator_calc'));
|
||||
$this->assertEquals(32, $DB->count_records('analytics_indicator_calc'));
|
||||
|
||||
// We have 1 prediction action.
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions'));
|
||||
@ -285,6 +288,8 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->u6->id => provider::get_contexts_for_userid($this->u6->id)->get_contextids(),
|
||||
$this->u7->id => provider::get_contexts_for_userid($this->u7->id)->get_contextids(),
|
||||
$this->u8->id => provider::get_contexts_for_userid($this->u8->id)->get_contextids(),
|
||||
$this->u9->id => provider::get_contexts_for_userid($this->u9->id)->get_contextids(),
|
||||
$this->u10->id => provider::get_contexts_for_userid($this->u10->id)->get_contextids(),
|
||||
];
|
||||
|
||||
foreach ($actualcontexts as $userid => $unused) {
|
||||
@ -295,7 +300,7 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
// Test initial record counts are as expected.
|
||||
$this->assertEquals(12, $DB->count_records('analytics_predictions'));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions'));
|
||||
$this->assertEquals(26, $DB->count_records('analytics_indicator_calc'));
|
||||
$this->assertEquals(32, $DB->count_records('analytics_indicator_calc'));
|
||||
|
||||
// Delete u1 and u3 from system context.
|
||||
$approveduserids = [$this->u1->id, $this->u3->id];
|
||||
@ -312,6 +317,8 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->u6->id => [$systemcontext->id, $course1context->id, $course2context->id],
|
||||
$this->u7->id => [$systemcontext->id, $course1context->id, $course2context->id],
|
||||
$this->u8->id => [$systemcontext->id, $course1context->id, $course2context->id],
|
||||
$this->u9->id => [$systemcontext->id, $course1context->id, $course2context->id],
|
||||
$this->u10->id => [$systemcontext->id, $course1context->id, $course2context->id],
|
||||
];
|
||||
|
||||
$actualcontexts = [
|
||||
@ -323,6 +330,8 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->u6->id => provider::get_contexts_for_userid($this->u6->id)->get_contextids(),
|
||||
$this->u7->id => provider::get_contexts_for_userid($this->u7->id)->get_contextids(),
|
||||
$this->u8->id => provider::get_contexts_for_userid($this->u8->id)->get_contextids(),
|
||||
$this->u9->id => provider::get_contexts_for_userid($this->u9->id)->get_contextids(),
|
||||
$this->u10->id => provider::get_contexts_for_userid($this->u10->id)->get_contextids(),
|
||||
];
|
||||
|
||||
foreach ($actualcontexts as $userid => $unused) {
|
||||
@ -334,11 +343,11 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
// Test expected number of records have been deleted.
|
||||
$this->assertEquals(11, $DB->count_records('analytics_predictions'));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions'));
|
||||
$this->assertEquals(24, $DB->count_records('analytics_indicator_calc'));
|
||||
$this->assertEquals(30, $DB->count_records('analytics_indicator_calc'));
|
||||
|
||||
// Delete for all 8 users in course 2 context.
|
||||
$approveduserids = [$this->u1->id, $this->u2->id, $this->u3->id, $this->u4->id, $this->u5->id, $this->u6->id,
|
||||
$this->u7->id, $this->u8->id];
|
||||
$this->u7->id, $this->u8->id, $this->u9->id, $this->u10->id];
|
||||
$approvedlist = new approved_userlist($course2context, $component, $approveduserids);
|
||||
provider::delete_data_for_users($approvedlist);
|
||||
|
||||
@ -352,6 +361,8 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->u6->id => [$systemcontext->id, $course1context->id],
|
||||
$this->u7->id => [$systemcontext->id, $course1context->id],
|
||||
$this->u8->id => [$systemcontext->id, $course1context->id],
|
||||
$this->u9->id => [$systemcontext->id, $course1context->id],
|
||||
$this->u10->id => [$systemcontext->id, $course1context->id],
|
||||
];
|
||||
|
||||
$actualcontexts = [
|
||||
@ -363,6 +374,8 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->u6->id => provider::get_contexts_for_userid($this->u6->id)->get_contextids(),
|
||||
$this->u7->id => provider::get_contexts_for_userid($this->u7->id)->get_contextids(),
|
||||
$this->u8->id => provider::get_contexts_for_userid($this->u8->id)->get_contextids(),
|
||||
$this->u9->id => provider::get_contexts_for_userid($this->u9->id)->get_contextids(),
|
||||
$this->u10->id => provider::get_contexts_for_userid($this->u10->id)->get_contextids(),
|
||||
];
|
||||
|
||||
foreach ($actualcontexts as $userid => $unused) {
|
||||
@ -374,7 +387,7 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
// Test expected number of records have been deleted.
|
||||
$this->assertEquals(7, $DB->count_records('analytics_predictions'));
|
||||
$this->assertEquals(1, $DB->count_records('analytics_prediction_actions'));
|
||||
$this->assertEquals(16, $DB->count_records('analytics_indicator_calc'));
|
||||
$this->assertEquals(20, $DB->count_records('analytics_indicator_calc'));
|
||||
|
||||
$approveduserids = [$this->u3->id];
|
||||
$approvedlist = new approved_userlist($course1context, $component, $approveduserids);
|
||||
@ -390,6 +403,8 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->u6->id => [$systemcontext->id, $course1context->id],
|
||||
$this->u7->id => [$systemcontext->id, $course1context->id],
|
||||
$this->u8->id => [$systemcontext->id, $course1context->id],
|
||||
$this->u9->id => [$systemcontext->id, $course1context->id],
|
||||
$this->u10->id => [$systemcontext->id, $course1context->id],
|
||||
];
|
||||
|
||||
$actualcontexts = [
|
||||
@ -401,6 +416,8 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
$this->u6->id => provider::get_contexts_for_userid($this->u6->id)->get_contextids(),
|
||||
$this->u7->id => provider::get_contexts_for_userid($this->u7->id)->get_contextids(),
|
||||
$this->u8->id => provider::get_contexts_for_userid($this->u8->id)->get_contextids(),
|
||||
$this->u9->id => provider::get_contexts_for_userid($this->u9->id)->get_contextids(),
|
||||
$this->u10->id => provider::get_contexts_for_userid($this->u10->id)->get_contextids(),
|
||||
];
|
||||
foreach ($actualcontexts as $userid => $unused) {
|
||||
sort($actualcontexts[$userid]);
|
||||
@ -411,7 +428,7 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
|
||||
// Test expected number of records have been deleted.
|
||||
$this->assertEquals(6, $DB->count_records('analytics_predictions'));
|
||||
$this->assertEquals(0, $DB->count_records('analytics_prediction_actions'));
|
||||
$this->assertEquals(15, $DB->count_records('analytics_indicator_calc'));
|
||||
$this->assertEquals(19, $DB->count_records('analytics_indicator_calc'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
namespace core_analytics;
|
||||
|
||||
use core_analytics\tests\mlbackend_configuration_trait;
|
||||
use core_analytics\tests\mlbackend_helper_trait;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -32,7 +32,7 @@ require_once(__DIR__ . '/fixtures/test_target_shortname.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
final class stats_test extends \advanced_testcase {
|
||||
use mlbackend_configuration_trait;
|
||||
use mlbackend_helper_trait;
|
||||
|
||||
/**
|
||||
* Set up the test environment.
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
namespace core_course\analytics;
|
||||
|
||||
use core_analytics\tests\mlbackend_configuration_trait;
|
||||
use core_analytics\tests\mlbackend_helper_trait;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@ -34,7 +34,7 @@ require_once(__DIR__ . '/../../../analytics/tests/fixtures/test_target_course_us
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
final class indicators_test extends \advanced_testcase {
|
||||
use mlbackend_configuration_trait;
|
||||
use mlbackend_helper_trait;
|
||||
|
||||
/**
|
||||
* test_no_teacher
|
||||
|
@ -26,6 +26,11 @@ namespace mlbackend_python;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/analytics/tests/classes/mlbackend_helper_trait.php');
|
||||
|
||||
use core_analytics\tests\mlbackend_helper_trait;
|
||||
|
||||
/**
|
||||
* Python predictions processor.
|
||||
*
|
||||
@ -35,6 +40,8 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class processor implements \core_analytics\classifier, \core_analytics\regressor, \core_analytics\packable {
|
||||
|
||||
use mlbackend_helper_trait;
|
||||
|
||||
/**
|
||||
* The required version of the python package that performs all calculations.
|
||||
*/
|
||||
@ -90,21 +97,31 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
|
||||
public function __construct() {
|
||||
global $CFG;
|
||||
|
||||
$config = get_config('mlbackend_python');
|
||||
|
||||
$this->useserver = !empty($config->useserver);
|
||||
|
||||
if (!$this->useserver) {
|
||||
// Set the python location if there is a value.
|
||||
if (!empty($CFG->pathtopython)) {
|
||||
$this->pathtopython = $CFG->pathtopython;
|
||||
}
|
||||
if ((defined('BEHAT_SITE_RUNNING') || (defined('PHPUNIT_TEST') && PHPUNIT_TEST)) &&
|
||||
self::is_mlbackend_python_configured()) {
|
||||
$this->useserver = true;
|
||||
$this->host = TEST_MLBACKEND_PYTHON_HOST;
|
||||
$this->port = TEST_MLBACKEND_PYTHON_PORT;
|
||||
$this->secure = false;
|
||||
$this->username = TEST_MLBACKEND_PYTHON_USERNAME;
|
||||
$this->password = TEST_MLBACKEND_PYTHON_PASSWORD;
|
||||
} else {
|
||||
$this->host = $config->host ?? '';
|
||||
$this->port = $config->port ?? '';
|
||||
$this->secure = $config->secure ?? false;
|
||||
$this->username = $config->username ?? '';
|
||||
$this->password = $config->password ?? '';
|
||||
$config = get_config('mlbackend_python');
|
||||
|
||||
$this->useserver = !empty($config->useserver);
|
||||
|
||||
if (!$this->useserver) {
|
||||
// Set the python location if there is a value.
|
||||
if (!empty($CFG->pathtopython)) {
|
||||
$this->pathtopython = $CFG->pathtopython;
|
||||
}
|
||||
} else {
|
||||
$this->host = $config->host ?? '';
|
||||
$this->port = $config->port ?? '';
|
||||
$this->secure = $config->secure ?? false;
|
||||
$this->username = $config->username ?? '';
|
||||
$this->password = $config->password ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user