Commit 0af2421a authored by David Monllaó's avatar David Monllaó
Browse files

MDL-59988 analytics: Reset trained status on clear

parent f1500719
......@@ -747,7 +747,7 @@ class model {
private function format_predictor_predictions($predictorresult) {
$predictions = array();
if ($predictorresult->predictions) {
if (!empty($predictorresult->predictions)) {
foreach ($predictorresult->predictions as $sampleinfo) {
// We parse each prediction.
......@@ -984,7 +984,7 @@ class model {
* @return void
*/
public function enable($timesplittingid = false) {
global $DB;
global $DB, $USER;
\core_analytics\manager::check_can_manage_models();
......@@ -1022,6 +1022,7 @@ class model {
$this->model->enabled = 1;
$this->model->timemodified = $now;
$this->model->usermodified = $USER->id;
// We don't always update timemodified intentionally as we reserve it for target, indicators or timesplitting updates.
$DB->update_record('analytics_models', $this->model);
......@@ -1447,7 +1448,7 @@ class model {
* @return void
*/
public function clear() {
global $DB;
global $DB, $USER;
\core_analytics\manager::check_can_manage_models();
......@@ -1474,6 +1475,11 @@ class model {
// We don't expect people to clear models regularly and the cost of filling the cache is
// 1 db read per context.
$this->purge_insights_cache();
$this->model->trained = 0;
$this->model->timemodified = time();
$this->model->usermodified = $USER->id;
$DB->update_record('analytics_models', $this->model);
}
/**
......
......@@ -150,9 +150,17 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
}
if ($exitcode != 0) {
$errors = $resultobj->errors;
if (is_array($errors)) {
$errors = implode(', ', $errors);
if (!empty($resultobj->errors)) {
$errors = $resultobj->errors;
if (is_array($errors)) {
$errors = implode(', ', $errors);
}
} else if (!empty($resultobj->info)) {
// Show info if no errors are returned.
$errors = $resultobj->info;
if (is_array($errors)) {
$errors = implode(', ', $errors);
}
}
$resultobj->info = array(get_string('errorpredictionsprocessor', 'analytics', $errors));
}
......@@ -195,9 +203,17 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
}
if ($exitcode != 0) {
$errors = $resultobj->errors;
if (is_array($errors)) {
$errors = implode(', ', $errors);
if (!empty($resultobj->errors)) {
$errors = $resultobj->errors;
if (is_array($errors)) {
$errors = implode(', ', $errors);
}
} else if (!empty($resultobj->info)) {
// Show info if no errors are returned.
$errors = $resultobj->info;
if (is_array($errors)) {
$errors = implode(', ', $errors);
}
}
$resultobj->info = array(get_string('errorpredictionsprocessor', 'analytics', $errors));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment