MDL-59657 analytics: No predictions until training is completed
authorDavid Monllao <david.monllao@gmail.com>
Thu, 7 Sep 2017 05:52:56 +0000 (07:52 +0200)
committerDavid Monllao <davidm@moodle.com>
Thu, 7 Sep 2017 08:58:39 +0000 (10:58 +0200)
admin/tool/analytics/model.php

index b2268f1..6d64c42 100644 (file)
@@ -161,8 +161,13 @@ switch ($action) {
 
         // Looks dumb to get a new instance but better be conservative.
         $model = new \core_analytics\model($model->get_model_obj());
-        $predictresults = $model->predict();
-        $predictlogs = $model->get_analyser()->get_logs();
+        if ($model->is_trained()) {
+            $predictresults = $model->predict();
+            $predictlogs = $model->get_analyser()->get_logs();
+        } else {
+            $predictresults = false;
+            $predictlogs = array();
+        }
 
         $renderer = $PAGE->get_renderer('tool_analytics');
         echo $renderer->render_get_predictions_results($trainresults, $trainlogs, $predictresults, $predictlogs);