Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 22... Línea 22...
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
Línea 24... Línea 24...
24
 
24
 
Línea -... Línea 25...
-
 
25
namespace core_analytics;
-
 
26
 
25
namespace core_analytics;
27
use core_analytics\tests\mlbackend_helper_trait;
Línea 26... Línea 28...
26
 
28
 
27
defined('MOODLE_INTERNAL') || die();
29
defined('MOODLE_INTERNAL') || die();
28
 
30
 
Línea 39... Línea 41...
39
 *
41
 *
40
 * @package   core_analytics
42
 * @package   core_analytics
41
 * @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
43
 * @copyright 2017 David Monllaó {@link http://www.davidmonllao.com}
42
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43
 */
45
 */
44
class model_test extends \advanced_testcase {
46
final class model_test extends \advanced_testcase {
-
 
47
    use mlbackend_helper_trait;
Línea 45... Línea 48...
45
 
48
 
46
    /** @var model Store Model. */
49
    /** @var model Store Model. */
Línea 47... Línea 50...
47
    protected $model;
50
    protected $model;
48
 
51
 
Línea 49... Línea 52...
49
    /** @var \stdClass Store model object. */
52
    /** @var \stdClass Store model object. */
-
 
53
    protected $modelobj;
Línea 50... Línea 54...
50
    protected $modelobj;
54
 
Línea 51... Línea 55...
51
 
55
    public function setUp(): void {
52
    public function setUp(): void {
56
        parent::setUp();
Línea 92... Línea 96...
92
     * test_delete
96
     * test_delete
93
     */
97
     */
94
    public function test_delete(): void {
98
    public function test_delete(): void {
95
        global $DB;
99
        global $DB;
Línea -... Línea 100...
-
 
100
 
-
 
101
        if (!self::is_mlbackend_python_configured()) {
-
 
102
            $this->markTestSkipped('mlbackend_python is not configured.');
-
 
103
        }
96
 
104
 
97
        $this->resetAfterTest(true);
105
        $this->resetAfterTest(true);
Línea 98... Línea -...
98
        set_config('enabled_stores', 'logstore_standard', 'tool_log');
-
 
99
 
106
        set_config('enabled_stores', 'logstore_standard', 'tool_log');
100
        $coursepredict1 = $this->getDataGenerator()->create_course(array('visible' => 0));
107
 
101
        $coursepredict2 = $this->getDataGenerator()->create_course(array('visible' => 0));
108
        // Create some courses.
Línea 102... Línea 109...
102
        $coursetrain1 = $this->getDataGenerator()->create_course(array('visible' => 1));
109
        $this->generate_courses(2, ['visible' => 0]);
Línea 103... Línea 110...
103
        $coursetrain2 = $this->getDataGenerator()->create_course(array('visible' => 1));
110
        $this->generate_courses(2, ['visible' => 1]);
104
 
111
 
Línea 105... Línea 112...
105
        $this->model->enable('\core\analytics\time_splitting\single_range');
112
        $this->model->enable('\core\analytics\time_splitting\single_range');
106
 
113
 
Línea 107... Línea -...
107
        $this->model->train();
-
 
108
        $this->model->predict();
-
 
109
 
-
 
110
        // Fake evaluation results record to check that it is actually deleted.
114
        $this->model->train();
111
        $this->add_fake_log();
115
        $this->model->predict();
112
 
116
 
113
        $modeloutputdir = $this->model->get_output_dir(array(), true);
117
        // Fake evaluation results record to check that it is actually deleted.
114
        $this->assertTrue(is_dir($modeloutputdir));
118
        $this->add_fake_log();
Línea 125... Línea 129...
125
        $this->assertEmpty($DB->count_records('analytics_predictions'));
129
        $this->assertEmpty($DB->count_records('analytics_predictions'));
126
        $this->assertEmpty($DB->count_records('analytics_prediction_actions'));
130
        $this->assertEmpty($DB->count_records('analytics_prediction_actions'));
127
        $this->assertEmpty($DB->count_records('analytics_train_samples'));
131
        $this->assertEmpty($DB->count_records('analytics_train_samples'));
128
        $this->assertEmpty($DB->count_records('analytics_predict_samples'));
132
        $this->assertEmpty($DB->count_records('analytics_predict_samples'));
129
        $this->assertEmpty($DB->count_records('analytics_used_files'));
133
        $this->assertEmpty($DB->count_records('analytics_used_files'));
130
        $this->assertFalse(is_dir($modeloutputdir));
-
 
Línea 131... Línea 134...
131
 
134
 
132
        set_config('enabled_stores', '', 'tool_log');
135
        set_config('enabled_stores', '', 'tool_log');
133
        get_log_manager(true);
136
        get_log_manager(true);
Línea 137... Línea 140...
137
     * test_clear
140
     * test_clear
138
     */
141
     */
139
    public function test_clear(): void {
142
    public function test_clear(): void {
140
        global $DB;
143
        global $DB;
Línea -... Línea 144...
-
 
144
 
-
 
145
        if (!self::is_mlbackend_python_configured()) {
-
 
146
            $this->markTestSkipped('mlbackend_python is not configured.');
-
 
147
        }
141
 
148
 
142
        $this->resetAfterTest(true);
149
        $this->resetAfterTest(true);
Línea 143... Línea -...
143
        set_config('enabled_stores', 'logstore_standard', 'tool_log');
-
 
144
 
150
        set_config('enabled_stores', 'logstore_standard', 'tool_log');
145
        $coursepredict1 = $this->getDataGenerator()->create_course(array('visible' => 0));
151
 
146
        $coursepredict2 = $this->getDataGenerator()->create_course(array('visible' => 0));
152
        // Create some courses.
Línea 147... Línea 153...
147
        $coursetrain1 = $this->getDataGenerator()->create_course(array('visible' => 1));
153
        $this->generate_courses(2, ['visible' => 0]);
Línea 148... Línea 154...
148
        $coursetrain2 = $this->getDataGenerator()->create_course(array('visible' => 1));
154
        $this->generate_courses(2, ['visible' => 1]);
149
 
155
 
Línea 164... Línea 170...
164
        $modelversionoutputdir = $this->model->get_output_dir();
170
        $modelversionoutputdir = $this->model->get_output_dir();
165
        $this->assertTrue(is_dir($modelversionoutputdir));
171
        $this->assertTrue(is_dir($modelversionoutputdir));
Línea 166... Línea 172...
166
 
172
 
167
        // Update to an empty time splitting method to force model::clear execution.
173
        // Update to an empty time splitting method to force model::clear execution.
168
        $this->model->clear();
-
 
Línea 169... Línea 174...
169
        $this->assertFalse(is_dir($modelversionoutputdir));
174
        $this->model->clear();
170
 
175
 
171
        // Check that most of the stuff got deleted.
176
        // Check that most of the stuff got deleted.
172
        $this->assertEquals(1, $DB->count_records('analytics_models', array('id' => $this->modelobj->id)));
177
        $this->assertEquals(1, $DB->count_records('analytics_models', array('id' => $this->modelobj->id)));
Línea 376... Línea 381...
376
 
381
 
377
    /**
382
    /**
378
     * Test that import_model import models' configurations.
383
     * Test that import_model import models' configurations.
379
     */
384
     */
-
 
385
    public function test_import_model_config(): void {
-
 
386
        if (!self::is_mlbackend_python_configured()) {
-
 
387
            $this->markTestSkipped('mlbackend_python is not configured.');
-
 
388
        }
380
    public function test_import_model_config(): void {
389
 
Línea 381... Línea 390...
381
        $this->resetAfterTest(true);
390
        $this->resetAfterTest(true);
382
 
391
 
Línea 418... Línea 427...
418
 
427
 
419
    /**
428
    /**
420
     * Test export_config
429
     * Test export_config
421
     */
430
     */
-
 
431
    public function test_export_config(): void {
-
 
432
        if (!self::is_mlbackend_python_configured()) {
-
 
433
            $this->markTestSkipped('mlbackend_python is not configured.');
-
 
434
        }
422
    public function test_export_config(): void {
435
 
Línea 423... Línea 436...
423
        $this->resetAfterTest(true);
436
        $this->resetAfterTest(true);
Línea 424... Línea 437...
424
 
437
 
Línea 522... Línea 535...
522
 
535
 
523
        if (!PHPUNIT_LONGTEST) {
536
        if (!PHPUNIT_LONGTEST) {
524
            $this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
537
            $this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
Línea 525... Línea 538...
525
        }
538
        }
526
 
539
 
527
        // 10000 should be enough to make oracle and mssql fail, if we want pgsql to fail we need around 70000
540
        // 10000 should be enough to make mssql fail, if we want pgsql to fail we need around 70000
Línea 528... Línea 541...
528
        // users, that is a few minutes just to create the users.
541
        // users, that is a few minutes just to create the users.
529
        $nusers = 10000;
542
        $nusers = 10000;