From 4de4d1652bbe79802f6bbef88eee391465326502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Mon, 25 Mar 2019 12:57:31 +0100 Subject: [PATCH] MDL-61667 analytics: Don't autoenable models with time splitting defined When the API had originally been designed, it was assumed that the presence of the time splitting method implies no requirement for the machine learning backend and that it is a sign of less performance demanding models. So it seemed to be safe and useful to have such models automatically enabled. That assumption did not prove to be valid. Most of the time is spent calculating indicators that depend on log tables. We realized it would be useful to be able to specify the default time splitting method without the need to have such models auto-enabled. --- analytics/classes/model.php | 14 ++++++++++---- analytics/tests/privacy_test.php | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/analytics/classes/model.php b/analytics/classes/model.php index 6230b758698..a96e6a6692f 100644 --- a/analytics/classes/model.php +++ b/analytics/classes/model.php @@ -360,6 +360,16 @@ class model { $modelobj->timemodified = $now; $modelobj->usermodified = $USER->id; + if ($timesplittingid) { + if (!\core_analytics\manager::is_valid($timesplittingid, '\core_analytics\local\time_splitting\base')) { + throw new \moodle_exception('errorinvalidtimesplitting', 'analytics'); + } + if (substr($timesplittingid, 0, 1) !== '\\') { + throw new \moodle_exception('errorinvalidtimesplitting', 'analytics'); + } + $modelobj->timesplitting = $timesplittingid; + } + if ($processor && !manager::is_valid($processor, '\core_analytics\classifier') && !manager::is_valid($processor, '\core_analytics\regressor')) { @@ -375,10 +385,6 @@ class model { $model = new static($modelobj); - if ($timesplittingid) { - $model->enable($timesplittingid); - } - if ($model->is_static()) { $model->mark_as_trained(); } diff --git a/analytics/tests/privacy_test.php b/analytics/tests/privacy_test.php index 4e7e2ae43be..eb3a9fe70ea 100644 --- a/analytics/tests/privacy_test.php +++ b/analytics/tests/privacy_test.php @@ -86,8 +86,10 @@ class core_analytics_privacy_model_testcase extends \core_privacy\tests\provider $this->setAdminUser(); + $this->model1->enable(); $this->model1->train(); $this->model1->predict(); + $this->model2->enable(); $this->model2->train(); $this->model2->predict();