diff --git a/analytics/classes/model.php b/analytics/classes/model.php index ef1435c215f..d8816458511 100644 --- a/analytics/classes/model.php +++ b/analytics/classes/model.php @@ -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); } /** diff --git a/lib/mlbackend/python/classes/processor.php b/lib/mlbackend/python/classes/processor.php index 69420b0c58a..97443dbe3c0 100644 --- a/lib/mlbackend/python/classes/processor.php +++ b/lib/mlbackend/python/classes/processor.php @@ -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)); }